fork download
  1. #include <mpi.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. const int MAX_STRING = 100;
  6.  
  7. int main(void) {
  8. char greeting[MAX_STRING];
  9. int comm_sz; /* Number of processes */
  10. int my_rank; /* My process rank */
  11.  
  12. MPI_Init(NULL, NULL);
  13. MPI_Comm_size(MPI_COMM_WORLD, &comm_sz);
  14. MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
  15.  
  16. if (my_rank != 0) {
  17. sprintf(greeting, "Greetings from process %d of %d!", my_rank, comm_sz);
  18. MPI_Send(greeting, strlen(greeting)+1, MPI_CHAR, 0, 0, MPI_COMM_WORLD);
  19. } else {
  20. printf("Greetings from process %d of %d!\n", my_rank, comm_sz);
  21. for (int q = 1; q < comm_sz; q++) {
  22. MPI_Recv(greeting, MAX_STRING, MPI_CHAR, q, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
  23. printf("%s\n", greeting);
  24. }
  25. }
  26.  
  27. MPI_Finalize();
  28. return 0;
  29. } /* main */
  30.  
  31.  
Success #stdin #stdout #stderr 0.27s 40704KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: unexpected symbol in "const int"
Execution halted