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