fork download
  1. #include <mpi.h>
  2. #include <stdio.h>
  3.  
  4. int main(int argc, char *argv[]) {
  5. int rank, size;
  6. MPI_Init(&argc, &argv); // Initialize MPI environment
  7. MPI_Comm_rank(MPI_COMM_WORLD, &rank); // Get the rank of the process
  8. MPI_Comm_size(MPI_COMM_WORLD, &size); // Get the number of processes
  9.  
  10. if (rank == 0) {
  11. // Process 0 sends a message to process 1
  12. int msg = 100;
  13. printf("Process %d sending message: %d\n", rank, msg);
  14. MPI_Send(&msg, 1, MPI_INT, 1, 0, MPI_COMM_WORLD);
  15. } else if (rank == 1) {
  16. // Process 1 receives the message from process 0
  17. int msg;
  18. MPI_Recv(&msg, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
  19. printf("Process %d received message: %d\n", rank, msg);
  20. }
  21.  
  22. MPI_Finalize(); // Finalize MPI environment
  23. return 0;
  24. }
  25.  
Success #stdin #stdout #stderr 0.26s 40576KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: unexpected symbol in "int main"
Execution halted