2 * This is a test of getting the number of basic elements
8 #if defined(NEEDS_STDLIB_PROTOTYPES)
17 int main( int argc, char **argv )
20 MPI_Datatype contig1, varstruct1, oldtypes[2], varstruct2;
26 int rank, size, partner, count, i;
27 int send_ibuf[4], recv_ibuf[4];
28 buf_t send_buf, recv_buf;
30 MPI_Init( &argc, &argv );
31 MPI_Comm_rank( MPI_COMM_WORLD, &world_rank );
33 /* Form the datatypes */
34 MPI_Type_contiguous( 4, MPI_INT, &contig1 );
35 MPI_Type_commit( &contig1 );
38 oldtypes[0] = MPI_INT;
39 oldtypes[1] = MPI_DOUBLE;
40 /* Note that the displacement for the data is probably double aligned */
41 MPI_Address( &send_buf.len, &displs[0] );
42 MPI_Address( &send_buf.data[0], &displs[1] );
44 displs[1] = displs[1] - displs[0];
46 MPI_Type_struct( 2, blens, displs, oldtypes, &varstruct1 );
47 MPI_Type_commit( &varstruct1 );
49 comm = MPI_COMM_WORLD;
51 MPI_Comm_size( comm, &size );
52 MPI_Comm_rank( comm, &rank );
55 fprintf( stderr, "This test requires at least 2 processes\n" );
56 MPI_Abort( MPI_COMM_WORLD, 1 );
59 if (rank == size - 1) {
61 /* Send contiguous data */
64 MPI_Send( send_ibuf, 1, contig1, partner, 0, comm );
66 /* Send partial structure */
68 MPI_Type_struct( 2, blens, displs, oldtypes, &varstruct2 );
69 MPI_Type_commit( &varstruct2 );
71 MPI_Send( &send_buf, 1, varstruct2, partner, 1, comm );
72 MPI_Type_free( &varstruct2 );
75 MPI_Send( MPI_BOTTOM, 0, MPI_INT, partner, 2, comm );
79 MPI_Recv( recv_ibuf, 1, contig1, partner, 0, comm, &status );
80 MPI_Get_count( &status, MPI_INT, &count );
84 "Wrong count for contig recv MPI_INT; got %d expected %d\n",
87 MPI_Get_count( &status, contig1, &count );
91 "Wrong count for contig recv (contig); got %d expected %d\n",
94 MPI_Get_elements( &status, contig1, &count );
98 "Wrong elements for contig recv contig; got %d expected %d\n",
102 /* Now, try the partial structure */
103 MPI_Recv( &recv_buf, 1, varstruct1, partner, 1, comm, &status );
104 MPI_Get_elements( &status, varstruct1, &count );
108 "Wrong number of elements for struct recv; got %d expected %d\n",
113 /* Receive nothing using a 0-sized type */
115 MPI_Type_contiguous( 0, MPI_INT, &ztype );
116 MPI_Type_commit( &ztype );
117 MPI_Recv( &recv_buf, 10, ztype, partner, 2, comm, &status );
118 /* Current clarification requires 0 for the result */
119 MPI_Get_elements( &status, ztype, &count );
123 "Wrong number of elements for 0-size datatype; got %d\n",
126 MPI_Get_count( &status, ztype, &count );
130 "Wrong count for 0-size datatype; got %d\n",
133 MPI_Type_free( &ztype );
136 MPI_Type_free( &contig1 );
137 MPI_Type_free( &varstruct1 );
139 MPI_Allreduce( &err, &toterr, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
140 if (world_rank == 0) {
142 printf( " No Errors\n" );
144 printf( "Found %d errors in MPI_Get_elements\n", toterr );