This source file includes following definitions.
- cache_trash
- create_inversed_vector
- print_double_mat
- init_random_upper_matrix
- check_diag_matrix
- upper_matrix
- lower_matrix
- test_matrix_borders
- test_contiguous
- test_struct_char_double
- test_create_twice_two_doubles
- test_create_blacs_type
- test_create_blacs_type1
- test_create_blacs_type2
- test_struct
- create_struct_constant_gap_resized_ddt
- create_strange_dt
- create_contiguous_type
- create_vector_type
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 #include "ompi_config.h"
25 #include "ddt_lib.h"
26 #include "ompi/constants.h"
27 #include <time.h>
28 #include <stdlib.h>
29 #ifdef HAVE_SYS_TIME_H
30 #include <sys/time.h>
31 #endif
32 #include <stdio.h>
33 #include <string.h>
34
35 #define TIMER_DATA_TYPE struct timeval
36 #define GET_TIME(TV) gettimeofday( &(TV), NULL )
37 #define ELAPSED_TIME(TSTART, TEND) (((TEND).tv_sec - (TSTART).tv_sec) * 1000000 + ((TEND).tv_usec - (TSTART).tv_usec))
38
39 #define DUMP_DATA_AFTER_COMMIT 0x00000001
40 #define CHECK_PACK_UNPACK 0x00000002
41 #define VALIDATE_DATA 0x00000004
42 uint32_t outputFlags = CHECK_PACK_UNPACK | VALIDATE_DATA;
43
44
45
46
47 #define CACHE_SIZE (4*1024*1024)
48 void cache_trash( void )
49 {
50 char* buffer;
51
52 buffer = (char*)malloc( sizeof(char) * CACHE_SIZE );
53 memset( buffer, 1, CACHE_SIZE );
54 memset( buffer, 0xff, CACHE_SIZE );
55 free( buffer );
56 }
57
58
59
60
61 ompi_datatype_t* create_inversed_vector( const ompi_datatype_t* type, int length )
62 {
63 ompi_datatype_t* type1;
64
65 ompi_datatype_create_vector( length, 1, 2, type, &type1 );
66
67 ompi_datatype_commit( &type1 );
68 return type1;
69 }
70
71 void print_double_mat( unsigned int N, double* mat )
72 {
73 unsigned int i, j;
74 double* pMat;
75
76 for( i = 0; i < N; i++ ) {
77 printf( "(%4d) :", i * N * (int)sizeof(double) );
78 pMat = mat + i * N;
79 for( j = 0; j < N; j++ ) {
80 printf( "%5.1f ", *pMat );
81 pMat++;
82 }
83 printf( "\n" );
84 }
85 }
86
87 int init_random_upper_matrix( unsigned int N, double* mat )
88 {
89 unsigned int i, j;
90
91 srand( time(NULL) );
92 for( i = 0; i < N; i++ ) {
93 mat += i;
94 for( j = i; j < N; j++ ) {
95 *mat = (double)random();
96 mat++;
97 }
98 }
99 return OMPI_SUCCESS;
100 }
101
102 int check_diag_matrix( unsigned int N, double* mat1, double* mat2 )
103 {
104 unsigned int i, j;
105
106 for( i = 0; i < N; i++ ) {
107 mat1 += i;
108 mat2 += i;
109 for( j = i; j < N; j++ ) {
110 if( *mat1 != *mat2 ) {
111 printf( "error in position (%d, %d) expect %f and find %f\n",
112 i, j, *mat1, *mat2 );
113 printf( "hex %lx != %lx\n", *(long*)mat1, *(long*)mat2 );
114 return OMPI_ERROR;
115 }
116 mat1++; mat2++;
117 }
118 }
119 return OMPI_SUCCESS;
120 }
121
122 ompi_datatype_t* upper_matrix( unsigned int mat_size )
123 {
124 int *disp, *blocklen;
125 unsigned int i;
126 ompi_datatype_t* upper;
127
128 disp = (int*)malloc( sizeof(int) * mat_size );
129 blocklen = (int*)malloc( sizeof(int) * mat_size );
130
131 for( i = 0; i < mat_size; i++ ) {
132 disp[i] = i * mat_size + i;
133 blocklen[i] = mat_size - i;
134 }
135
136 ompi_datatype_create_indexed( mat_size, blocklen, disp, &ompi_mpi_double.dt,
137 &upper );
138 ompi_datatype_commit( &upper );
139 if( outputFlags & DUMP_DATA_AFTER_COMMIT ) {
140 ompi_datatype_dump( upper );
141 }
142 free( disp );
143 free( blocklen );
144 return upper;
145 }
146
147 ompi_datatype_t* lower_matrix( unsigned int mat_size )
148 {
149 int *disp, *blocklen;
150 unsigned int i;
151 ompi_datatype_t* upper;
152
153 disp = (int*)malloc( sizeof(int) * mat_size );
154 blocklen = (int*)malloc( sizeof(int) * mat_size );
155
156 for( i = 0; i < mat_size; i++ ) {
157 disp[i] = i * mat_size;
158 blocklen[i] = i;
159 }
160
161 ompi_datatype_create_indexed( mat_size, blocklen, disp, &ompi_mpi_double.dt,
162 &upper );
163 free( disp );
164 free( blocklen );
165 return upper;
166 }
167
168 ompi_datatype_t* test_matrix_borders( unsigned int size, unsigned int width )
169 {
170 ompi_datatype_t *pdt, *pdt_line;
171 int disp[2];
172 int blocklen[2];
173
174 disp[0] = 0;
175 blocklen[0] = width;
176 disp[1] = (size - width) * sizeof(double);
177 blocklen[1] = width;
178
179 ompi_datatype_create_indexed( 2, blocklen, disp, &ompi_mpi_double.dt,
180 &pdt_line );
181 ompi_datatype_create_contiguous( size, pdt_line, &pdt );
182 OBJ_RELEASE( pdt_line );
183 return pdt;
184 }
185
186 ompi_datatype_t* test_contiguous( void )
187 {
188 ompi_datatype_t *pdt, *pdt1, *pdt2;
189
190 printf( "test contiguous (alignment)\n" );
191 ompi_datatype_create_contiguous(0, &ompi_mpi_datatype_null.dt, &pdt1);
192 ompi_datatype_add( pdt1, &ompi_mpi_double.dt, 1, 0, -1 );
193 if( outputFlags & DUMP_DATA_AFTER_COMMIT ) {
194 ompi_datatype_dump( pdt1 );
195 }
196 ompi_datatype_add( pdt1, &ompi_mpi_char.dt, 1, 8, -1 );
197 if( outputFlags & DUMP_DATA_AFTER_COMMIT ) {
198 ompi_datatype_dump( pdt1 );
199 }
200 ompi_datatype_create_contiguous( 4, pdt1, &pdt2 );
201 OBJ_RELEASE( pdt1 );
202 if( outputFlags & DUMP_DATA_AFTER_COMMIT ) {
203 ompi_datatype_dump( pdt2 );
204 }
205 ompi_datatype_create_contiguous( 2, pdt2, &pdt );
206 OBJ_RELEASE( pdt2 );
207 if( outputFlags & DUMP_DATA_AFTER_COMMIT ) {
208 ompi_datatype_dump( pdt );
209 }
210 return pdt;
211 }
212
213 typedef struct __struct_char_double {
214 char c;
215 double d;
216 } char_double_t;
217
218 ompi_datatype_t* test_struct_char_double( void )
219 {
220 char_double_t data;
221 int lengths[] = {1, 1};
222 MPI_Aint displ[] = {0, 0};
223 ompi_datatype_t *pdt;
224 ompi_datatype_t* types[] = { &ompi_mpi_char.dt, &ompi_mpi_double.dt};
225
226 displ[0] = (char*)&(data.c) - (char*)&(data);
227 displ[1] = (char*)&(data.d) - (char*)&(data);
228
229 ompi_datatype_create_struct( 2, lengths, displ, types, &pdt );
230 ompi_datatype_commit( &pdt );
231 if( outputFlags & DUMP_DATA_AFTER_COMMIT ) {
232 ompi_datatype_dump( pdt );
233 }
234 return pdt;
235 }
236
237 ompi_datatype_t* test_create_twice_two_doubles( void )
238 {
239 ompi_datatype_t* pdt;
240
241 ompi_datatype_create_vector( 2, 2, 5, &ompi_mpi_double.dt, &pdt );
242 ompi_datatype_commit( &pdt );
243 if( outputFlags & DUMP_DATA_AFTER_COMMIT ) {
244 ompi_datatype_dump( pdt );
245 }
246 return pdt;
247 }
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273 static int blacs_length[] = { 13, 13, 13, 13, 13, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 };
274 static int blacs_indices[] = { 1144/4, 1232/4, 1320/4, 1408/4, 1496/4, 1584/4, 1676/4, 1768/4,
275 1860/4, 1952/4, 2044/4, 2136/4, 2228/4, 2320/4, 2412/4, 2504/4,
276 2596/4, 2688/4 };
277 ompi_datatype_t* test_create_blacs_type( void )
278 {
279 ompi_datatype_t *pdt;
280
281 ompi_datatype_create_indexed( 18, blacs_length, blacs_indices, &ompi_mpi_int.dt, &pdt );
282 ompi_datatype_commit( &pdt );
283 if( outputFlags & DUMP_DATA_AFTER_COMMIT ) {
284 ompi_datatype_dump( pdt );
285 }
286 return pdt;
287 }
288
289 ompi_datatype_t* test_create_blacs_type1( const ompi_datatype_t* base_type )
290 {
291 ompi_datatype_t *pdt;
292
293 ompi_datatype_create_vector( 7, 1, 3, base_type, &pdt );
294 ompi_datatype_commit( &pdt );
295 if( outputFlags & DUMP_DATA_AFTER_COMMIT ) {
296 ompi_datatype_dump( pdt );
297 }
298 return pdt;
299 }
300
301 ompi_datatype_t* test_create_blacs_type2( const ompi_datatype_t* base_type )
302 {
303 ompi_datatype_t *pdt;
304
305 ompi_datatype_create_vector( 7, 1, 2, base_type, &pdt );
306 ompi_datatype_commit( &pdt );
307 if( outputFlags & DUMP_DATA_AFTER_COMMIT ) {
308 ompi_datatype_dump( pdt );
309 }
310 return pdt;
311 }
312
313 ompi_datatype_t* test_struct( void )
314 {
315 ompi_datatype_t* types[] = { &ompi_mpi_float.dt ,
316 NULL,
317 &ompi_mpi_char.dt };
318 int lengths[] = { 2, 1, 3 };
319 MPI_Aint disp[] = { 0, 16, 26 };
320 ompi_datatype_t* pdt, *pdt1;
321
322 printf( "test struct\n" );
323 ompi_datatype_create_contiguous(0, &ompi_mpi_datatype_null.dt, &pdt1);
324 ompi_datatype_add( pdt1, &ompi_mpi_double.dt, 1, 0, -1 );
325 ompi_datatype_add( pdt1, &ompi_mpi_char.dt, 1, 8, -1 );
326 if( outputFlags & DUMP_DATA_AFTER_COMMIT ) {
327 ompi_datatype_dump( pdt1 );
328 }
329
330 types[1] = pdt1;
331
332 ompi_datatype_create_struct( 3, lengths, disp, types, &pdt );
333 OBJ_RELEASE( pdt1 );
334 if( outputFlags & DUMP_DATA_AFTER_COMMIT ) {
335 ompi_datatype_dump( pdt );
336 }
337 return pdt;
338 }
339
340
341 struct structure {
342 double not_transfered;
343 double transfered_1;
344 double transfered_2;
345 };
346
347 ompi_datatype_t* create_struct_constant_gap_resized_ddt( ompi_datatype_t* type )
348 {
349 struct structure data[1];
350 ompi_datatype_t *struct_type, *temp_type;
351 ompi_datatype_t *types[2] = {type, type};
352 int blocklens[2] = {1, 1};
353 MPI_Aint disps[3];
354
355 MPI_Get_address(&data[0].transfered_1, &disps[0]);
356 MPI_Get_address(&data[0].transfered_2, &disps[1]);
357 MPI_Get_address(&data[0], &disps[2]);
358 disps[1] -= disps[2];
359 disps[0] -= disps[2];
360
361 ompi_datatype_create_struct(2, blocklens, disps, types, &temp_type);
362 ompi_datatype_create_resized(temp_type, 0, sizeof(data[0]), &struct_type);
363 ompi_datatype_commit(&struct_type);
364 OBJ_RELEASE(temp_type); assert( temp_type == NULL );
365 if( outputFlags & DUMP_DATA_AFTER_COMMIT ) {
366 ompi_datatype_dump( struct_type );
367 }
368
369 return struct_type;
370 }
371
372 typedef struct {
373 int i1;
374 int gap;
375 int i2;
376 } sdata_intern;
377
378 typedef struct {
379 int counter;
380 sdata_intern v[10];
381 int last;
382 } sstrange;
383
384 #define SSTRANGE_CNT 10
385 #define USE_RESIZED
386
387 ompi_datatype_t* create_strange_dt( void )
388 {
389 sdata_intern v[2];
390 MPI_Aint displ[3];
391 ompi_datatype_t* types[3] = { &ompi_mpi_int.dt };
392 sstrange t[2];
393 int pBlock[3] = {1, 10, 1}, dispi[3];
394 ompi_datatype_t *pdt, *pdt1, *pdt2, *pdtTemp;
395
396 dispi[0] = (int)((char*)&(v[0].i1) - (char*)&(v[0]));
397 dispi[1] = (int)(((char*)(&(v[0].i2)) - (char*)&(v[0])) / sizeof(int));
398 ompi_datatype_create_indexed_block( 2, 1, dispi, &ompi_mpi_int.dt, &pdtTemp );
399 #ifdef USE_RESIZED
400
401 displ[0] = 0;
402 displ[1] = (char*)&(v[1]) - (char*)&(v[0]);
403 ompi_datatype_create_resized( pdtTemp, displ[0], displ[1], &pdt1 );
404 OBJ_RELEASE( pdtTemp ); assert( pdtTemp == NULL );
405 #else
406 pdt1 = pdtTemp;
407 #endif
408
409 types[1] = pdt1;
410 types[2] = &ompi_mpi_int.dt;
411 displ[0] = 0;
412 displ[1] = (long)((char*)&(t[0].v[0]) - (char*)&(t[0]));
413 displ[2] = (long)((char*)&(t[0].last) - (char*)&(t[0]));
414 ompi_datatype_create_struct( 3, pBlock, displ, types, &pdtTemp );
415 #ifdef USE_RESIZED
416
417 displ[1] = (char*)&(t[1]) - (char*)&(t[0]);
418 ompi_datatype_create_resized( pdtTemp, displ[0], displ[1], &pdt2 );
419 OBJ_RELEASE( pdtTemp ); assert( pdtTemp == NULL );
420 #else
421 pdt2 = pdtTemp;
422 #endif
423
424 ompi_datatype_create_contiguous( SSTRANGE_CNT, pdt2, &pdt );
425
426 OBJ_RELEASE( pdt1 );
427 OBJ_RELEASE( pdt2 );
428 printf( "\nStrange datatype BEFORE COMMIT\n" );
429 if( outputFlags & DUMP_DATA_AFTER_COMMIT ) {
430 ompi_datatype_dump( pdt );
431 }
432 ompi_datatype_commit( &pdt );
433 printf( "\nStrange datatype AFTER COMMIT\n" );
434 if( outputFlags & DUMP_DATA_AFTER_COMMIT ) {
435 ompi_datatype_dump( pdt );
436 }
437 return pdt;
438 }
439
440 ompi_datatype_t* create_contiguous_type( const ompi_datatype_t* data, int count )
441 {
442 ompi_datatype_t* contiguous;
443
444 ompi_datatype_create_contiguous( count, data, &contiguous );
445 ompi_datatype_commit( &contiguous );
446 return contiguous;
447 }
448
449 ompi_datatype_t* create_vector_type( const ompi_datatype_t* data, int count, int length, int stride )
450 {
451 ompi_datatype_t* vector;
452
453 ompi_datatype_create_vector( count, length, stride, data, &vector );
454 ompi_datatype_commit( &vector );
455 return vector;
456 }
457