source: CIVL/examples/mpi/routines/Gather_Scatter/mpi_scatterv.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: 1.0 KB
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, source;
14 int sendcounts[4] = {2, 4, 5, 5};
15 int recvcounts[4] = {2, 4, 5, 5};
16 int displs[4] = {0, 2, 6, 11};
17 float sendbuf[SIZE * SIZE] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
18 float * recvbuf;
19
20 MPI_Init(&argc,&argv);
21 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
22 MPI_Comm_size(MPI_COMM_WORLD, &numtasks);
23
24 recvbuf = malloc(sizeof(float) * recvcounts[rank]);
25 if (numtasks == SIZE) {
26 source = 1;
27 MPI_Scatterv(sendbuf, sendcounts, displs, MPI_FLOAT, recvbuf, recvcounts[rank],
28 MPI_FLOAT, source, MPI_COMM_WORLD);
29 //assertions
30 for(int i=0; i<recvcounts[rank]; i++){
31 printf("process:%d recvbuf[%d] : %f\n", rank, i, recvbuf[i]);
32 assert(recvbuf[i] == displs[rank] + i);
33 }
34 }
35 else
36 printf("Must specify %d processors. Terminating.\n",SIZE);
37
38 MPI_Finalize();
39 free(recvbuf);
40}
Note: See TracBrowser for help on using the repository browser.