1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
4 * (C) 2003 by Argonne National Laboratory.
5 * See COPYRIGHT in top-level directory.
12 static char MTest_descrip[] = "Receive partial datatypes and check that\
13 MPI_Getelements gives the correct version";
16 int main( int argc, char *argv[] )
19 MPI_Datatype outtype, oldtypes[2];
23 int size, rank, src, dest, tag;
25 MTest_Init( &argc, &argv );
27 comm = MPI_COMM_WORLD;
29 MPI_Comm_rank( comm, &rank );
30 MPI_Comm_size( comm, &size );
34 printf( "This test requires at least 2 processes\n" );
35 MPI_Abort( MPI_COMM_WORLD, 1 );
43 int buf[128], position, cnt;
46 /* Create a datatype and send it (multiple of sizeof(int)) */
47 /* Create a send struct type */
48 oldtypes[0] = MPI_INT;
49 oldtypes[1] = MPI_CHAR;
51 blklens[1] = 4*sizeof(int);
53 offsets[1] = sizeof(int);
54 MPI_Type_struct( 2, blklens, offsets, oldtypes, &outtype );
55 MPI_Type_commit( &outtype );
57 buf[0] = 4*sizeof(int);
58 /* printf( "About to send to %d\n", dest ); */
59 MPI_Send( buf, 1, outtype, dest, 0, comm );
60 MPI_Type_free( &outtype );
62 /* Create a datatype and send it (not a multiple of sizeof(int)) */
63 /* Create a send struct type */
64 oldtypes[0] = MPI_INT;
65 oldtypes[1] = MPI_CHAR;
67 blklens[1] = 4*sizeof(int)+1;
69 offsets[1] = sizeof(int);
70 MPI_Type_struct( 2, blklens, offsets, oldtypes, &outtype );
71 MPI_Type_commit( &outtype );
73 buf[0] = 4*sizeof(int) + 1;
74 MPI_Send( buf, 1, outtype, dest, 1, comm );
75 MPI_Type_free( &outtype );
77 /* Pack data and send as packed */
80 MPI_Pack( &cnt, 1, MPI_INT,
81 buf, 128*sizeof(int), &position, comm );
82 MPI_Pack( (void*)"message", 7, MPI_CHAR,
83 buf, 128*sizeof(int), &position, comm );
84 MPI_Send( buf, position, MPI_PACKED, dest, 2, comm );
86 else if (rank == dest) {
88 int buf[128], i, elms, count;
91 /* Create a receive struct type */
92 oldtypes[0] = MPI_INT;
93 oldtypes[1] = MPI_CHAR;
97 offsets[1] = sizeof(int);
98 MPI_Type_struct( 2, blklens, offsets, oldtypes, &outtype );
99 MPI_Type_commit( &outtype );
101 for (i=0; i<3; i++) {
103 /* printf( "about to receive tag %d from %d\n", i, src ); */
104 MPI_Recv( buf, 1, outtype, src, tag, comm, &status );
105 MPI_Get_elements( &status, outtype, &elms );
106 if (elms != buf[0] + 1) {
108 printf( "For test %d, Get elements gave %d but should be %d\n",
109 i, elms, buf[0] + 1 );
111 MPI_Get_count( &status, outtype, &count );
112 if (count != MPI_UNDEFINED) {
114 printf( "For partial send, Get_count did not return MPI_UNDEFINED\n" );
117 MPI_Type_free( &outtype );
120 MTest_Finalize( errs );