Skip to content
Snippets Groups Projects
hello-world.c 755 B
#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>

int main(int argc, char** argv){
    MPI_Init(&argc, &argv);

    int size;
    MPI_Comm_size(MPI_COMM_WORLD, &size);

    int rank;
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);

    MPI_Status stat;

    if(size != 2){
        if(rank == 0){
            printf("This program requires exactly 2 MPI ranks, but you are attempting to use %d! Exiting...\n", size);
        }
        MPI_Finalize();
        exit(0);
    }
    int tag = 10;
    
    const char *payload = "world!";

    // TODO: Implement the MPI_Send call to send the six characters of "payload" to rank 1
    if (rank == 0) {
        MPI_Send(payload, 6, MPI_CHAR, 1, tag, MPI_COMM_WORLD);
    }

    printf("\n");
    
    return 0;
}