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++)
61 MPI_Irecv(buf, 1, strideType, source, 0, comm, &req);
62 MPI_Type_free(&strideType);
64 for (i = 0; i < 1024; i++) {
65 MPI_Type_vector(VEC_NELM, 1, 1, MPI_INT, &tmpType[i]);
66 MPI_Type_commit(&tmpType[i]);
69 MPI_Sendrecv(NULL, 0, MPI_INT, source, 1, NULL, 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, buf[VEC_STRIDE * i], i);
80 for (i = 0; i < 1024; i++) {
81 MPI_Type_free(&tmpType[i]);
85 else if (rank == source) {
86 buf = (int *) malloc(VEC_NELM * sizeof(int));
87 for (i = 0; i < VEC_NELM; i++)
89 /* Synchronize with the receiver */
90 MPI_Sendrecv(NULL, 0, MPI_INT, dest, 1, NULL, 0, MPI_INT, dest, 1, comm, &status);
91 MPI_Send(buf, VEC_NELM, MPI_INT, dest, 0, comm);
95 /* Clean up the strideType */
97 MPI_Type_free(&strideType);
101 MTest_Finalize(errs);