fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <mpi.h>
  4.  
  5. int main(int argc, char **argv)
  6. {
  7. int provided;
  8. MPI_Init_thread(&argc, &argv, MPI_THREAD_SERIALIZED, &provided);
  9. if (provided < MPI_THREAD_SERIALIZED)
  10. {
  11. printf("Thread level insufficient, exiting\n");
  12. abort();
  13. }
  14.  
  15. int rank, procs;
  16. MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  17. MPI_Comm_size(MPI_COMM_WORLD, &procs);
  18.  
  19. int bufSize = 4;
  20. int size = bufSize*procs+1;
  21. int sendBuf[size];
  22. int recvBuf[size];
  23. memset(&recvBuf, 0, size - 1);
  24.  
  25. int exampleData[bufSize];
  26. for (int i = 0; i < bufSize; i++)
  27. {
  28. exampleData[i] = rank + i;
  29. }
  30.  
  31. printf("Process %i of %i, local value: %d\n", rank, procs,
  32. exampleData[0], exampleData[1], exampleData[2], exampleData[3]);
  33.  
  34. MPI_Reduce(&exampleData, &recvBuf, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); //send to process 0
  35.  
  36. printf("Hello Collectives! I'm, process %i of %i and my recv buffer is %d, %d, %d, %d, %d, %d\n",
  37. rank, procs, recvBuf[0], recvBuf[1], recvBuf[2], recvBuf[3], recvBuf[4], recvBuf[5]);
  38.  
  39. MPI_Finalize();
  40.  
  41. return 0;
  42. }
  43.  
Success #stdin #stdout #stderr 0.25s 40856KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: unexpected symbol in "int main"
Execution halted