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

int main(int argc, char **argv)
{
    int provided;
    MPI_Init_thread(&argc, &argv, MPI_THREAD_SERIALIZED, &provided);
    if (provided < MPI_THREAD_SERIALIZED)
    {
        printf("Thread level insufficient, exiting\n");
        abort();
    }

    int rank, procs;
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &procs);

    int bufSize = 4;
    int size = bufSize*procs+1;
    int sendBuf[size];
    int recvBuf[size];
    memset(&recvBuf, 0, size - 1);

    int exampleData[bufSize];
    for (int i = 0; i < bufSize; i++)
    {
        exampleData[i] = rank + i;
    }

    printf("Process %i of %i, local value: %d\n", rank, procs,
            exampleData[0], exampleData[1], exampleData[2], exampleData[3]);

    MPI_Reduce(&exampleData, &recvBuf, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); //send to process 0
    
    printf("Hello Collectives! I'm, process %i of %i and my recv buffer is %d, %d, %d, %d, %d, %d\n",
            rank, procs, recvBuf[0], recvBuf[1], recvBuf[2], recvBuf[3], recvBuf[4], recvBuf[5]);

    MPI_Finalize();

    return 0;
}
Success #stdin #stdout #stderr 0.25s 40856KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: unexpected symbol in "int main"
Execution halted