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