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[] = "Receive partial datatypes and check that\
14 MPI_Getelements gives the correct version";
17 int main(int argc, char *argv[])
20 MPI_Datatype outtype, oldtypes[2];
24 int size, rank, src, dest, tag;
26 MTest_Init(&argc, &argv);
28 comm = MPI_COMM_WORLD;
30 MPI_Comm_rank(comm, &rank);
31 MPI_Comm_size(comm, &size);
35 printf("This test requires at least 2 processes\n");
36 MPI_Abort(MPI_COMM_WORLD, 1);
43 int buf[128], position, cnt;
44 MTEST_VG_MEM_INIT(buf, 128 * sizeof(buf[0]));
47 /* Create a datatype and send it (multiple of sizeof(int)) */
48 /* Create a send struct type */
49 oldtypes[0] = MPI_INT;
50 oldtypes[1] = MPI_CHAR;
52 blklens[1] = 4 * sizeof(int);
54 offsets[1] = sizeof(int);
55 MPI_Type_struct(2, blklens, offsets, oldtypes, &outtype);
56 MPI_Type_commit(&outtype);
58 buf[0] = 4 * sizeof(int);
59 /* printf("About to send to %d\n", dest); */
60 MPI_Send(buf, 1, outtype, dest, 0, comm);
61 MPI_Type_free(&outtype);
63 /* Create a datatype and send it (not a multiple of sizeof(int)) */
64 /* Create a send struct type */
65 oldtypes[0] = MPI_INT;
66 oldtypes[1] = MPI_CHAR;
68 blklens[1] = 4 * sizeof(int) + 1;
70 offsets[1] = sizeof(int);
71 MPI_Type_struct(2, blklens, offsets, oldtypes, &outtype);
72 MPI_Type_commit(&outtype);
74 buf[0] = 4 * sizeof(int) + 1;
75 MPI_Send(buf, 1, outtype, dest, 1, comm);
76 MPI_Type_free(&outtype);
78 /* Pack data and send as packed */
81 MPI_Pack(&cnt, 1, MPI_INT, buf, 128 * sizeof(int), &position, comm);
82 MPI_Pack((void *) "message", 7, MPI_CHAR, 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", i, elms, buf[0] + 1);
109 MPI_Get_count(&status, outtype, &count);
110 if (count != MPI_UNDEFINED) {
112 printf("For partial send, Get_count did not return MPI_UNDEFINED\n");
115 MPI_Type_free(&outtype);
118 MTest_Finalize(errs);