fork download
  1. #include <stdio.h>
  2. #include <mpi.h>
  3. int main(int argc, char* argv[]) {
  4. MPI_Init(&argc, &argv);
  5. int size, my_rank;
  6. MPI_Comm_size(MPI_COMM_WORLD, &size); // Get the total number of processes
  7. MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); // Get the rank of the current process
  8. int my_values[5]; // Array to hold values for each process
  9. for (int i = 0; i < 5; i++) {
  10. my_values[i] = (my_rank + 1* 100 ; // Initialize array with unique values based on rank
  11. }
  12. // Print the values before MPI_Alltoall
  13. printf("Process %d, my_values: %d, %d, %d, %d, %d.\n",
  14. my_rank, my_values[0], my_values[1], my_values[2], my_values[3], my_values[4]);
  15. int buffer_recv[5]; // Array to receive data from all other processes
  16. // Perform the MPI_Alltoall operation
  17. MPI_Alltoall(my_values, 1, MPI_INT, buffer_recv, 1, MPI_INT, MPI_COMM_WORLD);
  18. // Print the values received by each process
  19. printf("Process %d, received values: %d, %d, %d, %d, %d.\n",
  20. my_rank, buffer_recv[0], buffer_recv[1], buffer_recv[2], buffer_recv[3], buffer_recv[4]);
  21. MPI_Finalize();
  22. return 0;
  23. }
  24.  
  25.  
Success #stdin #stdout #stderr 0.32s 40796KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: unexpected symbol in "int main"
Execution halted