source: CIVL/examples/mpi/c_ex11.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: 1.6 KB
Line 
1/*
2Shows how to use MPI_Type_vector to send noncontiguous blocks of data
3 and MPI_Get_count and MPI_Get_elements to see the number of elements sent
4*/
5#include <stdio.h>
6#include <stdlib.h>
7#include <mpi.h>
8#include <math.h>
9int main(argc,argv)
10int argc;
11char *argv[];
12{
13 int myid, numprocs,mpi_err;
14#define SIZE 25
15 double svect[SIZE],rvect[SIZE];
16 int i,bonk1,bonk2,numx,stride,extent;
17 MPI_Datatype MPI_LEFT_RITE;
18 MPI_Status status;
19
20 MPI_Init(&argc,&argv);
21 MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
22 MPI_Comm_rank(MPI_COMM_WORLD,&myid);
23
24 stride=5;
25 numx=(SIZE+1)/stride;
26 extent=1;
27 if(myid == 1){
28 printf("numx=%d extent=%d stride=%d\n",numx,extent,stride);
29 }
30 mpi_err=MPI_Type_vector(numx,extent,stride,MPI_DOUBLE,&MPI_LEFT_RITE);
31 mpi_err=MPI_Type_commit(&MPI_LEFT_RITE);
32 if(myid == 0){
33 for (i=0;i<SIZE;i++)
34 svect[i]=i;
35 MPI_Send(svect,1,MPI_LEFT_RITE,1,100,MPI_COMM_WORLD);
36 }
37 if(myid == 1){
38 for (i=0;i<SIZE;i++)
39 rvect[i]=-1;
40 MPI_Recv(rvect,1,MPI_LEFT_RITE,0,100,MPI_COMM_WORLD,&status);
41 }
42 if(myid == 1){
43 MPI_Get_count(&status,MPI_LEFT_RITE,&bonk1);
44 MPI_Get_elements(&status,MPI_DOUBLE,&bonk2);
45 printf("got %d elements of type MY_TYPE\n",bonk1);
46 printf("which contained %d elements of type MPI_DOUBLE\n",bonk2);
47 for (i=0;i<SIZE;i++)
48 if(rvect[i] != -1)printf("%d %g\n",i,rvect[i]);
49 }
50 MPI_Finalize();
51}
52/*
53output
54numx=5 extent=5 stride=1
55got 1 elements of type MY_TYPE
56which contained 5 elements of type MPI_DOUBLE
570 0
585 5
5910 10
6015 15
6120 20
62*/
Note: See TracBrowser for help on using the repository browser.