source: CIVL/examples/mpi/routines/Gather_Scatter/mpi_gather.c@ dccd621

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

cleaned up examples

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

  • Property mode set to 100644
File size: 938 bytes
Line 
1#include <mpi.h>
2#include <stdio.h>
3#include <stdlib.h>
4#include <assert.h>
5#define SIZE 4
6
7#ifdef _CIVL
8$input int _NPROCS=4;
9#endif
10
11int main (int argc, char *argv[])
12{
13 int numtasks, rank, sendcount, recvcount, source;
14 float sendbuf[SIZE];
15 float recvbuf[SIZE * SIZE];
16
17 MPI_Init(&argc,&argv);
18 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
19 MPI_Comm_size(MPI_COMM_WORLD, &numtasks);
20
21 if (numtasks == SIZE) {
22 source = 1;
23 sendcount = SIZE;
24 recvcount = SIZE;
25 //init sendbuf
26 for(int i=0; i<SIZE; i++)
27 sendbuf[i] = (float)(rank * SIZE + i);
28 MPI_Gather(sendbuf,sendcount,MPI_FLOAT,recvbuf,recvcount,
29 MPI_FLOAT,source,MPI_COMM_WORLD);
30 //assertions
31 if(rank == source){
32 for(int i=0; i<(SIZE*SIZE); i++){
33 printf("recvbuf[%d] : %f\n", i, recvbuf[i]);
34 assert(recvbuf[i] == i);
35 }
36 }
37 }
38 else
39 printf("Must specify %d processors. Terminating.\n",SIZE);
40
41 MPI_Finalize();
42}
Note: See TracBrowser for help on using the repository browser.