1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
3 * (C) 2014 by Argonne National Laboratory.
4 * See COPYRIGHT in top-level directory.
8 /* The next is for isprint */
12 int main( int argc, char *argv[])
19 int rank, size, tsize;
23 MPI_Datatype bases[2];
24 MPI_Datatype str, con;
27 MTest_Init( &argc, &argv );
29 MPI_Comm_rank( MPI_COMM_WORLD, &rank );
30 MPI_Comm_size( MPI_COMM_WORLD, &size );
32 for( j = 0; j < 10; j ++ ) {
34 s[j].c = j + rank + 'a';
37 blens[0] = blens[1] = 1;
38 disps[0] = 0; disps[1] = sizeof(int);
39 bases[0] = MPI_INT; bases[1] = MPI_CHAR;
40 MPI_Type_struct( 2, blens, disps, bases, &str );
41 MPI_Type_commit( &str );
42 MPI_Type_contiguous( 10, str, &con );
43 MPI_Type_commit( &con );
44 MPI_Type_size( con, &tsize );
45 MPI_Type_extent( con, &text );
47 MTestPrintfMsg( 0, "Size of MPI array is %d, extent is %d\n",
50 /* The following block of code is only for verbose-level output */
54 p2 = &(s[10].i); /* This statement may fail on some systems */
56 "C array starts at %p and ends at %p for a length of %d\n",
57 s, &(s[9].c), (char *)p2-(char *)p1 );
60 MPI_Type_extent( str, &text );
61 MPI_Type_size( str, &tsize );
62 MTestPrintfMsg( 0, "Size of MPI struct is %d, extent is %d\n",
64 MTestPrintfMsg( 0, "Size of C struct is %d\n", sizeof(struct a) );
65 if (text != sizeof(struct a)) {
67 "Extent of struct a (%d) does not match sizeof (%d)\n",
68 (int)text, (int)sizeof(struct a) );
72 MPI_Send( s, 1, con, rank ^ 1, 0, MPI_COMM_WORLD );
73 MPI_Recv( s1, 1, con, rank ^ 1, 0, MPI_COMM_WORLD, &status );
75 for( j = 0; j < 10; j++ ) {
76 MTestPrintfMsg( 0, "%d Sent: %d %c, Got: %d %c\n", rank,
77 s[j].i, s[j].c, s1[j].i, s1[j].c );
78 if ( s1[j].i != j + status.MPI_SOURCE ) {
80 fprintf( stderr, "Got s[%d].i = %d; expected %d\n", j, s1[j].i,
81 j + status.MPI_SOURCE );
83 if ( s1[j].c != 'a' + j + status.MPI_SOURCE ) {
85 /* If the character is not a printing character,
86 this can generate a file that diff, for example,
87 believes is a binary file */
88 if (isprint( (int)(s1[j].c) )) {
89 fprintf( stderr, "Got s[%d].c = %c; expected %c\n",
90 j, s1[j].c, j + status.MPI_SOURCE + 'a');
93 fprintf( stderr, "Got s[%d].c = %x; expected %c\n",
94 j, (int)s1[j].c, j + status.MPI_SOURCE + 'a');
99 MPI_Type_free( &str );
100 MPI_Type_free( &con );
102 MTest_Finalize( errs );