fork download
  1. #include <mpi.h>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int main(int argc, char* argv[]) {
  6. MPI_Init(&argc, &argv); // Initialize MPI environment
  7. int rank;
  8. MPI_Comm_rank(MPI_COMM_WORLD, &rank); // Get process rank
  9.  
  10. if (rank == 0) { // Sender
  11. string message = "Hello from Sender!";
  12. MPI_Send(message.c_str(), message.size() + 1, MPI_CHAR, 1, 0, MPI_COMM_WORLD);
  13. cout << "Sender: Message sent.\n";
  14. } else if (rank == 1) { // Receiver
  15. char message[100];
  16. MPI_Recv(message, 100, MPI_CHAR, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
  17. cout << "Receiver: Message received: " << message << endl;
  18. }
  19.  
  20. MPI_Finalize(); // Finalize MPI environment
  21. return 0;
  22. }
  23.  
Success #stdin #stdout #stderr 0.29s 40780KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: unexpected symbol in "using namespace"
Execution halted