fork download
  1. #include <stdio.h>
  2. #include <mpi.h>
  3.  
  4. int main(int argc, char** argv) {
  5. int size, rank;
  6. int data;
  7. int next_rank, previous_rank;
  8. MPI_Status status;
  9.  
  10. // Initialize MPI
  11. MPI_Init(&argc, &argv);
  12. MPI_Comm_size(MPI_COMM_WORLD, &size);
  13. MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  14.  
  15. // Define the data to be passed around the ring
  16. data = rank;
  17.  
  18. // Pass the data in a ring
  19. next_rank = (rank + 1) % size;
  20. previous_rank = (rank - 1 + size) % size;
  21.  
  22. // Send and receive the data in the ring
  23. MPI_Send(&data, 1, MPI_INT, next_rank, 0, MPI_COMM_WORLD);
  24. MPI_Recv(&data, 1, MPI_INT, previous_rank, 0, MPI_COMM_WORLD, &status);
  25.  
  26. // Print the received data
  27. printf("Process %d received data: %d\n", rank, data);
  28.  
  29. // Finalize MPI
  30. MPI_Finalize();
  31.  
  32. return 0;
  33. }
  34.  
  35. # your code goes here
Success #stdin #stdout #stderr 0.27s 39364KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: unexpected symbol in "int main"
Execution halted