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