source: CIVL/examples/MPI/reduce.c@ 3f1f924

1.23 2.0 acw/focus-triggers main test-branch
Last change on this file since 3f1f924 was 3f1f924, checked in by Ziqing Luo <ziqing@…>, 12 years ago

A simple reduce test

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

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