4 #if defined(NEEDS_STDLIB_PROTOTYPES)
8 int main( int argc, char *argv[] )
10 MPI_Datatype dt1, dt2, dt3;
11 MPI_Aint ex1, ex2, ex3;
15 MPI_Datatype types[3];
18 MPI_Init(&argc, &argv);
20 blocklen[0] = 1; blocklen[1] = 1; blocklen[2] = 1;
21 disp[0] = -3; disp[1] = 0; disp[2] = 6;
22 types[0] = MPI_LB; types[1] = MPI_INT; types[2] = MPI_UB;
24 MPI_Type_struct(3,blocklen,disp, types,&dt1);
25 MPI_Type_commit(&dt1);
27 MPI_Type_lb(dt1, &lb); MPI_Type_ub(dt1, &ub);
28 MPI_Type_extent(dt1,&ex1); MPI_Type_size(dt1,&sz1);
30 /* Values should be lb = -3, ub = 6 extent 9;
31 size depends on implementation */
32 if (lb != -3 || ub != 6 || ex1 != 9) {
33 printf("Example 3.26 type1 lb %d ub %d extent %d size %d\n",
34 (int)lb, (int)ub, (int)ex1, sz1);
37 printf("Example 3.26 type1 correct\n" );
39 MPI_Type_contiguous(2,dt1,&dt2);
40 MPI_Type_lb(dt2, &lb); MPI_Type_ub(dt2, &ub);
41 MPI_Type_extent(dt2,&ex2); MPI_Type_size(dt2,&sz2);
42 /* Values should be lb = -3, ub = 15, extent = 18, size
43 depends on implementation */
44 if (lb != -3 || ub != 15 || ex2 != 18) {
45 printf("Example 3.26 type2 lb %d ub %d extent %d size %d\n",
46 (int)lb, (int)ub, (int)ex2, sz2);
49 printf( "Example 3.26 type2 correct\n" );
51 types[0]=dt1; types[1]=dt1;
52 blocklen[0]=1; blocklen[1]=1;
53 disp[0]=0; disp[1]=ex1;
55 MPI_Type_struct(2, blocklen, disp, types, &dt3);
56 MPI_Type_commit(&dt3);
58 MPI_Type_lb(dt3, &lb); MPI_Type_ub(dt3, &ub);
59 MPI_Type_extent(dt3,&ex3); MPI_Type_size(dt3,&sz3);
60 /* Another way to express type2 */
61 if (lb != -3 || ub != 15 || ex3 != 18) {
62 printf("type3 lb %d ub %d extent %d size %d\n",
63 (int)lb, (int)ub, (int)ex3, sz2);
66 printf( "type3 correct\n" );
68 MPI_Type_free( &dt1 );
69 MPI_Type_free( &dt2 );
70 MPI_Type_free( &dt3 );