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 );
42 int buf[128], position, cnt;
45 /* Create a datatype and send it (multiple of sizeof(int)) */
46 /* Create a send struct type */
47 oldtypes[0] = MPI_INT;
48 oldtypes[1] = MPI_CHAR;
50 blklens[1] = 4*sizeof(int);
52 offsets[1] = sizeof(int);
53 MPI_Type_struct( 2, blklens, offsets, oldtypes, &outtype );
54 MPI_Type_commit( &outtype );
56 buf[0] = 4*sizeof(int);
57 /* printf( "About to send to %d\n", dest ); */
58 MPI_Send( buf, 1, outtype, dest, 0, comm );
59 MPI_Type_free( &outtype );
61 /* Create a datatype and send it (not a multiple of sizeof(int)) */
62 /* Create a send struct type */
63 oldtypes[0] = MPI_INT;
64 oldtypes[1] = MPI_CHAR;
66 blklens[1] = 4*sizeof(int)+1;
68 offsets[1] = sizeof(int);
69 MPI_Type_struct( 2, blklens, offsets, oldtypes, &outtype );
70 MPI_Type_commit( &outtype );
72 buf[0] = 4*sizeof(int) + 1;
73 MPI_Send( buf, 1, outtype, dest, 1, comm );
74 MPI_Type_free( &outtype );
76 /* Pack data and send as packed */
79 MPI_Pack( &cnt, 1, MPI_INT,
80 buf, 128*sizeof(int), &position, comm );
81 MPI_Pack( (void*)"message", 7, MPI_CHAR,
82 buf, 128*sizeof(int), &position, comm );
83 MPI_Send( buf, position, MPI_PACKED, dest, 2, comm );
85 else if (rank == dest) {
87 int buf[128], i, elms, count;
90 /* Create a receive struct type */
91 oldtypes[0] = MPI_INT;
92 oldtypes[1] = MPI_CHAR;
96 offsets[1] = sizeof(int);
97 MPI_Type_struct( 2, blklens, offsets, oldtypes, &outtype );
98 MPI_Type_commit( &outtype );
100 for (i=0; i<3; i++) {
102 /* printf( "about to receive tag %d from %d\n", i, src ); */
103 MPI_Recv( buf, 1, outtype, src, tag, comm, &status );
104 MPI_Get_elements( &status, outtype, &elms );
105 if (elms != buf[0] + 1) {
107 printf( "For test %d, Get elements gave %d but should be %d\n",
108 i, elms, buf[0] + 1 );
110 MPI_Get_count( &status, outtype, &count );
111 if (count != MPI_UNDEFINED) {
113 printf( "For partial send, Get_count did not return MPI_UNDEFINED\n" );
116 MPI_Type_free( &outtype );
119 MTest_Finalize( errs );