#include <mpi.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
int rank, size;
MPI_Init(&argc, &argv); // Initialize MPI environment
MPI_Comm_rank(MPI_COMM_WORLD, &rank); // Get the rank of the process
MPI_Comm_size(MPI_COMM_WORLD, &size); // Get the number of processes
if (rank == 0) {
// Process 0 sends a message to process 1
int msg = 100;
printf("Process %d sending message: %d\n", rank
, msg
); MPI_Send(&msg, 1, MPI_INT, 1, 0, MPI_COMM_WORLD);
} else if (rank == 1) {
// Process 1 receives the message from process 0
int msg;
MPI_Recv(&msg, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
printf("Process %d received message: %d\n", rank
, msg
); }
MPI_Finalize(); // Finalize MPI environment
return 0;
}
I2luY2x1ZGUgPG1waS5oPgojaW5jbHVkZSA8c3RkaW8uaD4KCmludCBtYWluKGludCBhcmdjLCBjaGFyICphcmd2W10pIHsKICAgIGludCByYW5rLCBzaXplOwogICAgTVBJX0luaXQoJmFyZ2MsICZhcmd2KTsgICAgICAgICAgLy8gSW5pdGlhbGl6ZSBNUEkgZW52aXJvbm1lbnQKICAgIE1QSV9Db21tX3JhbmsoTVBJX0NPTU1fV09STEQsICZyYW5rKTsgLy8gR2V0IHRoZSByYW5rIG9mIHRoZSBwcm9jZXNzCiAgICBNUElfQ29tbV9zaXplKE1QSV9DT01NX1dPUkxELCAmc2l6ZSk7IC8vIEdldCB0aGUgbnVtYmVyIG9mIHByb2Nlc3NlcwoKICAgIGlmIChyYW5rID09IDApIHsKICAgICAgICAvLyBQcm9jZXNzIDAgc2VuZHMgYSBtZXNzYWdlIHRvIHByb2Nlc3MgMQogICAgICAgIGludCBtc2cgPSAxMDA7CiAgICAgICAgcHJpbnRmKCJQcm9jZXNzICVkIHNlbmRpbmcgbWVzc2FnZTogJWRcbiIsIHJhbmssIG1zZyk7CiAgICAgICAgTVBJX1NlbmQoJm1zZywgMSwgTVBJX0lOVCwgMSwgMCwgTVBJX0NPTU1fV09STEQpOwogICA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