source: CIVL/examples/mpi/routines/reduce.c

main
Last change on this file was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

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

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