Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add fortran tests from mpich-tests, enforce completion of mpich-tests suite with...
[simgrid.git] / teshsuite / smpi / mpich-test / pt2pt / typeub2.c
1 #include "mpi.h"
2 #include <stdio.h>
3
4 #if defined(NEEDS_STDLIB_PROTOTYPES)
5 #include "protofix.h"
6 #endif
7  
8 int main( int argc, char *argv[] )
9 {
10     MPI_Datatype dt1, dt2, dt3;
11     MPI_Aint     ex1, ex2, ex3;
12     int          sz1, sz2, sz3;
13     MPI_Aint     lb,ub;
14     MPI_Aint     disp[3];
15     MPI_Datatype types[3];
16     int          blocklen[3];
17  
18     MPI_Init(&argc, &argv);
19  
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;
23  
24     MPI_Type_struct(3,blocklen,disp, types,&dt1);
25     MPI_Type_commit(&dt1);
26  
27         MPI_Type_lb(dt1, &lb);          MPI_Type_ub(dt1, &ub);
28         MPI_Type_extent(dt1,&ex1);      MPI_Type_size(dt1,&sz1);
29
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);
35         }
36         else 
37             printf("Example 3.26 type1 correct\n" );
38  
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);
47         }
48         else 
49             printf( "Example 3.26 type2 correct\n" );
50  
51     types[0]=dt1;               types[1]=dt1;
52     blocklen[0]=1;              blocklen[1]=1;
53     disp[0]=0;                  disp[1]=ex1;
54  
55     MPI_Type_struct(2, blocklen, disp, types, &dt3);
56     MPI_Type_commit(&dt3);
57  
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);
64         }
65         else 
66             printf( "type3 correct\n" );
67  
68     MPI_Type_free( &dt1 );
69     MPI_Type_free( &dt2 );
70     MPI_Type_free( &dt3 );
71         
72     MPI_Finalize();
73     return 0;
74 }
75