fork download
  1. #include <stdio.h>
  2. #include <mpi.h>
  3.  
  4. #define N 10
  5.  
  6. int main(int argc, char *argv[]) {
  7. int rank, size;
  8. int array[N] = {4, 8, 2, 10, 6, 12, 3, 5, 7, 9};
  9. int max, product, bitwise_and;
  10.  
  11. MPI_Init(&argc, &argv);
  12. MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  13. MPI_Comm_size(MPI_COMM_WORLD, &size);
  14.  
  15. MPI_Reduce(&array, &max, 1, MPI_INT, MPI_MAX, 0, MPI_COMM_WORLD);
  16. MPI_Reduce(&array, &product, 1, MPI_INT, MPI_PROD, 0, MPI_COMM_WORLD);
  17. MPI_Reduce(&array, &bitwise_and, 1, MPI_INT, MPI_BAND, 0, MPI_COMM_WORLD);
  18.  
  19. if (rank == 0) {
  20. printf("Max value: %d\n", max);
  21. printf("Product of elements: %d\n", product);
  22. printf("Bitwise AND: %d\n", bitwise_and);
  23. }
  24.  
  25. MPI_Finalize();
  26. return 0;
  27. }
Success #stdin #stdout #stderr 0.28s 40732KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: unexpected symbol in "int main"
Execution halted