#include #include int main (int argc, char *argv[]){ MPI_Init(&argc,&argv); int myproc,nbproc; MPI_Comm_rank(MPI_COMM_WORLD,&myproc); MPI_Comm_size(MPI_COMM_WORLD,&nbproc); int result = 0; int N = 100; int start = N*myproc/nbproc; int end = N*(myproc+1)/nbproc; for (int i = start ; i < end ; i++){ result += i; } int resultReduce=0; MPI_Allreduce ( &result, &resultReduce, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD); printf ("proc %d result %d reduce %d\n",myproc,result,resultReduce); MPI_Finalize(); }