#include <stdio.h>
#include <mpi.h>

int main(void) {
    int my_rank;
    int comm_sz;

    MPI_Init(NULL, NULL);
    MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
    MPI_Comm_size(MPI_COMM_WORLD, &comm_sz);

    if (comm_sz != 2) {
        if (my_rank == 0) {
            printf("Run this example with exactly 2 processes.\n");
        }
        MPI_Finalize();
        return 1;
    }

    int number = -1;

    if (my_rank == 0) {
        number = 42;
        MPI_Send(&number, 1, MPI_INT, 1, 0, MPI_COMM_WORLD);
        printf("Process 0 sent %d.\n", number);
    } else {
        MPI_Recv(&number, 1, MPI_INT, 0, 0, MPI_COMM_WORLD,
                 MPI_STATUS_IGNORE);
        printf("Process 1 received %d.\n", number);
    }

    MPI_Finalize();
    return 0;
}
