fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <mpi.h>
  4.  
  5. int main(int argc, char* argv[]) {
  6. int rank, size;
  7.  
  8.  
  9. MPI_Init(&argc, &argv);
  10. MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  11. MPI_Comm_size(MPI_COMM_WORLD, &size);
  12.  
  13. char mission[20];
  14. char date[20];
  15. MPI_Status status;
  16.  
  17. if (rank == 0) {
  18.  
  19. strcpy_s(mission, "Chandrayaan 3");
  20. strcpy_s(date, "23-August-2023");
  21.  
  22. printf("Process 0 (ISRO) sending mission name: %s\n", mission);
  23.  
  24. MPI_Send(mission, strlen(mission) + 1, MPI_CHAR, 1, 0, MPI_COMM_WORLD);
  25.  
  26. printf("Process 0 (ISRO) sending landing date: %s\n", date);
  27.  
  28. MPI_Send(date, strlen(date) + 1, MPI_CHAR, 1, 1, MPI_COMM_WORLD);
  29.  
  30. printf("Process 0 (ISRO): All data sent to Moon successfully!\n");
  31. }
  32. else if (rank == 1) {
  33.  
  34. MPI_Recv(mission, 20, MPI_CHAR, 0, 0, MPI_COMM_WORLD, &status);
  35. printf("Process 1 (Moon) received mission name: %s\n", mission);
  36.  
  37.  
  38. MPI_Recv(date, 20, MPI_CHAR, 0, 1, MPI_COMM_WORLD, &status);
  39. printf("Process 1 (Moon) received landing date: %s\n", date);
  40.  
  41. printf("Process 1 (Moon): Successful landing confirmed!\n");
  42. }
  43.  
  44.  
  45. MPI_Finalize();
  46. return 0;
  47. }
Success #stdin #stdout #stderr 0.31s 40680KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: unexpected symbol in "int main"
Execution halted