Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
4d17ffbd629fb61135781d707f16b3c180bce4be
[simgrid.git] / teshsuite / smpi / mpich-test / pt2pt / typeub.c
1 #include <math.h>
2 #include <stdio.h>
3 #include "mpi.h"
4
5 #if defined(NEEDS_STDLIB_PROTOTYPES)
6 #include "protofix.h"
7 #endif
8
9 /*
10  *      Trying to manipulate the extent of a datatype with succesive
11  *      calls to MPI_Type_struct.  Tests that a MPI_UB buried within
12  *      a structure is found.  From kalns@canidae.cps.msu.edu (modified to
13  *      fit test structure).
14  */
15 int main( int argc, char **argv )
16 {
17    int          errs = 0, toterrs, rank; 
18    MPI_Aint     extent;
19    int          blens[2];
20    MPI_Aint     displ[2];
21    MPI_Datatype types[2];
22    MPI_Datatype type1,type2,type3;
23    MPI_Aint     extent1, extent2, extent3;
24
25    MPI_Init( &argc, &argv );
26
27   /*    2 blocks of 1 int each, stride of 4 ; expect extent to be 20
28    */
29    MPI_Type_vector( 2, 1, 4, MPI_INT, &type1 );
30    MPI_Type_commit( &type1 );
31    MPI_Type_extent( type1, &extent );
32    extent1 = 5 * sizeof(int);
33    if (extent != extent1) {
34        errs++;
35        printf("extent(type1)=%ld\n",(long)extent);
36        }
37
38    blens[0]=1;
39    blens[1]=1;
40    displ[0]=0;
41    displ[1]=sizeof(int)*4;
42    types[0]=type1;
43    types[1]=MPI_UB;
44    extent2 = displ[1];
45
46   /*    using MPI_UB and Type_struct, monkey with the extent, making it 16
47    */
48    MPI_Type_struct( 2, blens, displ, types, &type2 );
49    MPI_Type_commit( &type2 );
50    MPI_Type_extent( type2, &extent );
51    if (extent != extent2) {
52        errs++;
53        printf("extent(type2)=%ld\n",(long)extent);
54        }
55
56   /*    monkey with the extent again, making it 4
57    *    ===> MPICH gives 4      
58    *    ===> MPIF gives 16, the old extent      
59    */
60    displ[1]=sizeof(int);
61    types[0]=type2;
62    types[1]=MPI_UB;
63    extent3 = extent2;
64
65    MPI_Type_struct( 2, blens, displ, types, &type3 );
66    MPI_Type_commit( &type3 );
67
68    MPI_Type_extent( type3, &extent );
69    if (extent != extent3 && extent != 4) {
70        errs++;
71        printf("extent(type3)=%ld\n",(long)extent);
72        }
73
74    MPI_Type_free( &type1 );
75    MPI_Type_free( &type2 );
76    MPI_Type_free( &type3 );
77
78    MPI_Allreduce( &errs, &toterrs, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
79    MPI_Comm_rank( MPI_COMM_WORLD, &rank );
80    if (rank == 0) {
81        if (toterrs == 0) printf( "No errors\n" );
82        else              printf( "Found %d errors\n", toterrs );
83    }
84
85
86    MPI_Finalize();
87    return 0;
88 }