1 /* This test checks that all of the MPI Type routines correctly compute
2 the UB and LB of a datatype from the greatest/least instance */
7 #if defined(NEEDS_STDLIB_PROTOTYPES)
11 int main( int argc, char *argv[] )
13 MPI_Datatype dt1, dt2, dt3, dt4, dt5;
18 MPI_Datatype types[3];
22 MPI_Init(&argc, &argv);
24 /* Create a datatype with explicit LB and UB */
25 blocklen[0] = 1; blocklen[1] = 1; blocklen[2] = 1;
26 disp[0] = -3; disp[1] = 0; disp[2] = 6;
27 types[0] = MPI_LB; types[1] = MPI_INT; types[2] = MPI_UB;
29 /* Generate samples for contiguous, hindexed, hvector, indexed,
30 and vector (struct and contiguous tested in typeub2) */
32 MPI_Type_struct(3,blocklen,disp, types,&dt1);
33 MPI_Type_commit(&dt1);
35 /* This type is the same as in typeub2, and is tested there */
37 types[0]=dt1; types[1]=dt1;
38 blocklen[0]=1; blocklen[1]=1;
39 disp[0]=-4; disp[1]=7;
40 idisp[0]=-4; idisp[1]=7;
42 MPI_Type_hindexed( 2, blocklen, disp, dt1, &dt2 );
43 MPI_Type_commit( &dt2 );
45 MPI_Type_lb( dt2, &lb ); MPI_Type_ub( dt2, &ub );
46 MPI_Type_extent( dt2, &ex ); MPI_Type_size( dt2, &sz );
48 if (lb != -7 || ub != 13 || ex != 20) {
49 printf("hindexed lb %d ub %d extent %d size %d\n",
50 (int)lb, (int)ub, (int)ex, sz);
53 printf( "hindexed ok\n" );
55 MPI_Type_indexed( 2, blocklen, idisp, dt1, &dt3 );
56 MPI_Type_commit( &dt3 );
58 MPI_Type_lb( dt3, &lb ); MPI_Type_ub( dt3, &ub );
59 MPI_Type_extent( dt3, &ex ); MPI_Type_size( dt3, &sz );
61 if (lb != -39 || ub != 69 || ex != 108) {
62 printf("indexed lb %d ub %d extent %d size %d\n",
63 (int)lb, (int)ub, (int)ex, sz);
66 printf( "indexed ok\n" );
68 MPI_Type_hvector( 2, 1, 14, dt1, &dt4 );
69 MPI_Type_commit( &dt4 );
71 MPI_Type_lb( dt4, &lb ); MPI_Type_ub( dt4, &ub );
72 MPI_Type_extent( dt4, &ex ); MPI_Type_size( dt4, &sz );
74 if (lb != -3 || ub != 20 || ex != 23) {
75 printf("hvector lb %d ub %d extent %d size %d\n",
76 (int)lb, (int)ub, (int)ex, sz);
79 printf( "hvector ok\n" );
81 MPI_Type_vector( 2, 1, 14, dt1, &dt5 );
82 MPI_Type_commit( &dt5 );
84 MPI_Type_lb( dt5, &lb ); MPI_Type_ub( dt5, &ub );
85 MPI_Type_extent( dt5, &ex ); MPI_Type_size( dt5, &sz );
88 if (lb != -3 || ub != 132 || ex != 135) {
89 printf("vector lb %d ub %d extent %d size %d\n",
90 (int)lb, (int)ub, (int)ex, sz);
93 printf( "vector ok\n" );
95 MPI_Type_free( &dt1 );
96 MPI_Type_free( &dt2 );
97 MPI_Type_free( &dt3 );
98 MPI_Type_free( &dt4 );
99 MPI_Type_free( &dt5 );