fork download
#include <stdio.h>
#include <mpi.h>

#define N 10

int main(int argc, char *argv[]) {
    int rank, size;
    int array[N] = {4, 8, 2, 10, 6, 12, 3, 5, 7, 9};
    int max, product, bitwise_and;
    
    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &size);
    
    MPI_Reduce(&array, &max, 1, MPI_INT, MPI_MAX, 0, MPI_COMM_WORLD);
    MPI_Reduce(&array, &product, 1, MPI_INT, MPI_PROD, 0, MPI_COMM_WORLD);
    MPI_Reduce(&array, &bitwise_and, 1, MPI_INT, MPI_BAND, 0, MPI_COMM_WORLD);
    
    if (rank == 0) {
        printf("Max value: %d\n", max);
        printf("Product of elements: %d\n", product);
        printf("Bitwise AND: %d\n", bitwise_and);
    }
    
    MPI_Finalize();
    return 0;
}
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