fork download
  1. #include <stdio.h>
  2. #include <mpi.h>
  3.  
  4. int main(int argc, char** argv) {
  5. int rank, size;
  6. int send_data, recv_data;
  7.  
  8. MPI_Init(&argc, &argv);
  9. MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  10. MPI_Comm_size(MPI_COMM_WORLD, &size);
  11.  
  12. if (size < 2) {
  13. printf("This example requires at least 2 processes.\n");
  14. MPI_Finalize();
  15. return 0;
  16. }
  17.  
  18. if (rank == 0) {
  19. send_data = 42;
  20. MPI_Send(&send_data, 1, MPI_INT, 1, 0, MPI_COMM_WORLD);
  21. printf("Process %d sent data: %d\n", rank, send_data);
  22. } else if (rank == 1) {
  23. MPI_Recv(&recv_data, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
  24. printf("Process %d received data: %d\n", rank, recv_data);
  25. }
  26.  
  27. MPI_Finalize();
  28. return 0;
  29. }
  30.  
Success #stdin #stdout #stderr 0.29s 40848KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: unexpected symbol in "int main"
Execution halted