fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <mpi.h>
  4. #include <ctime>
  5. #include <cstdlib>
  6. const int MAX_STRING = 100;
  7. int main(void)
  8. {
  9. char gret[MAX_STRING];
  10. int csize;
  11. int prank;
  12. MPI_Init(NULL, NULL);
  13. MPI_Comm_size(MPI_COMM_WORLD, &csize);
  14. MPI_Comm_rank(MPI_COMM_WORLD, &prank);
  15. std::srand(static_cast<unsigned int>(std::time(0)));
  16.  
  17. for(int i = 0; i < csize; i++){
  18. int rand_num = std::rand() % 10;
  19. char temp[2];
  20. sprintf(temp, "%d%d", prank, rand_num);
  21. MPI_Send(temp, strlen(temp) + 1, MPI_CHAR, i, 0, MPI_COMM_WORLD);
  22. MPI_Recv(temp, 3, MPI_CHAR, i, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
  23. gret[temp[0]] = temp[0];
  24. gret[temp[0]+1] = temp[1];
  25. }
  26. printf("Process %d recived:%s \n", prank, gret);
  27.  
  28. MPI_Finalize();
  29. return 0;
  30. }
Success #stdin #stdout #stderr 0.27s 40472KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: unexpected symbol in "const int"
Execution halted