Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
remove few tests which may never finish, and change one that used too much stack...
[simgrid.git] / teshsuite / smpi / mpich-test / pt2pt / typebase.c
1 /*
2  */
3 #include "mpi.h"
4 #include <stdio.h>
5 #include "test.h"
6
7 /* 
8  * This program checks that the type inquiry routines work with the 
9  * basic types
10  */
11
12 #define MAX_TYPES 14
13 static int ntypes;
14 static MPI_Datatype BasicTypes[MAX_TYPES];
15 static char         *(BasicTypesName[MAX_TYPES]);
16 static int          BasicSizes[MAX_TYPES];
17
18 /* Prototypes for picky compilers */
19 void SetupBasicTypes (void);
20
21 void 
22 SetupBasicTypes()
23 {
24     BasicTypes[0] = MPI_CHAR;
25     BasicTypes[1] = MPI_SHORT;
26     BasicTypes[2] = MPI_INT;
27     BasicTypes[3] = MPI_LONG;
28     BasicTypes[4] = MPI_UNSIGNED_CHAR;
29     BasicTypes[5] = MPI_UNSIGNED_SHORT;
30     BasicTypes[6] = MPI_UNSIGNED;
31     BasicTypes[7] = MPI_UNSIGNED_LONG;
32     BasicTypes[8] = MPI_FLOAT;
33     BasicTypes[9] = MPI_DOUBLE;
34
35     BasicTypesName[0] = (char*)"MPI_CHAR";
36     BasicTypesName[1] = (char*)"MPI_SHORT";
37     BasicTypesName[2] = (char*)"MPI_INT";
38     BasicTypesName[3] = (char*)"MPI_LONG";
39     BasicTypesName[4] = (char*)"MPI_UNSIGNED_CHAR";
40     BasicTypesName[5] = (char*)"MPI_UNSIGNED_SHORT";
41     BasicTypesName[6] = (char*)"MPI_UNSIGNED";
42     BasicTypesName[7] = (char*)"MPI_UNSIGNED_LONG";
43     BasicTypesName[8] = (char*)"MPI_FLOAT";
44     BasicTypesName[9] = (char*)"MPI_DOUBLE";
45
46     BasicSizes[0] = sizeof(char);
47     BasicSizes[1] = sizeof(short);
48     BasicSizes[2] = sizeof(int);
49     BasicSizes[3] = sizeof(long);
50     BasicSizes[4] = sizeof(unsigned char);
51     BasicSizes[5] = sizeof(unsigned short);
52     BasicSizes[6] = sizeof(unsigned);
53     BasicSizes[7] = sizeof(unsigned long);
54     BasicSizes[8] = sizeof(float);
55     BasicSizes[9] = sizeof(double);
56
57     ntypes = 10;
58 #ifdef HAVE_LONG_DOUBLE
59     BasicTypes[ntypes] = MPI_LONG_DOUBLE;
60     BasicSizes[ntypes] = sizeof(long double);
61     BasicTypesName[ntypes] = (char*)"MPI_LONG_DOUBLE";
62     ntypes++;
63 #endif
64     BasicTypes[ntypes] = MPI_BYTE;
65     BasicSizes[ntypes] = sizeof(unsigned char);
66     BasicTypesName[ntypes] = (char*)"MPI_BYTE";
67     ntypes++;
68
69 #ifdef HAVE_LONG_LONG_INT
70     BasicTypes[ntypes] = MPI_LONG_LONG_INT;
71     BasicSizes[ntypes] = sizeof(long long);
72     BasicTypesName[ntypes] = "MPI_LONG_LONG_INT";
73     ntypes++;
74 #endif
75     }
76
77 int main( int argc, char **argv )
78 {
79 int      i, errs;
80 int      size;
81 MPI_Aint extent, lb, ub;
82  
83 MPI_Init( &argc, &argv );
84
85 /* This should be run by a single process */
86
87 SetupBasicTypes();
88
89 errs = 0;
90 for (i=0; i<ntypes; i++) {
91     MPI_Type_size( BasicTypes[i], &size );
92     MPI_Type_extent( BasicTypes[i], &extent );
93     MPI_Type_lb( BasicTypes[i], &lb );
94     MPI_Type_ub( BasicTypes[i], &ub );
95     if (size != extent) {
96         errs++;
97         printf( "size (%d) != extent (%ld) for basic type %s\n", size, 
98                 (long) extent, BasicTypesName[i] );
99         }
100     if (size != BasicSizes[i]) {
101         errs++;
102         printf( "size(%d) != C size (%d) for basic type %s\n", size, 
103                BasicSizes[i], BasicTypesName[i] );
104         }
105     if (lb != 0) {
106         errs++;
107         printf( "Lowerbound of %s was %d instead of 0\n", 
108                 BasicTypesName[i], (int)lb );
109         }
110     if (ub != extent) {
111         errs++;
112         printf( "Upperbound of %s was %d instead of %d\n", 
113                 BasicTypesName[i], (int)ub, (int)extent );
114         }
115     }
116
117 if (errs) {
118     printf( "Found %d errors in testing C types\n", errs );
119     }
120 else {
121     printf( "Found no errors in basic C types\n" );
122     }
123
124 MPI_Finalize( );
125 return 0;
126 }