1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
3 * (C) 2014 by Argonne National Laboratory.
4 * See COPYRIGHT in top-level directory.
11 /* Communicating a datatype built out of structs
12 * This test was motivated by the failure of an example program for
13 * RMA involving simple operations on a struct that included a struct
15 * The observed failure was a SEGV in the MPI_Get
19 #define MAX_KEY_SIZE 64
20 #define MAX_VALUE_SIZE 256
28 char key[MAX_KEY_SIZE], value[MAX_VALUE_SIZE];
30 Rptr nullDptr = { 0, -1, 0 };
34 #define TWO_STRUCT 0x2
37 int main(int argc, char **argv)
41 ListElm *headLptr = 0;
43 MPI_Datatype dptrType, listelmType;
46 MTest_Init(&argc, &argv);
47 MPI_Comm_rank(MPI_COMM_WORLD, &wrank);
49 for (i = 1; i < argc; i++) {
50 if (strcmp(argv[i], "-byteonly") == 0) {
51 testCases = BYTE_ONLY;
53 else if (strcmp(argv[i], "-twostruct") == 0) {
54 testCases = TWO_STRUCT;
56 else if (strcmp(argv[i], "-onelevel") == 0) {
60 printf("Unrecognized argument %s\n", argv[i]);
64 /* Create the datatypes that we will use to move the data */
68 MPI_Datatype dtypes[3];
73 MPI_Get_address(&nullDptr.disp, &displ[0]);
74 MPI_Get_address(&nullDptr.rank, &displ[1]);
75 displ[1] = displ[1] - displ[0];
79 MPI_Type_create_struct(2, blens, displ, dtypes, &dptrType);
80 MPI_Type_commit(&dptrType);
83 blens[0] = sizeof(nullDptr);
90 blens[1] = MAX_KEY_SIZE;
92 blens[2] = MAX_VALUE_SIZE;
94 MPI_Get_address(&sampleElm.next, &displ[0]);
95 MPI_Get_address(&sampleElm.key[0], &displ[1]);
96 MPI_Get_address(&sampleElm.value[0], &displ[2]);
100 for (i = 0; i < 3; i++) {
101 MTestPrintfMsg(0, "%d:count=%d,disp=%ld\n", i, blens[i], displ[i]);
103 MPI_Type_create_struct(3, blens, displ, dtypes, &listelmType);
104 MPI_Type_commit(&listelmType);
107 MPI_Win_create_dynamic(MPI_INFO_NULL, MPI_COMM_WORLD, &listwin);
111 /* Create 1 list element (the head) and initialize it */
112 MPI_Alloc_mem(sizeof(ListElm), MPI_INFO_NULL, &headLptr);
113 MPI_Get_address(headLptr, &headDptr.disp);
114 headLptr->next.rank = -1;
115 headLptr->next.disp = (MPI_Aint) MPI_BOTTOM;
116 headLptr->next.lptr = 0;
117 strncpy(headLptr->key, "key1", MAX_KEY_SIZE);
118 strncpy(headLptr->value, "value1", MAX_VALUE_SIZE);
119 MPI_Win_attach(listwin, headLptr, sizeof(ListElm));
121 MPI_Bcast(&headDptr.disp, 1, MPI_AINT, 0, MPI_COMM_WORLD);
123 MPI_Barrier(MPI_COMM_WORLD);
128 MPI_Win_lock_all(0, listwin);
129 /* Get head element with simple get of BYTES */
130 if (testCases & BYTE_ONLY) {
131 headcopy.next.rank = 100;
132 headcopy.next.disp = 0xefefefef;
133 MPI_Get(&headcopy, sizeof(ListElm), MPI_BYTE,
134 headDptr.rank, headDptr.disp, sizeof(ListElm), MPI_BYTE, listwin);
135 MPI_Win_flush(headDptr.rank, listwin);
136 if (headcopy.next.rank != -1 && headcopy.next.disp != (MPI_Aint) MPI_BOTTOM) {
138 printf("MPI_BYTE: headcopy contains incorrect next:<%d,%ld>\n",
139 headcopy.next.rank, (long) headcopy.next.disp);
143 if (testCases & TWO_STRUCT) {
144 headcopy.next.rank = 100;
145 headcopy.next.disp = 0xefefefef;
146 /* Get head element using struct of struct type. This is
147 * not an identical get to the simple BYTE one above but should
149 MPI_Get(&headcopy, 1, listelmType, headDptr.rank, headDptr.disp,
150 1, listelmType, listwin);
151 MPI_Win_flush(headDptr.rank, listwin);
152 if (headcopy.next.rank != -1 && headcopy.next.disp != (MPI_Aint) MPI_BOTTOM) {
154 printf("ListelmType: headcopy contains incorrect next:<%d,%ld>\n",
155 headcopy.next.rank, (long) headcopy.next.disp);
159 MPI_Win_unlock_all(listwin);
161 MPI_Barrier(MPI_COMM_WORLD);
163 MPI_Win_detach(listwin, headLptr);
164 MPI_Free_mem(headLptr);
166 MPI_Win_free(&listwin);
167 MPI_Type_free(&dptrType);
168 MPI_Type_free(&listelmType);
170 MTest_Finalize(errors);
172 return MTestReturnValue(errors);