Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
first commit to add the mpich-test suite to smpi tesh suite. Obviously all tests...
[simgrid.git] / teshsuite / smpi / mpich-test / pt2pt / typeub3.c
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 */
3
4 #include "mpi.h"
5 #include <stdio.h>
6
7 #if defined(NEEDS_STDLIB_PROTOTYPES)
8 #include "protofix.h"
9 #endif
10  
11 int main( int argc, char *argv[] )
12 {
13     MPI_Datatype dt1, dt2, dt3, dt4, dt5;
14     MPI_Aint     ex;
15     int          sz;
16     MPI_Aint     lb,ub;
17     MPI_Aint     disp[3];
18     MPI_Datatype types[3];
19     int          blocklen[3];
20     int          idisp[3];
21
22     MPI_Init(&argc, &argv);
23
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;
28  
29     /* Generate samples for contiguous, hindexed, hvector, indexed, 
30        and vector (struct and contiguous tested in typeub2) */
31
32     MPI_Type_struct(3,blocklen,disp, types,&dt1);
33     MPI_Type_commit(&dt1);
34
35     /* This type is the same as in typeub2, and is tested there */
36     
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;
41
42     MPI_Type_hindexed( 2, blocklen, disp, dt1, &dt2 );
43     MPI_Type_commit( &dt2 );
44
45         MPI_Type_lb( dt2, &lb );       MPI_Type_ub( dt2, &ub );
46         MPI_Type_extent( dt2, &ex );   MPI_Type_size( dt2, &sz );
47
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);
51         }
52         else 
53             printf( "hindexed ok\n" );
54
55     MPI_Type_indexed( 2, blocklen, idisp, dt1, &dt3 );
56     MPI_Type_commit( &dt3 );
57
58         MPI_Type_lb( dt3, &lb );       MPI_Type_ub( dt3, &ub );
59         MPI_Type_extent( dt3, &ex );   MPI_Type_size( dt3, &sz );
60
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);
64         }
65         else 
66             printf( "indexed ok\n" );
67
68     MPI_Type_hvector( 2, 1, 14, dt1, &dt4 );
69     MPI_Type_commit( &dt4 );
70
71         MPI_Type_lb( dt4, &lb );       MPI_Type_ub( dt4, &ub );
72         MPI_Type_extent( dt4, &ex );   MPI_Type_size( dt4, &sz );
73
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);
77         }
78         else 
79             printf( "hvector ok\n" );
80
81     MPI_Type_vector( 2, 1, 14, dt1, &dt5 );
82     MPI_Type_commit( &dt5 );
83     
84         MPI_Type_lb( dt5, &lb );       MPI_Type_ub( dt5, &ub );
85         MPI_Type_extent( dt5, &ex );   MPI_Type_size( dt5, &sz );
86
87  
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);
91         }
92         else 
93             printf( "vector ok\n" );
94
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 );
100
101     MPI_Finalize();
102     return 0;
103 }
104