fork download
  1. #include <mpi.h>
  2. #include <iostream>
  3.  
  4. int main(int argc, char** argv) {
  5. MPI_Init(&argc, &argv);
  6.  
  7. int rank, numProcesses;
  8. MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  9. MPI_Comm_size(MPI_COMM_WORLD, &numProcesses);
  10.  
  11. int data = 0;
  12.  
  13. if (rank == 0) {
  14. data = 100;
  15. MPI_Send(&data, 1, MPI_INT, 1, 0, MPI_COMM_WORLD); // Rank 0 sends data to rank 1
  16. } else if (rank == 1) {
  17. MPI_Recv(&data, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); // Rank 1 receives data from rank 0
  18. std::cout << "Received data: " << data << " on process " << rank << std::endl;
  19. }
  20.  
  21. MPI_Finalize();
  22. return 0;
  23. }
  24.  
  25.  
Success #stdin #stdout #stderr 0.26s 40772KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: unexpected symbol in "int main"
Execution halted