source: CIVL/mods/dev.civl.abc/examples/mpi/reduce.c

main
Last change on this file was aad342c, checked in by Stephen Siegel <siegel@…>, 3 years ago

Performing huge refactor to incorporate ABC, GMC, and SARL into CIVL repo and use Java modules.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5664 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 762 bytes
Line 
1#include <mpi.h>
2#include <stdio.h>
3
4void main(int argc, char * argv[]){
5
6 int nprocs, rank;
7 int IntValue;
8 double DoubleValue;
9
10 MPI_Init(&argc, &argv);
11 MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
12 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
13
14 if(nprocs < 2){
15 printf("The program needs more than 2 processes.\n");
16 MPI_Finalize();
17 return;
18 }else{
19 double temp;
20
21 MPI_Allreduce(&rank, &IntValue, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
22 temp = rank * 0.1;
23 MPI_Reduce(&temp, &DoubleValue, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
24 printf("I'm process %d, my integer value is %d \n", rank, IntValue);
25 if(rank == 0)
26 printf("I'm process %d, my double value is %.4f \n", rank, DoubleValue);
27 MPI_Finalize();
28 return;
29 }
30}
Note: See TracBrowser for help on using the repository browser.