This source file includes following definitions.
- print_hex
- print_bar_pbar
- testcase
- unpack_ooo
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 #include "ompi_config.h"
17 #include "ompi/datatype/ompi_datatype.h"
18 #include "opal/runtime/opal.h"
19 #include "opal/datatype/opal_convertor.h"
20 #include "opal/datatype/opal_datatype_internal.h"
21
22 #include <time.h>
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <string.h>
26 #include <unistd.h>
27
28 #define N 331
29
30 uint32_t remote_arch = 0xffffffff;
31
32 struct foo_t {
33 int i[3];
34 double d[3];
35 } foo = {0}, *bar = NULL;
36
37 struct pfoo_t {
38 int i[2];
39 double d[2];
40 } pfoo = {0}, *pbar = NULL;
41
42 static void print_hex(void* ptr, int count, int space)
43 {
44 for( int i = 0; i < count; i++ ) {
45 fprintf(stderr, "%02x", (unsigned int)(((unsigned char*)ptr)[i]));
46 }
47 if(space) fprintf(stderr, " ");
48 }
49
50 static void print_bar_pbar(struct foo_t* bar, struct pfoo_t* pbar)
51 {
52 print_hex(&bar->i[0], sizeof(int), 1);
53 print_hex(&bar->i[2], sizeof(int), 1);
54 print_hex(&bar->d[0], sizeof(double), 1);
55 print_hex(&bar->d[2], sizeof(double), 1);
56 fprintf(stderr, "\n");
57 print_hex(&pbar->i[0], sizeof(int), 1);
58 print_hex(&pbar->i[1], sizeof(int), 1);
59 print_hex(&pbar->d[0], sizeof(double), 1);
60 print_hex(&pbar->d[1], sizeof(double), 1);
61 fprintf(stderr, "\n");
62 }
63
64 static int testcase(ompi_datatype_t * newtype, size_t arr[10][2]) {
65 int i, j, errors = 0;
66 struct iovec a;
67 unsigned int iov_count;
68 size_t max_data;
69 size_t pos;
70 opal_convertor_t * pConv;
71
72 for (j = 0; j < N; ++j) {
73 pbar[j].i[0] = 123+j;
74 pbar[j].i[1] = 789+j;
75 pbar[j].d[0] = 123.456+j;
76 pbar[j].d[1] = 789.123+j;
77 memset(&bar[j].i[0], 0xFF, sizeof(int));
78 memset(&bar[j].i[2], 0xFF, sizeof(int));
79 bar[j].i[1] = 0;
80 memset(&bar[j].d[0], 0xFF, sizeof(double));
81 memset(&bar[j].d[2], 0xFF, sizeof(double));
82 bar[j].d[1] = 0.0;
83 }
84
85 pConv = opal_convertor_create( remote_arch, 0 );
86 if( OPAL_SUCCESS != opal_convertor_prepare_for_recv( pConv, &(newtype->super), N, bar ) ) {
87 printf( "Cannot attach the datatype to a convertor\n" );
88 return OMPI_ERROR;
89 }
90
91 for (i=0; arr[i][0] != 0; i++) {
92
93 a.iov_base = malloc(arr[i][0]+2048);
94 if (NULL == a.iov_base) {
95 printf("cannot malloc iov_base\n");
96 return 1;
97 }
98 memset(a.iov_base, 0xAA, 1024);
99 memcpy((char*)a.iov_base+1024, (char *)pbar + arr[i][1], arr[i][0]);
100 memset((char*)a.iov_base+1024+arr[i][0], 0xAA, 1024);
101 a.iov_base = (char*)a.iov_base + 1024;
102 a.iov_len = arr[i][0];
103 iov_count = 1;
104 max_data = a.iov_len;
105 pos = arr[i][1];
106 opal_convertor_set_position(pConv, &pos);
107 assert(arr[i][1] == pos);
108 opal_convertor_unpack( pConv, &a, &iov_count, &max_data );
109 a.iov_base = (char*)a.iov_base - 1024;
110 free(a.iov_base);
111 }
112
113 for (j = 0; j < N; ++j) {
114 if (bar[j].i[0] != pbar[j].i[0] ||
115 bar[j].i[1] != 0 ||
116 bar[j].i[2] != pbar[j].i[1] ||
117 bar[j].d[0] != pbar[j].d[0] ||
118 bar[j].d[1] != 0.0 ||
119 bar[j].d[2] != pbar[j].d[1]) {
120 if(0 == errors) {
121 fprintf(stderr, "ERROR ! count=%d, position=%d, ptr = %p"
122 " got (%d,%d,%d,%g,%g,%g) expected (%d,%d,%d,%g,%g,%g)\n",
123 N, j, (void*)&bar[j],
124 bar[j].i[0],
125 bar[j].i[1],
126 bar[j].i[2],
127 bar[j].d[0],
128 bar[j].d[1],
129 bar[j].d[2],
130 pbar[j].i[0],
131 0,
132 pbar[j].i[1],
133 pbar[j].d[0],
134 0.0,
135 pbar[j].d[1]);
136 print_bar_pbar(&bar[j], &pbar[j]);
137 }
138 errors++;
139 }
140 }
141 OBJ_RELEASE( pConv );
142 return errors;
143 }
144
145 static int unpack_ooo(void)
146 {
147 ompi_datatype_t * t1;
148 ompi_datatype_t * t2;
149 ompi_datatype_t * type[2];
150 ompi_datatype_t * newtype;
151 MPI_Aint disp[2];
152 int len[2], rc;
153
154 rc = ompi_datatype_create_vector(2, 1, 2, MPI_INT, &t1);
155 if (OMPI_SUCCESS != rc) {
156 fprintf(stderr, "could not create vector t1\n");
157 return 1;
158 }
159 rc = ompi_datatype_commit (&t1);
160 if (OMPI_SUCCESS != rc) {
161 fprintf(stderr, "could not commit vector t1\n");
162 return 1;
163 }
164
165 rc = ompi_datatype_create_vector(2, 1, 2, MPI_DOUBLE, &t2);
166 if (OMPI_SUCCESS != rc) {
167 fprintf(stderr, "could not create vector t2\n");
168 return 1;
169 }
170 rc = ompi_datatype_commit (&t2);
171 if (OMPI_SUCCESS != rc) {
172 fprintf(stderr, "could not commit vector t2\n");
173 return 1;
174 }
175
176
177
178
179
180
181
182
183
184
185
186 size_t test1[9][2] = {
187 {992, 0},
188 {1325, 992},
189 {992, 2317},
190 {992, 3309},
191 {992, 4301},
192 {992, 5293},
193 {992, 6285},
194 {667, 7277},
195 {0, -1},
196 };
197
198
199
200
201
202
203
204
205
206
207
208 size_t test2[9][2] = {
209 {992, 0},
210 {992, 2317},
211 {992, 3309},
212 {992, 4301},
213 {992, 5293},
214 {992, 6285},
215 {1325, 992},
216 {667, 7277},
217 {0, -1},
218 };
219
220
221 size_t test3[9][2] = {
222 {992, 0},
223 {4960, 2317},
224 {1325, 992},
225 {667, 7277},
226 {0, -1},
227 };
228
229
230 size_t test4[9][2] = {
231 {992, 0},
232 {992, 2976},
233 {992, 1984},
234 {992, 992},
235 {3976, 3968},
236 {0, -1},
237 };
238
239 disp[0] = (long)(&foo.i[0]) - (long)&foo;
240 disp[1] = (long)(&foo.d[0]) - (long)&foo;
241
242 type[0] = t1;
243 type[1] = t2;
244
245 len[0] = 1;
246 len[1] = 1;
247
248 rc = ompi_datatype_create_struct(2, len, disp, type, &newtype);
249 if (OMPI_SUCCESS != rc) {
250 fprintf(stderr, "could not create struct\n");
251 return 1;
252 }
253 rc = ompi_datatype_commit (&newtype);
254 if (OMPI_SUCCESS != rc) {
255 fprintf(stderr, "could not create struct\n");
256 return 1;
257 }
258
259 pbar = (struct pfoo_t *)malloc (N * sizeof(struct pfoo_t));
260 if (NULL == pbar) {
261 fprintf(stderr, "could not malloc pbar\n");
262 return 1;
263 }
264 bar = (struct foo_t *)malloc (N * sizeof(struct foo_t));
265 if (NULL == bar) {
266 fprintf(stderr, "could not malloc bar\n");
267 return 1;
268 }
269
270 if (0 != testcase(newtype, test1)) {
271 printf ("test1 failed\n");
272 return 2;
273 }
274
275 if (0 != testcase(newtype, test2)) {
276 printf ("test2 failed\n");
277 return 2;
278 }
279
280 if (0 != testcase(newtype, test3)) {
281 printf ("test3 failed\n");
282 return 2;
283 }
284
285 if (0 != testcase(newtype, test4)) {
286 printf ("test4 failed\n");
287 return 2;
288 }
289
290
291
292 ompi_datatype_destroy( &newtype ); assert( newtype == NULL );
293
294 return rc;
295 }
296
297 int main( int argc, char* argv[] )
298 {
299 int rc;
300
301 opal_init_util(&argc, &argv);
302 ompi_datatype_init();
303
304
305
306 remote_arch = opal_local_arch;
307
308 printf( "\n\n#\n * TEST UNPACK OUT OF ORDER\n #\n\n" );
309 rc = unpack_ooo();
310 if( rc == 0 ) {
311 printf( "unpack out of order [PASSED]\n" );
312 return 0;
313 }
314 printf( "unpack out of order [NOT PASSED]\n" );
315 return -1;
316 }