Created
June 14, 2021 11:14
-
-
Save MarkusOstermayer/9a1ac29c9c373b97b91c0fdd1bf304da to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <mpi.h> | |
#include <stdio.h> | |
#define ROOT 0 | |
#define COMM_TAG 1 | |
int main(int argc, char *argv[]) | |
{ | |
int communicator_size, process_rank; | |
MPI_Init(&argc, &argv); | |
MPI_Comm_size(MPI_COMM_WORLD, &communicator_size); | |
MPI_Comm_rank(MPI_COMM_WORLD, &process_rank); | |
if(process_rank == 0) | |
{ | |
MPI_Status mpi_status_obj; | |
char recv_buffer; | |
MPI_Recv(&recv_buffer, 1, MPI_CHAR, MPI_ANY_SOURCE, COMM_TAG, MPI_COMM_WORLD, &mpi_status_obj); | |
printf("Root got Info from Node %d\n", mpi_status_obj.MPI_SOURCE); | |
} | |
else | |
{ | |
if(process_rank == communicator_size - 1) | |
{ | |
char send_buffer = 0; | |
MPI_Send(&send_buffer, 1, MPI_CHAR, ROOT, COMM_TAG, MPI_COMM_WORLD); | |
} | |
} | |
MPI_Finalize(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment