fork download
  1. #include <iostream>
  2. #include <mpi.h>
  3.  
  4. int main(int argc, char** argv) {
  5. int world_rank;
  6. int world_size;
  7. int data = 0;
  8.  
  9. MPI_Init(&argc, &argv);
  10. MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
  11. MPI_Comm_size(MPI_COMM_WORLD, &world_size);
  12.  
  13. if (world_rank == 0) {
  14. data = 42;
  15. MPI_Send(&data, 1, MPI_INT, 1, 0, MPI_COMM_WORLD);
  16. }
  17. else if (world_rank == 1) {
  18. MPI_Recv(&data, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
  19. }
  20.  
  21. if (world_rank == 1) {
  22. std::cout << "Process " << world_rank << " received: " << data << std::endl;
  23. }
  24.  
  25. MPI_Finalize();
  26. return 0;
  27. }
Success #stdin #stdout #stderr 0.33s 40720KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: unexpected symbol in "int main"
Execution halted