#include <string.h>
#include <stdio.h>

#include <mpi.h>

int main(int argc, char** argv) {
  char message[20];
  MPI_Status status;

  MPI_Init(&argc, &argv);

  int world_size;
  MPI_Comm_size(MPI_COMM_WORLD, &world_size);

  int world_rank;
  MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);

  if (world_size != 2) {
    printf("This example should be run on two processes\n");
    MPI_Abort(MPI_COMM_WORLD, 1);
  }

  if (world_rank == 0) {
    strcpy(message,"Hello, there");
    MPI_Send(message, strlen(message)+1, MPI_CHAR, 1, 99, MPI_COMM_WORLD);

  } else if (world_rank == 1) {
    MPI_Recv(message, 20, MPI_CHAR, 0, 99, MPI_COMM_WORLD, &status);
    printf("Rank %d received: %s\n", world_rank, message);
  }

  MPI_Finalize();

  return 0;
}
