fork download
  1. #include <iostream.h>
  2. #include <mpi.h>
  3.  
  4. int main(int argc, char *argv[]) {
  5. int i;
  6. int nitems=10;
  7. int mynode, totalnodes;
  8. MPI_Status status;
  9. double *array;
  10.  
  11. MPI_Init(&argc, &argv);
  12. MPI_Comm_size(MPI_COMM_WORLD, &totalnodes);
  13. MPI_Comm_rank(MPI_COMM_WORLD, &mynode);
  14.  
  15. array = new double[nitems];
  16.  
  17. if(mynode==0){
  18. for(i=0; i<nitems; i++){
  19. array[i] = (double) i;
  20.  
  21. }
  22. }
  23.  
  24. if(mynode==0)
  25.  
  26. for(i=1; i<totalnodes; i++){
  27. MPI_Send(array, nitems, MPI_DOUBLE, i, 1, MPI_COMM_WORLD);
  28.  
  29. }
  30. }
  31. else{
  32. MPI_Recv(array, nitems, MPI_DOUBLE, 0, 1, MPI_COMM_WORLD, &status)
  33. }
  34.  
  35. for(i=0; i<nitems; i++){
  36. cout << "Processor" << mynode;
  37. cout << ": array[" << i << "] = " << array[i] << endl;
  38. }
  39.  
  40. MPI_Finalize();
  41. }
  42.  
  43.  
Success #stdin #stdout #stderr 0.28s 40920KB
stdin
2 heyy
stdout
Standard output is empty
stderr
Error: unexpected symbol in "int main"
Execution halted