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 / dataalign.c
1 #include "test.h"
2 #include <stdio.h>
3 #include "mpi.h"
4 #include <ctype.h>
5
6
7 int main( int argc, char *argv[])
8 {
9         struct a {      int     i;
10                         char    c;
11                 } s[10], s1[10];
12         int j;
13         int errs = 0, toterrs;
14         int rank, size, tsize;
15         MPI_Aint text;
16         int blens[2]; 
17         MPI_Aint disps[2];
18         MPI_Datatype bases[2];
19         MPI_Datatype str, con;
20         MPI_Status status;
21
22         MPI_Init( &argc, &argv );
23
24         MPI_Comm_rank( MPI_COMM_WORLD, &rank );
25         MPI_Comm_size( MPI_COMM_WORLD, &size );
26
27         for( j = 0; j < 10; j ++ ) {
28                 s[j].i = j + rank;
29                 s[j].c = j + rank + 'a';
30         }
31
32         blens[0] = blens[1] = 1;
33         disps[0] = 0; disps[1] = sizeof(int);
34         bases[0] = MPI_INT; bases[1] = MPI_CHAR;
35         MPI_Type_struct( 2, blens, disps, bases, &str );
36         MPI_Type_commit( &str );
37         MPI_Type_contiguous( 10, str, &con );
38         MPI_Type_commit( &con );
39         MPI_Type_size( con, &tsize );
40         MPI_Type_extent( con, &text );
41
42 #ifdef DEBUG
43         printf("Size of MPI array is %d, extent is %d\n", tsize, text );
44 #endif
45
46 #ifdef DEBUG
47         {
48         void * p1, *p2;
49         p1 = s;
50         p2 = &(s[10].i);  /* This statement may fail on some systems */
51         printf("C array starts at %p and ends at %p for a length of %d\n",
52                 s, &(s[9].c), (char *)p2-(char *)p1 );
53         }
54 #endif
55         MPI_Type_extent( str, &text );
56 #ifdef DEBUG
57         MPI_Type_size( str, &tsize );
58         printf("Size of MPI struct is %d, extent is %d\n", tsize, (int)text );
59         printf("Size of C struct is %d\n", sizeof(struct a) );
60 #endif
61         if (text != sizeof(struct a)) {
62             printf( "Extent of struct a (%d) does not match sizeof (%d)\n",
63                     (int)text, (int)sizeof(struct a) );
64             errs++;
65         }
66
67         MPI_Send( s, 1, con, rank ^ 1, 0, MPI_COMM_WORLD );
68         MPI_Recv( s1, 1, con, rank ^ 1, 0, MPI_COMM_WORLD, &status );
69
70         for( j = 0; j < 10; j++ ) {
71 #ifdef DEBUG        
72                 printf("%d Sent: %d %c, Got: %d %c\n", rank,
73                         s[j].i, s[j].c, s1[j].i, s1[j].c );
74 #endif
75                 if ( s1[j].i != j + status.MPI_SOURCE ) {
76                     errs++;
77                     printf( "Got s[%d].i = %d; expected %d\n", j, s1[j].i,
78                             j + status.MPI_SOURCE );
79                 }
80                 if ( s1[j].c != 'a' + j + status.MPI_SOURCE ) {
81                     errs++;
82                     /* If the character is not a printing character, 
83                        this can generate an file that diff, for example,
84                        believes is a binary file */
85                     if (isprint( (int)(s1[j].c) )) {
86                         printf( "Got s[%d].c = %c; expected %c\n", j, s1[j].c,
87                                 j + status.MPI_SOURCE + 'a');
88                     }
89                     else {
90                         printf( "Got s[%d].c = %x; expected %c\n", j, (int)s1[j].c,
91                                 j + status.MPI_SOURCE + 'a');
92                     }
93                 }
94         }
95
96         MPI_Allreduce( &errs, &toterrs, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
97         if (rank == 0) {
98             if (toterrs > 0) printf( "Found %d errors\n", toterrs );
99             else             printf( " No Errors\n" );
100         }
101         MPI_Type_free( &str );
102         MPI_Type_free( &con );
103         MPI_Finalize();
104         return 0;
105 }