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.
10 /* The next is for isprint */
13 int main( int argc, char *argv[])
19 int errs = 0, toterrs;
20 int rank, size, tsize;
24 MPI_Datatype bases[2];
25 MPI_Datatype str, con;
27 int bufsize, position, insize;
29 MTest_Init( &argc, &argv );
31 MPI_Comm_rank( MPI_COMM_WORLD, &rank );
32 MPI_Comm_size( MPI_COMM_WORLD, &size );
34 for( j = 0; j < 10; j ++ ) {
36 s[j].c = j + rank + 'a';
39 blens[0] = blens[1] = 1;
40 disps[0] = 0; disps[1] = sizeof(int);
41 bases[0] = MPI_INT; bases[1] = MPI_CHAR;
42 MPI_Type_struct( 2, blens, disps, bases, &str );
43 MPI_Type_commit( &str );
44 MPI_Type_contiguous( 10, str, &con );
45 MPI_Type_commit( &con );
46 MPI_Type_size( con, &tsize );
47 MPI_Type_extent( con, &text );
50 printf("Size of MPI array is %d, extent is %d\n", tsize, text );
57 p2 = &(s[10].i); /* This statement may fail on some systems */
58 printf("C array starts at %p and ends at %p for a length of %d\n",
59 s, &(s[9].c), (char *)p2-(char *)p1 );
62 MPI_Type_extent( str, &text );
64 MPI_Type_size( str, &tsize );
65 printf("Size of MPI struct is %d, extent is %d\n", tsize, (int)text );
66 printf("Size of C struct is %d\n", sizeof(struct a) );
68 if (text != sizeof(struct a)) {
69 printf( "Extent of struct a (%d) does not match sizeof (%d)\n",
70 (int)text, (int)sizeof(struct a) );
74 MPI_Pack_size(1, con, MPI_COMM_WORLD, &bufsize);
75 buffer = (char *) malloc(bufsize);
78 MPI_Pack(s,1,con,buffer,bufsize,&position,MPI_COMM_WORLD);
81 MPI_Unpack(buffer,insize,&position,s1,1,con,MPI_COMM_WORLD );
83 for( j = 0; j < 10; j++ ) {
85 printf("%d Sent: %d %c, Got: %d %c\n", rank,
86 s[j].i, s[j].c, s1[j].i, s1[j].c );
88 if ( s1[j].i != j + rank ) {
90 printf( "Got s[%d].i = %d (%x); expected %d\n", j, s1[j].i,
93 if ( s1[j].c != 'a' + j + rank ) {
95 /* If the character is not a printing character,
96 this can generate an file that diff, for example,
97 believes is a binary file */
98 if (isprint( (int)(s1[j].c) )) {
99 printf( "Got s[%d].c = %c; expected %c\n", j, s1[j].c,
103 printf( "Got s[%d].c = %x; expected %c\n", j, (int)s1[j].c,
109 MPI_Type_free( &str );
110 MPI_Type_free( &con );
111 MTest_Finalize( errs );