fork download
  1. #include <stdio.h>
  2. #include “mpi.h”
  3. int main ( int argc, char **argv )
  4. {
  5. int numtasks, rank, next, prev, buf [2], tag1 = 1, tag2 = 2;
  6. MPI_Request reqs [4];
  7. MPI_Status stats [2];
  8. MPI_Init ( &argc, &argv );
  9. MPI_Comm_size (MPI_COMM_WORLD, &numtasks);
  10. MPI_Comm_rank (MPI_COMM_WORLD, &rank);
  11. prev = rank -1;
  12. next = rank + 1;
  13. if ( rank == 0 ) prev = numtasks -1;
  14. if ( rank == ( numtasks -1 ) ) next = 0;
  15. MPI_Irecv ( &buf [0], 1, MPI_INT, prev, tag1, MPI_COMM_WORLD, &reqs [0]
  16. );
  17. MPI_Irecv ( &buf [1], 1, MPI_INT, next, tag2, MPI_COMM_WORLD, &reqs [1]
  18. );
  19. MPI_Isend ( &rank, 1, MPI_INT, prev, tag2, MPI_COMM_WORLD, &reqs [2] );
  20. MPI_Isend ( &rank, 1, MPI_INT, next, tag1, MPI_COMM_WORLD, &reqs [3] );
  21.  
  22. MPI_Waitall (4, reqs, stats );
  23. MPI_Finalize();
  24. return 0;
  25. }
  26.  
Success #stdin #stdout #stderr 0.23s 40748KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: unexpected symbol in "int main"
Execution halted