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.
13 static char MTEST_Descrip[] = "Test that freed datatypes have reference count semantics";
19 int main( int argc, char *argv[] )
22 int rank, size, source, dest, i;
26 MPI_Datatype strideType;
27 MPI_Datatype tmpType[1024];
30 MTest_Init( &argc, &argv );
32 comm = MPI_COMM_WORLD;
34 MPI_Comm_rank( comm, &rank );
35 MPI_Comm_size( comm, &size );
38 fprintf( stderr, "This test requires at least two processes." );
39 MPI_Abort( MPI_COMM_WORLD, 1 );
46 The idea here is to create a simple but non-contig datatype,
47 perform an irecv with it, free it, and then create
48 many new datatypes. While not a complete test, if the datatype
49 was freed and the space was reused, this test may detect
51 A similar test for sends might work by sending a large enough message
52 to force the use of rendezvous send.
54 MPI_Type_vector( VEC_NELM, 1, VEC_STRIDE, MPI_INT, &strideType );
55 MPI_Type_commit( &strideType );
58 buf = (int *)malloc( VEC_NELM * VEC_STRIDE * sizeof(int) );
59 for (i=0; i<VEC_NELM*VEC_STRIDE; i++) buf[i] = -i;
60 MPI_Irecv( buf, 1, strideType, source, 0, comm, &req );
61 MPI_Type_free( &strideType );
63 for (i=0; i<1024; i++) {
64 MPI_Type_vector( VEC_NELM, 1, 1, MPI_INT, &tmpType[i] );
65 MPI_Type_commit( &tmpType[i] );
68 MPI_Sendrecv( 0, 0, MPI_INT, source, 1,
69 0, 0, MPI_INT, source, 1, comm, &status );
71 MPI_Wait( &req, &status );
72 for (i=0; i<VEC_NELM; i++) {
73 if (buf[VEC_STRIDE*i] != i) {
76 printf( "buf[%d] = %d, expected %d\n", VEC_STRIDE*i,
77 buf[VEC_STRIDE*i], i );
81 for (i=0; i<1024; i++) {
82 MPI_Type_free( &tmpType[i] );
86 else if (rank == source) {
87 buf = (int *)malloc( VEC_NELM * sizeof(int) );
88 for (i=0; i<VEC_NELM; i++) buf[i] = i;
89 /* Synchronize with the receiver */
90 MPI_Sendrecv( 0, 0, MPI_INT, dest, 1,
91 0, 0, MPI_INT, dest, 1, comm, &status );
92 MPI_Send( buf, VEC_NELM, MPI_INT, dest, 0, comm );
96 /* Clean up the strideType */
98 MPI_Type_free( &strideType );
102 MTest_Finalize( errs );