fork download
  1. #include <mpi.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. int main(int argc, char** argv) {
  6. int rank, size;
  7. int BIG = atoi(argv[1]);
  8. MPI_Init(&argc, &argv);
  9. MPI_Comm_size(MPI_COMM_WORLD, &size);
  10. MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  11.  
  12. int *i = (int *) malloc(sizeof(int) * BIG);
  13. // reserve BIG(10000) int pointers.
  14. i[0] = rank;
  15. i[BIG - 1] = size * (rank + 1);
  16.  
  17. printf("Task %d is trying to send to task %d\n", rank, (rank + 1) % size);
  18. MPI_Send(i, BIG, MPI_INT, (rank + 1) % size, 1, MPI_COMM_WORLD);
  19. printf("Task %d sent values i[0]=%d and i[%d]=%d\n", rank, i[0], BIG-1, i[BIG - 1]);
  20.  
  21. printf("Task %d is trying to receive from task %d\n", rank, (size + rank - 1) % size);
  22. MPI_Recv(i, BIG, MPI_INT, (size + rank - 1) % size, 1, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
  23.  
  24. printf("Task %d received values i[0]=%d and i[%d]=%d from task %d\n", rank, i[0], BIG-1, i[BIG - 1], (size + rank - 1) % size);
  25.  
  26. MPI_Finalize();
  27. return 0;
  28. }
  29.  
Success #stdin #stdout #stderr 0.26s 38876KB
stdin
5
stdout
Standard output is empty
stderr
Error: unexpected symbol in "int main"
Execution halted