Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add mpich3 test suite, to replace older one.
[simgrid.git] / teshsuite / smpi / mpich-test / pt2pt / commit.c
1 /*
2  * This is a test of Type_commit.  This checks to see if Type_commit
3  * (or Type_struct) replaces a struct with a contiguous type, and
4  * that that type is constructed correctly.
5  */
6
7 #include "mpi.h"
8 #include <stdio.h>
9
10 #if defined(NEEDS_STDLIB_PROTOTYPES)
11 #include "protofix.h"
12 #endif
13
14 int main( int argc, char **argv )
15 {
16     int          nsize, n2size;
17     MPI_Aint     nlb, nub, n2lb, n2ub;
18     MPI_Datatype ntype, n2type;
19     MPI_Aint     displs[2];
20     MPI_Datatype types[2];
21     int          blockcounts[2];
22     double       myarray[10];
23     int          err = 0;
24
25     MPI_Init( &argc, &argv );
26     
27     MPI_Address( &myarray[0], &displs[0] );
28     MPI_Address( &myarray[3], &displs[1] );
29     blockcounts[0] = 3;
30     blockcounts[1] = 1;
31     displs[1] = displs[1] - displs[0];
32     displs[0] = 0;
33     types[0] = MPI_DOUBLE;
34     types[1] = MPI_DOUBLE;
35     MPI_Type_struct( 2, blockcounts, displs, types, &ntype );
36     MPI_Type_commit( &ntype );
37
38     MPI_Type_size( ntype, &nsize );
39     MPI_Type_lb( ntype, &nlb );
40     MPI_Type_ub( ntype, &nub );
41
42     if (nlb != 0) {
43         err++;
44         printf( "LB for struct is %d\n", (int)nlb );
45     }
46     if (nub != 4 * sizeof(double)) {
47         err++;
48         printf( "UB for struct is %d != %d\n", (int)nub, 
49                 4 * (int)sizeof(double) );
50     }
51     if (nsize != 4 * sizeof(double)) {
52         err++;
53         printf( "Size for struct %d != %d\n", nsize, 4 * (int)sizeof(double) );
54     }
55
56     MPI_Type_contiguous( 3, ntype, &n2type );
57     MPI_Type_commit( &n2type );
58
59     MPI_Type_size( n2type, &n2size );
60     MPI_Type_lb( n2type, &n2lb );
61     MPI_Type_ub( n2type, &n2ub );
62
63     if (n2size != 3 * nsize) {
64         err++;
65         printf( "Size of contig type %d != %d\n", n2size, 3*nsize );
66     }
67     if (n2lb != 0) {
68         err++;
69         printf( "LB for contig is %d\n", (int)n2lb );
70     }
71     if (n2ub != 3 * nub) {
72         err++;
73         printf( "UB for contig %d != %d\n", (int)n2ub, 3 * (int)nub );
74     }
75
76     if (err) {
77         printf( "Found %d errors\n", err );
78     }
79     else {
80         printf( " No Errors\n" );
81     }
82     MPI_Type_free( &ntype );
83     MPI_Type_free( &n2type );
84     MPI_Finalize();
85     return 0;
86 }