#include <mpi.h>
#include <iostream>
using namespace std;
int main(int argc, char* argv[]) {
MPI_Init(&argc, &argv); // Initialize MPI environment
int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank); // Get process rank
if (rank == 0) { // Sender
string message = "Hello from Sender!";
MPI_Send(message.c_str(), message.size() + 1, MPI_CHAR, 1, 0, MPI_COMM_WORLD);
cout << "Sender: Message sent.\n";
} else if (rank == 1) { // Receiver
char message[100];
MPI_Recv(message, 100, MPI_CHAR, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
cout << "Receiver: Message received: " << message << endl;
}
MPI_Finalize(); // Finalize MPI environment
return 0;
}
I2luY2x1ZGUgPG1waS5oPgojaW5jbHVkZSA8aW9zdHJlYW0+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbihpbnQgYXJnYywgY2hhciogYXJndltdKSB7CiAgICBNUElfSW5pdCgmYXJnYywgJmFyZ3YpOyAvLyBJbml0aWFsaXplIE1QSSBlbnZpcm9ubWVudAogICAgaW50IHJhbms7CiAgICBNUElfQ29tbV9yYW5rKE1QSV9DT01NX1dPUkxELCAmcmFuayk7IC8vIEdldCBwcm9jZXNzIHJhbmsKCiAgICBpZiAocmFuayA9PSAwKSB7IC8vIFNlbmRlcgogICAgICAgIHN0cmluZyBtZXNzYWdlID0gIkhlbGxvIGZyb20gU2VuZGVyISI7CiAgICAgICAgTVBJX1NlbmQobWVzc2FnZS5jX3N0cigpLCBtZXNzYWdlLnNpemUoKSArIDEsIE1QSV9DSEFSLCAxLCAwLCBNUElfQ09NTV9XT1JMRCk7CiAgICAgICAgY291dCA8PCAiU2VuZGVyOiBNZXNzYWdlIHNlbnQuXG4iOwogICAgfSBlbHNlIGlmIChyYW5rID09IDEpIHsgLy8gUmVjZWl2ZXIKICAgICAgICBjaGFyIG1lc3NhZ2VbMTAwXTsKICAgICAgICBNUElfUmVjdihtZXNzYWdlLCAxMDAsIE1QSV9DSEFSLCAwLCAwLCBNUElfQ09NTV9XT1JMRCwgTVBJX1NUQVRVU19JR05PUkUpOwogICAgICAgIGNvdXQgPDwgIlJlY2VpdmVyOiBNZXNzYWdlIHJlY2VpdmVkOiAiIDw8IG1lc3NhZ2UgPDwgZW5kbDsKICAgIH0KCiAgICBNUElfRmluYWxpemUoKTsgLy8gRmluYWxpemUgTVBJIGVudmlyb25tZW50CiAgICByZXR1cm4gMDsKfQo=