Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
first commit to add the mpich-test suite to smpi tesh suite. Obviously all tests...
[simgrid.git] / teshsuite / smpi / mpich-test / coll / allred.c
1
2 #include <math.h>
3 #include "mpi.h"
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include "test.h"
7 #include "../pt2pt/gcomm.h"
8
9 int verbose = 1;
10 int main( int argc, char **argv )
11 {
12 int count, errcnt = 0, gerr = 0, toterr, size, rank;
13 MPI_Comm comm;
14
15 MPI_Comm comms[10];
16 int      ncomm, ii, world_rank;
17
18 MPI_Init( &argc, &argv );
19 MPI_Comm_rank( MPI_COMM_WORLD, &world_rank );
20
21 /* First tests */
22 MakeComms( comms, 10, &ncomm, 0 );
23 for (ii=0; ii<ncomm; ii++) {
24 if (world_rank == 0 && verbose) printf( "Testing with communicator %d\n", ii );
25 comm = comms[ii];
26
27
28 MPI_Comm_size( comm, &size );
29 MPI_Comm_rank( comm, &rank );
30 count = 10;
31
32 /* Test sum */
33 if (world_rank == 0 && verbose) printf( "Testing MPI_SUM...\n" );
34
35
36
37 {
38 int *in, *out, *sol;
39 int  i, fnderr=0;
40 in = (int *)malloc( count * sizeof(int) );
41 out = (int *)malloc( count * sizeof(int) );
42 sol = (int *)malloc( count * sizeof(int) );
43 for (i=0; i<count; i++) { *(in + i) = i; *(sol + i) = i*size; 
44         *(out + i) = 0; }
45 MPI_Allreduce( in, out, count, MPI_INT, MPI_SUM, comm );
46 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
47 if (fnderr) fprintf( stderr, 
48         "(%d) Error for type MPI_INT and op MPI_SUM\n", world_rank );
49 free( in );
50 free( out );
51 free( sol );
52 }
53
54
55 {
56 long *in, *out, *sol;
57 int  i, fnderr=0;
58 in = (long *)malloc( count * sizeof(long) );
59 out = (long *)malloc( count * sizeof(long) );
60 sol = (long *)malloc( count * sizeof(long) );
61 for (i=0; i<count; i++) { *(in + i) = i; *(sol + i) = i*size; 
62         *(out + i) = 0; }
63 MPI_Allreduce( in, out, count, MPI_LONG, MPI_SUM, comm );
64 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
65 if (fnderr) fprintf( stderr, 
66         "(%d) Error for type MPI_LONG and op MPI_SUM\n", world_rank );
67 free( in );
68 free( out );
69 free( sol );
70 }
71
72
73 {
74 short *in, *out, *sol;
75 int  i, fnderr=0;
76 in = (short *)malloc( count * sizeof(short) );
77 out = (short *)malloc( count * sizeof(short) );
78 sol = (short *)malloc( count * sizeof(short) );
79 for (i=0; i<count; i++) { *(in + i) = i; *(sol + i) = i*size; 
80         *(out + i) = 0; }
81 MPI_Allreduce( in, out, count, MPI_SHORT, MPI_SUM, comm );
82 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
83 if (fnderr) fprintf( stderr, 
84         "(%d) Error for type MPI_SHORT and op MPI_SUM\n", world_rank );
85 free( in );
86 free( out );
87 free( sol );
88 }
89
90
91 {
92 unsigned short *in, *out, *sol;
93 int  i, fnderr=0;
94 in = (unsigned short *)malloc( count * sizeof(unsigned short) );
95 out = (unsigned short *)malloc( count * sizeof(unsigned short) );
96 sol = (unsigned short *)malloc( count * sizeof(unsigned short) );
97 for (i=0; i<count; i++) { *(in + i) = i; *(sol + i) = i*size; 
98         *(out + i) = 0; }
99 MPI_Allreduce( in, out, count, MPI_UNSIGNED_SHORT, MPI_SUM, comm );
100 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
101 if (fnderr) fprintf( stderr, 
102         "(%d) Error for type MPI_UNSIGNED_SHORT and op MPI_SUM\n", world_rank );
103 free( in );
104 free( out );
105 free( sol );
106 }
107
108
109 {
110 unsigned *in, *out, *sol;
111 int  i, fnderr=0;
112 in = (unsigned *)malloc( count * sizeof(unsigned) );
113 out = (unsigned *)malloc( count * sizeof(unsigned) );
114 sol = (unsigned *)malloc( count * sizeof(unsigned) );
115 for (i=0; i<count; i++) { *(in + i) = i; *(sol + i) = i*size; 
116         *(out + i) = 0; }
117 MPI_Allreduce( in, out, count, MPI_UNSIGNED, MPI_SUM, comm );
118 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
119 if (fnderr) fprintf( stderr, 
120         "(%d) Error for type MPI_UNSIGNED and op MPI_SUM\n", world_rank );
121 free( in );
122 free( out );
123 free( sol );
124 }
125
126
127 {
128 unsigned long *in, *out, *sol;
129 int  i, fnderr=0;
130 in = (unsigned long *)malloc( count * sizeof(unsigned long) );
131 out = (unsigned long *)malloc( count * sizeof(unsigned long) );
132 sol = (unsigned long *)malloc( count * sizeof(unsigned long) );
133 for (i=0; i<count; i++) { *(in + i) = i; *(sol + i) = i*size; 
134         *(out + i) = 0; }
135 MPI_Allreduce( in, out, count, MPI_UNSIGNED_LONG, MPI_SUM, comm );
136 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
137 if (fnderr) fprintf( stderr, 
138         "(%d) Error for type MPI_UNSIGNED_LONG and op MPI_SUM\n", world_rank );
139 free( in );
140 free( out );
141 free( sol );
142 }
143
144
145 {
146 float *in, *out, *sol;
147 int  i, fnderr=0;
148 in = (float *)malloc( count * sizeof(float) );
149 out = (float *)malloc( count * sizeof(float) );
150 sol = (float *)malloc( count * sizeof(float) );
151 for (i=0; i<count; i++) { *(in + i) = i; *(sol + i) = i*size; 
152         *(out + i) = 0; }
153 MPI_Allreduce( in, out, count, MPI_FLOAT, MPI_SUM, comm );
154 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
155 if (fnderr) fprintf( stderr, 
156         "(%d) Error for type MPI_FLOAT and op MPI_SUM\n", world_rank );
157 free( in );
158 free( out );
159 free( sol );
160 }
161
162
163 {
164 double *in, *out, *sol;
165 int  i, fnderr=0;
166 in = (double *)malloc( count * sizeof(double) );
167 out = (double *)malloc( count * sizeof(double) );
168 sol = (double *)malloc( count * sizeof(double) );
169 for (i=0; i<count; i++) { *(in + i) = i; *(sol + i) = i*size; 
170         *(out + i) = 0; }
171 MPI_Allreduce( in, out, count, MPI_DOUBLE, MPI_SUM, comm );
172 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
173 if (fnderr) fprintf( stderr, 
174         "(%d) Error for type MPI_DOUBLE and op MPI_SUM\n", world_rank );
175 free( in );
176 free( out );
177 free( sol );
178 }
179
180
181 gerr += errcnt;
182 if (errcnt > 0)
183         printf( "Found %d errors on %d for MPI_SUM\n", errcnt, rank );
184 errcnt = 0;
185
186 /* Test product */
187 if (world_rank == 0 && verbose) printf( "Testing MPI_PROD...\n" );
188
189 {
190 int *in, *out, *sol;
191 int  i, fnderr=0;
192 in = (int *)malloc( count * sizeof(int) );
193 out = (int *)malloc( count * sizeof(int) );
194 sol = (int *)malloc( count * sizeof(int) );
195 for (i=0; i<count; i++) { *(in + i) = i; *(sol + i) = (i > 0) ? (int)(pow((double)(i),(double)size)+0.1) : 0; 
196         *(out + i) = 0; }
197 MPI_Allreduce( in, out, count, MPI_INT, MPI_PROD, comm );
198 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
199 if (fnderr) fprintf( stderr, 
200         "(%d) Error for type MPI_INT and op MPI_PROD\n", world_rank );
201 free( in );
202 free( out );
203 free( sol );
204 }
205
206
207 {
208 long *in, *out, *sol;
209 int  i, fnderr=0;
210 in = (long *)malloc( count * sizeof(long) );
211 out = (long *)malloc( count * sizeof(long) );
212 sol = (long *)malloc( count * sizeof(long) );
213 for (i=0; i<count; i++) { *(in + i) = i; *(sol + i) = (i > 0) ? (int)(pow((double)(i),(double)size)+0.1) : 0; 
214         *(out + i) = 0; }
215 MPI_Allreduce( in, out, count, MPI_LONG, MPI_PROD, comm );
216 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
217 if (fnderr) fprintf( stderr, 
218         "(%d) Error for type MPI_LONG and op MPI_PROD\n", world_rank );
219 free( in );
220 free( out );
221 free( sol );
222 }
223
224
225 {
226 short *in, *out, *sol;
227 int  i, fnderr=0;
228 in = (short *)malloc( count * sizeof(short) );
229 out = (short *)malloc( count * sizeof(short) );
230 sol = (short *)malloc( count * sizeof(short) );
231 for (i=0; i<count; i++) { *(in + i) = i; *(sol + i) = (i > 0) ? (int)(pow((double)(i),(double)size)+0.1) : 0; 
232         *(out + i) = 0; }
233 MPI_Allreduce( in, out, count, MPI_SHORT, MPI_PROD, comm );
234 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
235 if (fnderr) fprintf( stderr, 
236         "(%d) Error for type MPI_SHORT and op MPI_PROD\n", world_rank );
237 free( in );
238 free( out );
239 free( sol );
240 }
241
242
243 {
244 unsigned short *in, *out, *sol;
245 int  i, fnderr=0;
246 in = (unsigned short *)malloc( count * sizeof(unsigned short) );
247 out = (unsigned short *)malloc( count * sizeof(unsigned short) );
248 sol = (unsigned short *)malloc( count * sizeof(unsigned short) );
249 for (i=0; i<count; i++) { *(in + i) = i; *(sol + i) = (i > 0) ? (int)(pow((double)(i),(double)size)+0.1) : 0; 
250         *(out + i) = 0; }
251 MPI_Allreduce( in, out, count, MPI_UNSIGNED_SHORT, MPI_PROD, comm );
252 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
253 if (fnderr) fprintf( stderr, 
254         "(%d) Error for type MPI_UNSIGNED_SHORT and op MPI_PROD\n", world_rank );
255 free( in );
256 free( out );
257 free( sol );
258 }
259
260
261 {
262 unsigned *in, *out, *sol;
263 int  i, fnderr=0;
264 in = (unsigned *)malloc( count * sizeof(unsigned) );
265 out = (unsigned *)malloc( count * sizeof(unsigned) );
266 sol = (unsigned *)malloc( count * sizeof(unsigned) );
267 for (i=0; i<count; i++) { *(in + i) = i; *(sol + i) = (i > 0) ? (int)(pow((double)(i),(double)size)+0.1) : 0; 
268         *(out + i) = 0; }
269 MPI_Allreduce( in, out, count, MPI_UNSIGNED, MPI_PROD, comm );
270 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
271 if (fnderr) fprintf( stderr, 
272         "(%d) Error for type MPI_UNSIGNED and op MPI_PROD\n", world_rank );
273 free( in );
274 free( out );
275 free( sol );
276 }
277
278
279 {
280 unsigned long *in, *out, *sol;
281 int  i, fnderr=0;
282 in = (unsigned long *)malloc( count * sizeof(unsigned long) );
283 out = (unsigned long *)malloc( count * sizeof(unsigned long) );
284 sol = (unsigned long *)malloc( count * sizeof(unsigned long) );
285 for (i=0; i<count; i++) { *(in + i) = i; *(sol + i) = (i > 0) ? (int)(pow((double)(i),(double)size)+0.1) : 0; 
286         *(out + i) = 0; }
287 MPI_Allreduce( in, out, count, MPI_UNSIGNED_LONG, MPI_PROD, comm );
288 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
289 if (fnderr) fprintf( stderr, 
290         "(%d) Error for type MPI_UNSIGNED_LONG and op MPI_PROD\n", world_rank );
291 free( in );
292 free( out );
293 free( sol );
294 }
295
296
297 {
298 float *in, *out, *sol;
299 int  i, fnderr=0;
300 in = (float *)malloc( count * sizeof(float) );
301 out = (float *)malloc( count * sizeof(float) );
302 sol = (float *)malloc( count * sizeof(float) );
303 for (i=0; i<count; i++) { *(in + i) = i; *(sol + i) = (i > 0) ? (int)(pow((double)(i),(double)size)+0.1) : 0; 
304         *(out + i) = 0; }
305 MPI_Allreduce( in, out, count, MPI_FLOAT, MPI_PROD, comm );
306 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
307 if (fnderr) fprintf( stderr, 
308         "(%d) Error for type MPI_FLOAT and op MPI_PROD\n", world_rank );
309 free( in );
310 free( out );
311 free( sol );
312 }
313
314
315 {
316 double *in, *out, *sol;
317 int  i, fnderr=0;
318 in = (double *)malloc( count * sizeof(double) );
319 out = (double *)malloc( count * sizeof(double) );
320 sol = (double *)malloc( count * sizeof(double) );
321 for (i=0; i<count; i++) { *(in + i) = i; *(sol + i) = (i > 0) ? (int)(pow((double)(i),(double)size)+0.1) : 0; 
322         *(out + i) = 0; }
323 MPI_Allreduce( in, out, count, MPI_DOUBLE, MPI_PROD, comm );
324 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
325 if (fnderr) fprintf( stderr, 
326         "(%d) Error for type MPI_DOUBLE and op MPI_PROD\n", world_rank );
327 free( in );
328 free( out );
329 free( sol );
330 }
331
332
333 gerr += errcnt;
334 if (errcnt > 0)
335         printf( "Found %d errors on %d for MPI_PROD\n", errcnt, rank );
336 errcnt = 0;
337
338 /* Test max */
339 if (world_rank == 0 && verbose) printf( "Testing MPI_MAX...\n" );
340
341 {
342 int *in, *out, *sol;
343 int  i, fnderr=0;
344 in = (int *)malloc( count * sizeof(int) );
345 out = (int *)malloc( count * sizeof(int) );
346 sol = (int *)malloc( count * sizeof(int) );
347 for (i=0; i<count; i++) { *(in + i) = (rank + i); *(sol + i) = (size - 1 + i); 
348         *(out + i) = 0; }
349 MPI_Allreduce( in, out, count, MPI_INT, MPI_MAX, comm );
350 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
351 if (fnderr) fprintf( stderr, 
352         "(%d) Error for type MPI_INT and op MPI_MAX\n", world_rank );
353 free( in );
354 free( out );
355 free( sol );
356 }
357
358
359 {
360 long *in, *out, *sol;
361 int  i, fnderr=0;
362 in = (long *)malloc( count * sizeof(long) );
363 out = (long *)malloc( count * sizeof(long) );
364 sol = (long *)malloc( count * sizeof(long) );
365 for (i=0; i<count; i++) { *(in + i) = (rank + i); *(sol + i) = (size - 1 + i); 
366         *(out + i) = 0; }
367 MPI_Allreduce( in, out, count, MPI_LONG, MPI_MAX, comm );
368 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
369 if (fnderr) fprintf( stderr, 
370         "(%d) Error for type MPI_LONG and op MPI_MAX\n", world_rank );
371 free( in );
372 free( out );
373 free( sol );
374 }
375
376
377 {
378 short *in, *out, *sol;
379 int  i, fnderr=0;
380 in = (short *)malloc( count * sizeof(short) );
381 out = (short *)malloc( count * sizeof(short) );
382 sol = (short *)malloc( count * sizeof(short) );
383 for (i=0; i<count; i++) { *(in + i) = (rank + i); *(sol + i) = (size - 1 + i); 
384         *(out + i) = 0; }
385 MPI_Allreduce( in, out, count, MPI_SHORT, MPI_MAX, comm );
386 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
387 if (fnderr) fprintf( stderr, 
388         "(%d) Error for type MPI_SHORT and op MPI_MAX\n", world_rank );
389 free( in );
390 free( out );
391 free( sol );
392 }
393
394
395 {
396 unsigned short *in, *out, *sol;
397 int  i, fnderr=0;
398 in = (unsigned short *)malloc( count * sizeof(unsigned short) );
399 out = (unsigned short *)malloc( count * sizeof(unsigned short) );
400 sol = (unsigned short *)malloc( count * sizeof(unsigned short) );
401 for (i=0; i<count; i++) { *(in + i) = (rank + i); *(sol + i) = (size - 1 + i); 
402         *(out + i) = 0; }
403 MPI_Allreduce( in, out, count, MPI_UNSIGNED_SHORT, MPI_MAX, comm );
404 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
405 if (fnderr) fprintf( stderr, 
406         "(%d) Error for type MPI_UNSIGNED_SHORT and op MPI_MAX\n", world_rank );
407 free( in );
408 free( out );
409 free( sol );
410 }
411
412
413 {
414 unsigned *in, *out, *sol;
415 int  i, fnderr=0;
416 in = (unsigned *)malloc( count * sizeof(unsigned) );
417 out = (unsigned *)malloc( count * sizeof(unsigned) );
418 sol = (unsigned *)malloc( count * sizeof(unsigned) );
419 for (i=0; i<count; i++) { *(in + i) = (rank + i); *(sol + i) = (size - 1 + i); 
420         *(out + i) = 0; }
421 MPI_Allreduce( in, out, count, MPI_UNSIGNED, MPI_MAX, comm );
422 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
423 if (fnderr) fprintf( stderr, 
424         "(%d) Error for type MPI_UNSIGNED and op MPI_MAX\n", world_rank );
425 free( in );
426 free( out );
427 free( sol );
428 }
429
430
431 {
432 unsigned long *in, *out, *sol;
433 int  i, fnderr=0;
434 in = (unsigned long *)malloc( count * sizeof(unsigned long) );
435 out = (unsigned long *)malloc( count * sizeof(unsigned long) );
436 sol = (unsigned long *)malloc( count * sizeof(unsigned long) );
437 for (i=0; i<count; i++) { *(in + i) = (rank + i); *(sol + i) = (size - 1 + i); 
438         *(out + i) = 0; }
439 MPI_Allreduce( in, out, count, MPI_UNSIGNED_LONG, MPI_MAX, comm );
440 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
441 if (fnderr) fprintf( stderr, 
442         "(%d) Error for type MPI_UNSIGNED_LONG and op MPI_MAX\n", world_rank );
443 free( in );
444 free( out );
445 free( sol );
446 }
447
448
449 {
450 float *in, *out, *sol;
451 int  i, fnderr=0;
452 in = (float *)malloc( count * sizeof(float) );
453 out = (float *)malloc( count * sizeof(float) );
454 sol = (float *)malloc( count * sizeof(float) );
455 for (i=0; i<count; i++) { *(in + i) = (rank + i); *(sol + i) = (size - 1 + i); 
456         *(out + i) = 0; }
457 MPI_Allreduce( in, out, count, MPI_FLOAT, MPI_MAX, comm );
458 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
459 if (fnderr) fprintf( stderr, 
460         "(%d) Error for type MPI_FLOAT and op MPI_MAX\n", world_rank );
461 free( in );
462 free( out );
463 free( sol );
464 }
465
466
467 {
468 double *in, *out, *sol;
469 int  i, fnderr=0;
470 in = (double *)malloc( count * sizeof(double) );
471 out = (double *)malloc( count * sizeof(double) );
472 sol = (double *)malloc( count * sizeof(double) );
473 for (i=0; i<count; i++) { *(in + i) = (rank + i); *(sol + i) = (size - 1 + i); 
474         *(out + i) = 0; }
475 MPI_Allreduce( in, out, count, MPI_DOUBLE, MPI_MAX, comm );
476 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
477 if (fnderr) fprintf( stderr, 
478         "(%d) Error for type MPI_DOUBLE and op MPI_MAX\n", world_rank );
479 free( in );
480 free( out );
481 free( sol );
482 }
483
484
485 gerr += errcnt;
486 if (errcnt > 0)
487         printf( "Found %d errors on %d for MPI_MAX\n", errcnt, rank );
488 errcnt = 0;
489
490 /* Test min */
491 if (world_rank == 0 && verbose) printf( "Testing MPI_MIN...\n" );
492
493 {
494 int *in, *out, *sol;
495 int  i, fnderr=0;
496 in = (int *)malloc( count * sizeof(int) );
497 out = (int *)malloc( count * sizeof(int) );
498 sol = (int *)malloc( count * sizeof(int) );
499 for (i=0; i<count; i++) { *(in + i) = (rank + i); *(sol + i) = i; 
500         *(out + i) = 0; }
501 MPI_Allreduce( in, out, count, MPI_INT, MPI_MIN, comm );
502 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
503 if (fnderr) fprintf( stderr, 
504         "(%d) Error for type MPI_INT and op MPI_MIN\n", world_rank );
505 free( in );
506 free( out );
507 free( sol );
508 }
509
510
511 {
512 long *in, *out, *sol;
513 int  i, fnderr=0;
514 in = (long *)malloc( count * sizeof(long) );
515 out = (long *)malloc( count * sizeof(long) );
516 sol = (long *)malloc( count * sizeof(long) );
517 for (i=0; i<count; i++) { *(in + i) = (rank + i); *(sol + i) = i; 
518         *(out + i) = 0; }
519 MPI_Allreduce( in, out, count, MPI_LONG, MPI_MIN, comm );
520 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
521 if (fnderr) fprintf( stderr, 
522         "(%d) Error for type MPI_LONG and op MPI_MIN\n", world_rank );
523 free( in );
524 free( out );
525 free( sol );
526 }
527
528
529 {
530 short *in, *out, *sol;
531 int  i, fnderr=0;
532 in = (short *)malloc( count * sizeof(short) );
533 out = (short *)malloc( count * sizeof(short) );
534 sol = (short *)malloc( count * sizeof(short) );
535 for (i=0; i<count; i++) { *(in + i) = (rank + i); *(sol + i) = i; 
536         *(out + i) = 0; }
537 MPI_Allreduce( in, out, count, MPI_SHORT, MPI_MIN, comm );
538 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
539 if (fnderr) fprintf( stderr, 
540         "(%d) Error for type MPI_SHORT and op MPI_MIN\n", world_rank );
541 free( in );
542 free( out );
543 free( sol );
544 }
545
546
547 {
548 unsigned short *in, *out, *sol;
549 int  i, fnderr=0;
550 in = (unsigned short *)malloc( count * sizeof(unsigned short) );
551 out = (unsigned short *)malloc( count * sizeof(unsigned short) );
552 sol = (unsigned short *)malloc( count * sizeof(unsigned short) );
553 for (i=0; i<count; i++) { *(in + i) = (rank + i); *(sol + i) = i; 
554         *(out + i) = 0; }
555 MPI_Allreduce( in, out, count, MPI_UNSIGNED_SHORT, MPI_MIN, comm );
556 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
557 if (fnderr) fprintf( stderr, 
558         "(%d) Error for type MPI_UNSIGNED_SHORT and op MPI_MIN\n", world_rank );
559 free( in );
560 free( out );
561 free( sol );
562 }
563
564
565 {
566 unsigned *in, *out, *sol;
567 int  i, fnderr=0;
568 in = (unsigned *)malloc( count * sizeof(unsigned) );
569 out = (unsigned *)malloc( count * sizeof(unsigned) );
570 sol = (unsigned *)malloc( count * sizeof(unsigned) );
571 for (i=0; i<count; i++) { *(in + i) = (rank + i); *(sol + i) = i; 
572         *(out + i) = 0; }
573 MPI_Allreduce( in, out, count, MPI_UNSIGNED, MPI_MIN, comm );
574 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
575 if (fnderr) fprintf( stderr, 
576         "(%d) Error for type MPI_UNSIGNED and op MPI_MIN\n", world_rank );
577 free( in );
578 free( out );
579 free( sol );
580 }
581
582
583 {
584 unsigned long *in, *out, *sol;
585 int  i, fnderr=0;
586 in = (unsigned long *)malloc( count * sizeof(unsigned long) );
587 out = (unsigned long *)malloc( count * sizeof(unsigned long) );
588 sol = (unsigned long *)malloc( count * sizeof(unsigned long) );
589 for (i=0; i<count; i++) { *(in + i) = (rank + i); *(sol + i) = i; 
590         *(out + i) = 0; }
591 MPI_Allreduce( in, out, count, MPI_UNSIGNED_LONG, MPI_MIN, comm );
592 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
593 if (fnderr) fprintf( stderr, 
594         "(%d) Error for type MPI_UNSIGNED_LONG and op MPI_MIN\n", world_rank );
595 free( in );
596 free( out );
597 free( sol );
598 }
599
600
601 {
602 float *in, *out, *sol;
603 int  i, fnderr=0;
604 in = (float *)malloc( count * sizeof(float) );
605 out = (float *)malloc( count * sizeof(float) );
606 sol = (float *)malloc( count * sizeof(float) );
607 for (i=0; i<count; i++) { *(in + i) = (rank + i); *(sol + i) = i; 
608         *(out + i) = 0; }
609 MPI_Allreduce( in, out, count, MPI_FLOAT, MPI_MIN, comm );
610 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
611 if (fnderr) fprintf( stderr, 
612         "(%d) Error for type MPI_FLOAT and op MPI_MIN\n", world_rank );
613 free( in );
614 free( out );
615 free( sol );
616 }
617
618
619 {
620 double *in, *out, *sol;
621 int  i, fnderr=0;
622 in = (double *)malloc( count * sizeof(double) );
623 out = (double *)malloc( count * sizeof(double) );
624 sol = (double *)malloc( count * sizeof(double) );
625 for (i=0; i<count; i++) { *(in + i) = (rank + i); *(sol + i) = i; 
626         *(out + i) = 0; }
627 MPI_Allreduce( in, out, count, MPI_DOUBLE, MPI_MIN, comm );
628 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
629 if (fnderr) fprintf( stderr, 
630         "(%d) Error for type MPI_DOUBLE and op MPI_MIN\n", world_rank );
631 free( in );
632 free( out );
633 free( sol );
634 }
635
636
637 gerr += errcnt;
638 if (errcnt > 0)
639         printf( "Found %d errors on %d for MPI_MIN\n", errcnt, rank );
640 errcnt = 0;
641
642 /* Test LOR */
643 if (world_rank == 0 && verbose) printf( "Testing MPI_LOR...\n" );
644
645 {
646 int *in, *out, *sol;
647 int  i, fnderr=0;
648 in = (int *)malloc( count * sizeof(int) );
649 out = (int *)malloc( count * sizeof(int) );
650 sol = (int *)malloc( count * sizeof(int) );
651 for (i=0; i<count; i++) { *(in + i) = (rank & 0x1); *(sol + i) = (size > 1); 
652         *(out + i) = 0; }
653 MPI_Allreduce( in, out, count, MPI_INT, MPI_LOR, comm );
654 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
655 if (fnderr) fprintf( stderr, 
656         "(%d) Error for type MPI_INT and op MPI_LOR\n", world_rank );
657 free( in );
658 free( out );
659 free( sol );
660 }
661
662
663 {
664 long *in, *out, *sol;
665 int  i, fnderr=0;
666 in = (long *)malloc( count * sizeof(long) );
667 out = (long *)malloc( count * sizeof(long) );
668 sol = (long *)malloc( count * sizeof(long) );
669 for (i=0; i<count; i++) { *(in + i) = (rank & 0x1); *(sol + i) = (size > 1); 
670         *(out + i) = 0; }
671 MPI_Allreduce( in, out, count, MPI_LONG, MPI_LOR, comm );
672 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
673 if (fnderr) fprintf( stderr, 
674         "(%d) Error for type MPI_LONG and op MPI_LOR\n", world_rank );
675 free( in );
676 free( out );
677 free( sol );
678 }
679
680
681 {
682 short *in, *out, *sol;
683 int  i, fnderr=0;
684 in = (short *)malloc( count * sizeof(short) );
685 out = (short *)malloc( count * sizeof(short) );
686 sol = (short *)malloc( count * sizeof(short) );
687 for (i=0; i<count; i++) { *(in + i) = (rank & 0x1); *(sol + i) = (size > 1); 
688         *(out + i) = 0; }
689 MPI_Allreduce( in, out, count, MPI_SHORT, MPI_LOR, comm );
690 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
691 if (fnderr) fprintf( stderr, 
692         "(%d) Error for type MPI_SHORT and op MPI_LOR\n", world_rank );
693 free( in );
694 free( out );
695 free( sol );
696 }
697
698
699 {
700 unsigned short *in, *out, *sol;
701 int  i, fnderr=0;
702 in = (unsigned short *)malloc( count * sizeof(unsigned short) );
703 out = (unsigned short *)malloc( count * sizeof(unsigned short) );
704 sol = (unsigned short *)malloc( count * sizeof(unsigned short) );
705 for (i=0; i<count; i++) { *(in + i) = (rank & 0x1); *(sol + i) = (size > 1); 
706         *(out + i) = 0; }
707 MPI_Allreduce( in, out, count, MPI_UNSIGNED_SHORT, MPI_LOR, comm );
708 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
709 if (fnderr) fprintf( stderr, 
710         "(%d) Error for type MPI_UNSIGNED_SHORT and op MPI_LOR\n", world_rank );
711 free( in );
712 free( out );
713 free( sol );
714 }
715
716
717 {
718 unsigned *in, *out, *sol;
719 int  i, fnderr=0;
720 in = (unsigned *)malloc( count * sizeof(unsigned) );
721 out = (unsigned *)malloc( count * sizeof(unsigned) );
722 sol = (unsigned *)malloc( count * sizeof(unsigned) );
723 for (i=0; i<count; i++) { *(in + i) = (rank & 0x1); *(sol + i) = (size > 1); 
724         *(out + i) = 0; }
725 MPI_Allreduce( in, out, count, MPI_UNSIGNED, MPI_LOR, comm );
726 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
727 if (fnderr) fprintf( stderr, 
728         "(%d) Error for type MPI_UNSIGNED and op MPI_LOR\n", world_rank );
729 free( in );
730 free( out );
731 free( sol );
732 }
733
734
735 {
736 unsigned long *in, *out, *sol;
737 int  i, fnderr=0;
738 in = (unsigned long *)malloc( count * sizeof(unsigned long) );
739 out = (unsigned long *)malloc( count * sizeof(unsigned long) );
740 sol = (unsigned long *)malloc( count * sizeof(unsigned long) );
741 for (i=0; i<count; i++) { *(in + i) = (rank & 0x1); *(sol + i) = (size > 1); 
742         *(out + i) = 0; }
743 MPI_Allreduce( in, out, count, MPI_UNSIGNED_LONG, MPI_LOR, comm );
744 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
745 if (fnderr) fprintf( stderr, 
746         "(%d) Error for type MPI_UNSIGNED_LONG and op MPI_LOR\n", world_rank );
747 free( in );
748 free( out );
749 free( sol );
750 }
751
752
753 gerr += errcnt;
754 if (errcnt > 0)
755         printf( "Found %d errors on %d for MPI_LOR(1)\n", errcnt, rank );
756 errcnt = 0;
757
758
759 {
760 int *in, *out, *sol;
761 int  i, fnderr=0;
762 in = (int *)malloc( count * sizeof(int) );
763 out = (int *)malloc( count * sizeof(int) );
764 sol = (int *)malloc( count * sizeof(int) );
765 for (i=0; i<count; i++) { *(in + i) = 0; *(sol + i) = 0; 
766         *(out + i) = 0; }
767 MPI_Allreduce( in, out, count, MPI_INT, MPI_LOR, comm );
768 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
769 if (fnderr) fprintf( stderr, 
770         "(%d) Error for type MPI_INT and op MPI_LOR\n", world_rank );
771 free( in );
772 free( out );
773 free( sol );
774 }
775
776
777 {
778 long *in, *out, *sol;
779 int  i, fnderr=0;
780 in = (long *)malloc( count * sizeof(long) );
781 out = (long *)malloc( count * sizeof(long) );
782 sol = (long *)malloc( count * sizeof(long) );
783 for (i=0; i<count; i++) { *(in + i) = 0; *(sol + i) = 0; 
784         *(out + i) = 0; }
785 MPI_Allreduce( in, out, count, MPI_LONG, MPI_LOR, comm );
786 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
787 if (fnderr) fprintf( stderr, 
788         "(%d) Error for type MPI_LONG and op MPI_LOR\n", world_rank );
789 free( in );
790 free( out );
791 free( sol );
792 }
793
794
795 {
796 short *in, *out, *sol;
797 int  i, fnderr=0;
798 in = (short *)malloc( count * sizeof(short) );
799 out = (short *)malloc( count * sizeof(short) );
800 sol = (short *)malloc( count * sizeof(short) );
801 for (i=0; i<count; i++) { *(in + i) = 0; *(sol + i) = 0; 
802         *(out + i) = 0; }
803 MPI_Allreduce( in, out, count, MPI_SHORT, MPI_LOR, comm );
804 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
805 if (fnderr) fprintf( stderr, 
806         "(%d) Error for type MPI_SHORT and op MPI_LOR\n", world_rank );
807 free( in );
808 free( out );
809 free( sol );
810 }
811
812
813 {
814 unsigned short *in, *out, *sol;
815 int  i, fnderr=0;
816 in = (unsigned short *)malloc( count * sizeof(unsigned short) );
817 out = (unsigned short *)malloc( count * sizeof(unsigned short) );
818 sol = (unsigned short *)malloc( count * sizeof(unsigned short) );
819 for (i=0; i<count; i++) { *(in + i) = 0; *(sol + i) = 0; 
820         *(out + i) = 0; }
821 MPI_Allreduce( in, out, count, MPI_UNSIGNED_SHORT, MPI_LOR, comm );
822 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
823 if (fnderr) fprintf( stderr, 
824         "(%d) Error for type MPI_UNSIGNED_SHORT and op MPI_LOR\n", world_rank );
825 free( in );
826 free( out );
827 free( sol );
828 }
829
830
831 {
832 unsigned *in, *out, *sol;
833 int  i, fnderr=0;
834 in = (unsigned *)malloc( count * sizeof(unsigned) );
835 out = (unsigned *)malloc( count * sizeof(unsigned) );
836 sol = (unsigned *)malloc( count * sizeof(unsigned) );
837 for (i=0; i<count; i++) { *(in + i) = 0; *(sol + i) = 0; 
838         *(out + i) = 0; }
839 MPI_Allreduce( in, out, count, MPI_UNSIGNED, MPI_LOR, comm );
840 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
841 if (fnderr) fprintf( stderr, 
842         "(%d) Error for type MPI_UNSIGNED and op MPI_LOR\n", world_rank );
843 free( in );
844 free( out );
845 free( sol );
846 }
847
848
849 {
850 unsigned long *in, *out, *sol;
851 int  i, fnderr=0;
852 in = (unsigned long *)malloc( count * sizeof(unsigned long) );
853 out = (unsigned long *)malloc( count * sizeof(unsigned long) );
854 sol = (unsigned long *)malloc( count * sizeof(unsigned long) );
855 for (i=0; i<count; i++) { *(in + i) = 0; *(sol + i) = 0; 
856         *(out + i) = 0; }
857 MPI_Allreduce( in, out, count, MPI_UNSIGNED_LONG, MPI_LOR, comm );
858 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
859 if (fnderr) fprintf( stderr, 
860         "(%d) Error for type MPI_UNSIGNED_LONG and op MPI_LOR\n", world_rank );
861 free( in );
862 free( out );
863 free( sol );
864 }
865
866
867 gerr += errcnt;
868 if (errcnt > 0)
869         printf( "Found %d errors on %d for MPI_LOR(0)\n", errcnt, rank );
870 errcnt = 0;
871
872 /* Test LXOR */
873 if (world_rank == 0 && verbose) printf( "Testing MPI_LXOR...\n" );
874
875 {
876 int *in, *out, *sol;
877 int  i, fnderr=0;
878 in = (int *)malloc( count * sizeof(int) );
879 out = (int *)malloc( count * sizeof(int) );
880 sol = (int *)malloc( count * sizeof(int) );
881 for (i=0; i<count; i++) { *(in + i) = (rank == 1); *(sol + i) = (size > 1); 
882         *(out + i) = 0; }
883 MPI_Allreduce( in, out, count, MPI_INT, MPI_LXOR, comm );
884 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
885 if (fnderr) fprintf( stderr, 
886         "(%d) Error for type MPI_INT and op MPI_LXOR\n", world_rank );
887 free( in );
888 free( out );
889 free( sol );
890 }
891
892
893 {
894 long *in, *out, *sol;
895 int  i, fnderr=0;
896 in = (long *)malloc( count * sizeof(long) );
897 out = (long *)malloc( count * sizeof(long) );
898 sol = (long *)malloc( count * sizeof(long) );
899 for (i=0; i<count; i++) { *(in + i) = (rank == 1); *(sol + i) = (size > 1); 
900         *(out + i) = 0; }
901 MPI_Allreduce( in, out, count, MPI_LONG, MPI_LXOR, comm );
902 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
903 if (fnderr) fprintf( stderr, 
904         "(%d) Error for type MPI_LONG and op MPI_LXOR\n", world_rank );
905 free( in );
906 free( out );
907 free( sol );
908 }
909
910
911 {
912 short *in, *out, *sol;
913 int  i, fnderr=0;
914 in = (short *)malloc( count * sizeof(short) );
915 out = (short *)malloc( count * sizeof(short) );
916 sol = (short *)malloc( count * sizeof(short) );
917 for (i=0; i<count; i++) { *(in + i) = (rank == 1); *(sol + i) = (size > 1); 
918         *(out + i) = 0; }
919 MPI_Allreduce( in, out, count, MPI_SHORT, MPI_LXOR, comm );
920 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
921 if (fnderr) fprintf( stderr, 
922         "(%d) Error for type MPI_SHORT and op MPI_LXOR\n", world_rank );
923 free( in );
924 free( out );
925 free( sol );
926 }
927
928
929 {
930 unsigned short *in, *out, *sol;
931 int  i, fnderr=0;
932 in = (unsigned short *)malloc( count * sizeof(unsigned short) );
933 out = (unsigned short *)malloc( count * sizeof(unsigned short) );
934 sol = (unsigned short *)malloc( count * sizeof(unsigned short) );
935 for (i=0; i<count; i++) { *(in + i) = (rank == 1); *(sol + i) = (size > 1); 
936         *(out + i) = 0; }
937 MPI_Allreduce( in, out, count, MPI_UNSIGNED_SHORT, MPI_LXOR, comm );
938 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
939 if (fnderr) fprintf( stderr, 
940         "(%d) Error for type MPI_UNSIGNED_SHORT and op MPI_LXOR\n", world_rank );
941 free( in );
942 free( out );
943 free( sol );
944 }
945
946
947 {
948 unsigned *in, *out, *sol;
949 int  i, fnderr=0;
950 in = (unsigned *)malloc( count * sizeof(unsigned) );
951 out = (unsigned *)malloc( count * sizeof(unsigned) );
952 sol = (unsigned *)malloc( count * sizeof(unsigned) );
953 for (i=0; i<count; i++) { *(in + i) = (rank == 1); *(sol + i) = (size > 1); 
954         *(out + i) = 0; }
955 MPI_Allreduce( in, out, count, MPI_UNSIGNED, MPI_LXOR, comm );
956 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
957 if (fnderr) fprintf( stderr, 
958         "(%d) Error for type MPI_UNSIGNED and op MPI_LXOR\n", world_rank );
959 free( in );
960 free( out );
961 free( sol );
962 }
963
964
965 {
966 unsigned long *in, *out, *sol;
967 int  i, fnderr=0;
968 in = (unsigned long *)malloc( count * sizeof(unsigned long) );
969 out = (unsigned long *)malloc( count * sizeof(unsigned long) );
970 sol = (unsigned long *)malloc( count * sizeof(unsigned long) );
971 for (i=0; i<count; i++) { *(in + i) = (rank == 1); *(sol + i) = (size > 1); 
972         *(out + i) = 0; }
973 MPI_Allreduce( in, out, count, MPI_UNSIGNED_LONG, MPI_LXOR, comm );
974 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
975 if (fnderr) fprintf( stderr, 
976         "(%d) Error for type MPI_UNSIGNED_LONG and op MPI_LXOR\n", world_rank );
977 free( in );
978 free( out );
979 free( sol );
980 }
981
982
983 gerr += errcnt;
984 if (errcnt > 0)
985         printf( "Found %d errors on %d for MPI_LXOR(1)\n", errcnt, rank );
986 errcnt = 0;
987
988
989 {
990 int *in, *out, *sol;
991 int  i, fnderr=0;
992 in = (int *)malloc( count * sizeof(int) );
993 out = (int *)malloc( count * sizeof(int) );
994 sol = (int *)malloc( count * sizeof(int) );
995 for (i=0; i<count; i++) { *(in + i) = 0; *(sol + i) = 0; 
996         *(out + i) = 0; }
997 MPI_Allreduce( in, out, count, MPI_INT, MPI_LXOR, comm );
998 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
999 if (fnderr) fprintf( stderr, 
1000         "(%d) Error for type MPI_INT and op MPI_LXOR\n", world_rank );
1001 free( in );
1002 free( out );
1003 free( sol );
1004 }
1005
1006
1007 {
1008 long *in, *out, *sol;
1009 int  i, fnderr=0;
1010 in = (long *)malloc( count * sizeof(long) );
1011 out = (long *)malloc( count * sizeof(long) );
1012 sol = (long *)malloc( count * sizeof(long) );
1013 for (i=0; i<count; i++) { *(in + i) = 0; *(sol + i) = 0; 
1014         *(out + i) = 0; }
1015 MPI_Allreduce( in, out, count, MPI_LONG, MPI_LXOR, comm );
1016 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1017 if (fnderr) fprintf( stderr, 
1018         "(%d) Error for type MPI_LONG and op MPI_LXOR\n", world_rank );
1019 free( in );
1020 free( out );
1021 free( sol );
1022 }
1023
1024
1025 {
1026 short *in, *out, *sol;
1027 int  i, fnderr=0;
1028 in = (short *)malloc( count * sizeof(short) );
1029 out = (short *)malloc( count * sizeof(short) );
1030 sol = (short *)malloc( count * sizeof(short) );
1031 for (i=0; i<count; i++) { *(in + i) = 0; *(sol + i) = 0; 
1032         *(out + i) = 0; }
1033 MPI_Allreduce( in, out, count, MPI_SHORT, MPI_LXOR, comm );
1034 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1035 if (fnderr) fprintf( stderr, 
1036         "(%d) Error for type MPI_SHORT and op MPI_LXOR\n", world_rank );
1037 free( in );
1038 free( out );
1039 free( sol );
1040 }
1041
1042
1043 {
1044 unsigned short *in, *out, *sol;
1045 int  i, fnderr=0;
1046 in = (unsigned short *)malloc( count * sizeof(unsigned short) );
1047 out = (unsigned short *)malloc( count * sizeof(unsigned short) );
1048 sol = (unsigned short *)malloc( count * sizeof(unsigned short) );
1049 for (i=0; i<count; i++) { *(in + i) = 0; *(sol + i) = 0; 
1050         *(out + i) = 0; }
1051 MPI_Allreduce( in, out, count, MPI_UNSIGNED_SHORT, MPI_LXOR, comm );
1052 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1053 if (fnderr) fprintf( stderr, 
1054         "(%d) Error for type MPI_UNSIGNED_SHORT and op MPI_LXOR\n", world_rank );
1055 free( in );
1056 free( out );
1057 free( sol );
1058 }
1059
1060
1061 {
1062 unsigned *in, *out, *sol;
1063 int  i, fnderr=0;
1064 in = (unsigned *)malloc( count * sizeof(unsigned) );
1065 out = (unsigned *)malloc( count * sizeof(unsigned) );
1066 sol = (unsigned *)malloc( count * sizeof(unsigned) );
1067 for (i=0; i<count; i++) { *(in + i) = 0; *(sol + i) = 0; 
1068         *(out + i) = 0; }
1069 MPI_Allreduce( in, out, count, MPI_UNSIGNED, MPI_LXOR, comm );
1070 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1071 if (fnderr) fprintf( stderr, 
1072         "(%d) Error for type MPI_UNSIGNED and op MPI_LXOR\n", world_rank );
1073 free( in );
1074 free( out );
1075 free( sol );
1076 }
1077
1078
1079 {
1080 unsigned long *in, *out, *sol;
1081 int  i, fnderr=0;
1082 in = (unsigned long *)malloc( count * sizeof(unsigned long) );
1083 out = (unsigned long *)malloc( count * sizeof(unsigned long) );
1084 sol = (unsigned long *)malloc( count * sizeof(unsigned long) );
1085 for (i=0; i<count; i++) { *(in + i) = 0; *(sol + i) = 0; 
1086         *(out + i) = 0; }
1087 MPI_Allreduce( in, out, count, MPI_UNSIGNED_LONG, MPI_LXOR, comm );
1088 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1089 if (fnderr) fprintf( stderr, 
1090         "(%d) Error for type MPI_UNSIGNED_LONG and op MPI_LXOR\n", world_rank );
1091 free( in );
1092 free( out );
1093 free( sol );
1094 }
1095
1096
1097 gerr += errcnt;
1098 if (errcnt > 0)
1099         printf( "Found %d errors on %d for MPI_LXOR(0)\n", errcnt, rank );
1100 errcnt = 0;
1101
1102
1103 {
1104 int *in, *out, *sol;
1105 int  i, fnderr=0;
1106 in = (int *)malloc( count * sizeof(int) );
1107 out = (int *)malloc( count * sizeof(int) );
1108 sol = (int *)malloc( count * sizeof(int) );
1109 for (i=0; i<count; i++) { *(in + i) = 1; *(sol + i) = 0; 
1110         *(out + i) = 0; }
1111 MPI_Allreduce( in, out, count, MPI_INT, MPI_LXOR, comm );
1112 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1113 if (fnderr) fprintf( stderr, 
1114         "(%d) Error for type MPI_INT and op MPI_LXOR\n", world_rank );
1115 free( in );
1116 free( out );
1117 free( sol );
1118 }
1119
1120
1121 {
1122 long *in, *out, *sol;
1123 int  i, fnderr=0;
1124 in = (long *)malloc( count * sizeof(long) );
1125 out = (long *)malloc( count * sizeof(long) );
1126 sol = (long *)malloc( count * sizeof(long) );
1127 for (i=0; i<count; i++) { *(in + i) = 1; *(sol + i) = 0; 
1128         *(out + i) = 0; }
1129 MPI_Allreduce( in, out, count, MPI_LONG, MPI_LXOR, comm );
1130 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1131 if (fnderr) fprintf( stderr, 
1132         "(%d) Error for type MPI_LONG and op MPI_LXOR\n", world_rank );
1133 free( in );
1134 free( out );
1135 free( sol );
1136 }
1137
1138
1139 {
1140 short *in, *out, *sol;
1141 int  i, fnderr=0;
1142 in = (short *)malloc( count * sizeof(short) );
1143 out = (short *)malloc( count * sizeof(short) );
1144 sol = (short *)malloc( count * sizeof(short) );
1145 for (i=0; i<count; i++) { *(in + i) = 1; *(sol + i) = 0; 
1146         *(out + i) = 0; }
1147 MPI_Allreduce( in, out, count, MPI_SHORT, MPI_LXOR, comm );
1148 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1149 if (fnderr) fprintf( stderr, 
1150         "(%d) Error for type MPI_SHORT and op MPI_LXOR\n", world_rank );
1151 free( in );
1152 free( out );
1153 free( sol );
1154 }
1155
1156
1157 {
1158 unsigned short *in, *out, *sol;
1159 int  i, fnderr=0;
1160 in = (unsigned short *)malloc( count * sizeof(unsigned short) );
1161 out = (unsigned short *)malloc( count * sizeof(unsigned short) );
1162 sol = (unsigned short *)malloc( count * sizeof(unsigned short) );
1163 for (i=0; i<count; i++) { *(in + i) = 1; *(sol + i) = 0; 
1164         *(out + i) = 0; }
1165 MPI_Allreduce( in, out, count, MPI_UNSIGNED_SHORT, MPI_LXOR, comm );
1166 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1167 if (fnderr) fprintf( stderr, 
1168         "(%d) Error for type MPI_UNSIGNED_SHORT and op MPI_LXOR\n", world_rank );
1169 free( in );
1170 free( out );
1171 free( sol );
1172 }
1173
1174
1175 {
1176 unsigned *in, *out, *sol;
1177 int  i, fnderr=0;
1178 in = (unsigned *)malloc( count * sizeof(unsigned) );
1179 out = (unsigned *)malloc( count * sizeof(unsigned) );
1180 sol = (unsigned *)malloc( count * sizeof(unsigned) );
1181 for (i=0; i<count; i++) { *(in + i) = 1; *(sol + i) = 0; 
1182         *(out + i) = 0; }
1183 MPI_Allreduce( in, out, count, MPI_UNSIGNED, MPI_LXOR, comm );
1184 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1185 if (fnderr) fprintf( stderr, 
1186         "(%d) Error for type MPI_UNSIGNED and op MPI_LXOR\n", world_rank );
1187 free( in );
1188 free( out );
1189 free( sol );
1190 }
1191
1192
1193 {
1194 unsigned long *in, *out, *sol;
1195 int  i, fnderr=0;
1196 in = (unsigned long *)malloc( count * sizeof(unsigned long) );
1197 out = (unsigned long *)malloc( count * sizeof(unsigned long) );
1198 sol = (unsigned long *)malloc( count * sizeof(unsigned long) );
1199 for (i=0; i<count; i++) { *(in + i) = 1; *(sol + i) = 0; 
1200         *(out + i) = 0; }
1201 MPI_Allreduce( in, out, count, MPI_UNSIGNED_LONG, MPI_LXOR, comm );
1202 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1203 if (fnderr) fprintf( stderr, 
1204         "(%d) Error for type MPI_UNSIGNED_LONG and op MPI_LXOR\n", world_rank );
1205 free( in );
1206 free( out );
1207 free( sol );
1208 }
1209
1210
1211 gerr += errcnt;
1212 if (errcnt > 0)
1213         printf( "Found %d errors on %d for MPI_LXOR(1-0)\n", errcnt, rank );
1214 errcnt = 0;
1215
1216 /* Test LAND */
1217 if (world_rank == 0 && verbose) printf( "Testing MPI_LAND...\n" );
1218
1219 {
1220 int *in, *out, *sol;
1221 int  i, fnderr=0;
1222 in = (int *)malloc( count * sizeof(int) );
1223 out = (int *)malloc( count * sizeof(int) );
1224 sol = (int *)malloc( count * sizeof(int) );
1225 for (i=0; i<count; i++) { *(in + i) = (rank & 0x1); *(sol + i) = 0; 
1226         *(out + i) = 0; }
1227 MPI_Allreduce( in, out, count, MPI_INT, MPI_LAND, comm );
1228 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1229 if (fnderr) fprintf( stderr, 
1230         "(%d) Error for type MPI_INT and op MPI_LAND\n", world_rank );
1231 free( in );
1232 free( out );
1233 free( sol );
1234 }
1235
1236
1237 {
1238 long *in, *out, *sol;
1239 int  i, fnderr=0;
1240 in = (long *)malloc( count * sizeof(long) );
1241 out = (long *)malloc( count * sizeof(long) );
1242 sol = (long *)malloc( count * sizeof(long) );
1243 for (i=0; i<count; i++) { *(in + i) = (rank & 0x1); *(sol + i) = 0; 
1244         *(out + i) = 0; }
1245 MPI_Allreduce( in, out, count, MPI_LONG, MPI_LAND, comm );
1246 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1247 if (fnderr) fprintf( stderr, 
1248         "(%d) Error for type MPI_LONG and op MPI_LAND\n", world_rank );
1249 free( in );
1250 free( out );
1251 free( sol );
1252 }
1253
1254
1255 {
1256 short *in, *out, *sol;
1257 int  i, fnderr=0;
1258 in = (short *)malloc( count * sizeof(short) );
1259 out = (short *)malloc( count * sizeof(short) );
1260 sol = (short *)malloc( count * sizeof(short) );
1261 for (i=0; i<count; i++) { *(in + i) = (rank & 0x1); *(sol + i) = 0; 
1262         *(out + i) = 0; }
1263 MPI_Allreduce( in, out, count, MPI_SHORT, MPI_LAND, comm );
1264 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1265 if (fnderr) fprintf( stderr, 
1266         "(%d) Error for type MPI_SHORT and op MPI_LAND\n", world_rank );
1267 free( in );
1268 free( out );
1269 free( sol );
1270 }
1271
1272
1273 {
1274 unsigned short *in, *out, *sol;
1275 int  i, fnderr=0;
1276 in = (unsigned short *)malloc( count * sizeof(unsigned short) );
1277 out = (unsigned short *)malloc( count * sizeof(unsigned short) );
1278 sol = (unsigned short *)malloc( count * sizeof(unsigned short) );
1279 for (i=0; i<count; i++) { *(in + i) = (rank & 0x1); *(sol + i) = 0; 
1280         *(out + i) = 0; }
1281 MPI_Allreduce( in, out, count, MPI_UNSIGNED_SHORT, MPI_LAND, comm );
1282 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1283 if (fnderr) fprintf( stderr, 
1284         "(%d) Error for type MPI_UNSIGNED_SHORT and op MPI_LAND\n", world_rank );
1285 free( in );
1286 free( out );
1287 free( sol );
1288 }
1289
1290
1291 {
1292 unsigned *in, *out, *sol;
1293 int  i, fnderr=0;
1294 in = (unsigned *)malloc( count * sizeof(unsigned) );
1295 out = (unsigned *)malloc( count * sizeof(unsigned) );
1296 sol = (unsigned *)malloc( count * sizeof(unsigned) );
1297 for (i=0; i<count; i++) { *(in + i) = (rank & 0x1); *(sol + i) = 0; 
1298         *(out + i) = 0; }
1299 MPI_Allreduce( in, out, count, MPI_UNSIGNED, MPI_LAND, comm );
1300 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1301 if (fnderr) fprintf( stderr, 
1302         "(%d) Error for type MPI_UNSIGNED and op MPI_LAND\n", world_rank );
1303 free( in );
1304 free( out );
1305 free( sol );
1306 }
1307
1308
1309 {
1310 unsigned long *in, *out, *sol;
1311 int  i, fnderr=0;
1312 in = (unsigned long *)malloc( count * sizeof(unsigned long) );
1313 out = (unsigned long *)malloc( count * sizeof(unsigned long) );
1314 sol = (unsigned long *)malloc( count * sizeof(unsigned long) );
1315 for (i=0; i<count; i++) { *(in + i) = (rank & 0x1); *(sol + i) = 0; 
1316         *(out + i) = 0; }
1317 MPI_Allreduce( in, out, count, MPI_UNSIGNED_LONG, MPI_LAND, comm );
1318 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1319 if (fnderr) fprintf( stderr, 
1320         "(%d) Error for type MPI_UNSIGNED_LONG and op MPI_LAND\n", world_rank );
1321 free( in );
1322 free( out );
1323 free( sol );
1324 }
1325
1326
1327 gerr += errcnt;
1328 if (errcnt > 0)
1329         printf( "Found %d errors on %d for MPI_LAND(0)\n", errcnt, rank );
1330 errcnt = 0;
1331
1332
1333 {
1334 int *in, *out, *sol;
1335 int  i, fnderr=0;
1336 in = (int *)malloc( count * sizeof(int) );
1337 out = (int *)malloc( count * sizeof(int) );
1338 sol = (int *)malloc( count * sizeof(int) );
1339 for (i=0; i<count; i++) { *(in + i) = 1; *(sol + i) = 1; 
1340         *(out + i) = 0; }
1341 MPI_Allreduce( in, out, count, MPI_INT, MPI_LAND, comm );
1342 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1343 if (fnderr) fprintf( stderr, 
1344         "(%d) Error for type MPI_INT and op MPI_LAND\n", world_rank );
1345 free( in );
1346 free( out );
1347 free( sol );
1348 }
1349
1350
1351 {
1352 long *in, *out, *sol;
1353 int  i, fnderr=0;
1354 in = (long *)malloc( count * sizeof(long) );
1355 out = (long *)malloc( count * sizeof(long) );
1356 sol = (long *)malloc( count * sizeof(long) );
1357 for (i=0; i<count; i++) { *(in + i) = 1; *(sol + i) = 1; 
1358         *(out + i) = 0; }
1359 MPI_Allreduce( in, out, count, MPI_LONG, MPI_LAND, comm );
1360 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1361 if (fnderr) fprintf( stderr, 
1362         "(%d) Error for type MPI_LONG and op MPI_LAND\n", world_rank );
1363 free( in );
1364 free( out );
1365 free( sol );
1366 }
1367
1368
1369 {
1370 short *in, *out, *sol;
1371 int  i, fnderr=0;
1372 in = (short *)malloc( count * sizeof(short) );
1373 out = (short *)malloc( count * sizeof(short) );
1374 sol = (short *)malloc( count * sizeof(short) );
1375 for (i=0; i<count; i++) { *(in + i) = 1; *(sol + i) = 1; 
1376         *(out + i) = 0; }
1377 MPI_Allreduce( in, out, count, MPI_SHORT, MPI_LAND, comm );
1378 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1379 if (fnderr) fprintf( stderr, 
1380         "(%d) Error for type MPI_SHORT and op MPI_LAND\n", world_rank );
1381 free( in );
1382 free( out );
1383 free( sol );
1384 }
1385
1386
1387 {
1388 unsigned short *in, *out, *sol;
1389 int  i, fnderr=0;
1390 in = (unsigned short *)malloc( count * sizeof(unsigned short) );
1391 out = (unsigned short *)malloc( count * sizeof(unsigned short) );
1392 sol = (unsigned short *)malloc( count * sizeof(unsigned short) );
1393 for (i=0; i<count; i++) { *(in + i) = 1; *(sol + i) = 1; 
1394         *(out + i) = 0; }
1395 MPI_Allreduce( in, out, count, MPI_UNSIGNED_SHORT, MPI_LAND, comm );
1396 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1397 if (fnderr) fprintf( stderr, 
1398         "(%d) Error for type MPI_UNSIGNED_SHORT and op MPI_LAND\n", world_rank );
1399 free( in );
1400 free( out );
1401 free( sol );
1402 }
1403
1404
1405 {
1406 unsigned *in, *out, *sol;
1407 int  i, fnderr=0;
1408 in = (unsigned *)malloc( count * sizeof(unsigned) );
1409 out = (unsigned *)malloc( count * sizeof(unsigned) );
1410 sol = (unsigned *)malloc( count * sizeof(unsigned) );
1411 for (i=0; i<count; i++) { *(in + i) = 1; *(sol + i) = 1; 
1412         *(out + i) = 0; }
1413 MPI_Allreduce( in, out, count, MPI_UNSIGNED, MPI_LAND, comm );
1414 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1415 if (fnderr) fprintf( stderr, 
1416         "(%d) Error for type MPI_UNSIGNED and op MPI_LAND\n", world_rank );
1417 free( in );
1418 free( out );
1419 free( sol );
1420 }
1421
1422
1423 {
1424 unsigned long *in, *out, *sol;
1425 int  i, fnderr=0;
1426 in = (unsigned long *)malloc( count * sizeof(unsigned long) );
1427 out = (unsigned long *)malloc( count * sizeof(unsigned long) );
1428 sol = (unsigned long *)malloc( count * sizeof(unsigned long) );
1429 for (i=0; i<count; i++) { *(in + i) = 1; *(sol + i) = 1; 
1430         *(out + i) = 0; }
1431 MPI_Allreduce( in, out, count, MPI_UNSIGNED_LONG, MPI_LAND, comm );
1432 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1433 if (fnderr) fprintf( stderr, 
1434         "(%d) Error for type MPI_UNSIGNED_LONG and op MPI_LAND\n", world_rank );
1435 free( in );
1436 free( out );
1437 free( sol );
1438 }
1439
1440
1441 gerr += errcnt;
1442 if (errcnt > 0)
1443         printf( "Found %d errors on %d for MPI_LAND(1)\n", errcnt, rank );
1444 errcnt = 0;
1445
1446 /* Test BOR */
1447 if (world_rank == 0 && verbose) printf( "Testing MPI_BOR...\n" );
1448
1449 {
1450 int *in, *out, *sol;
1451 int  i, fnderr=0;
1452 in = (int *)malloc( count * sizeof(int) );
1453 out = (int *)malloc( count * sizeof(int) );
1454 sol = (int *)malloc( count * sizeof(int) );
1455 for (i=0; i<count; i++) { *(in + i) = rank & 0x3; *(sol + i) = (size < 3) ? size - 1 : 0x3; 
1456         *(out + i) = 0; }
1457 MPI_Allreduce( in, out, count, MPI_INT, MPI_BOR, comm );
1458 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1459 if (fnderr) fprintf( stderr, 
1460         "(%d) Error for type MPI_INT and op MPI_BOR\n", world_rank );
1461 free( in );
1462 free( out );
1463 free( sol );
1464 }
1465
1466
1467 {
1468 long *in, *out, *sol;
1469 int  i, fnderr=0;
1470 in = (long *)malloc( count * sizeof(long) );
1471 out = (long *)malloc( count * sizeof(long) );
1472 sol = (long *)malloc( count * sizeof(long) );
1473 for (i=0; i<count; i++) { *(in + i) = rank & 0x3; *(sol + i) = (size < 3) ? size - 1 : 0x3; 
1474         *(out + i) = 0; }
1475 MPI_Allreduce( in, out, count, MPI_LONG, MPI_BOR, comm );
1476 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1477 if (fnderr) fprintf( stderr, 
1478         "(%d) Error for type MPI_LONG and op MPI_BOR\n", world_rank );
1479 free( in );
1480 free( out );
1481 free( sol );
1482 }
1483
1484
1485 {
1486 short *in, *out, *sol;
1487 int  i, fnderr=0;
1488 in = (short *)malloc( count * sizeof(short) );
1489 out = (short *)malloc( count * sizeof(short) );
1490 sol = (short *)malloc( count * sizeof(short) );
1491 for (i=0; i<count; i++) { *(in + i) = rank & 0x3; *(sol + i) = (size < 3) ? size - 1 : 0x3; 
1492         *(out + i) = 0; }
1493 MPI_Allreduce( in, out, count, MPI_SHORT, MPI_BOR, comm );
1494 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1495 if (fnderr) fprintf( stderr, 
1496         "(%d) Error for type MPI_SHORT and op MPI_BOR\n", world_rank );
1497 free( in );
1498 free( out );
1499 free( sol );
1500 }
1501
1502
1503 {
1504 unsigned short *in, *out, *sol;
1505 int  i, fnderr=0;
1506 in = (unsigned short *)malloc( count * sizeof(unsigned short) );
1507 out = (unsigned short *)malloc( count * sizeof(unsigned short) );
1508 sol = (unsigned short *)malloc( count * sizeof(unsigned short) );
1509 for (i=0; i<count; i++) { *(in + i) = rank & 0x3; *(sol + i) = (size < 3) ? size - 1 : 0x3; 
1510         *(out + i) = 0; }
1511 MPI_Allreduce( in, out, count, MPI_UNSIGNED_SHORT, MPI_BOR, comm );
1512 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1513 if (fnderr) fprintf( stderr, 
1514         "(%d) Error for type MPI_UNSIGNED_SHORT and op MPI_BOR\n", world_rank );
1515 free( in );
1516 free( out );
1517 free( sol );
1518 }
1519
1520
1521 {
1522 unsigned *in, *out, *sol;
1523 int  i, fnderr=0;
1524 in = (unsigned *)malloc( count * sizeof(unsigned) );
1525 out = (unsigned *)malloc( count * sizeof(unsigned) );
1526 sol = (unsigned *)malloc( count * sizeof(unsigned) );
1527 for (i=0; i<count; i++) { *(in + i) = rank & 0x3; *(sol + i) = (size < 3) ? size - 1 : 0x3; 
1528         *(out + i) = 0; }
1529 MPI_Allreduce( in, out, count, MPI_UNSIGNED, MPI_BOR, comm );
1530 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1531 if (fnderr) fprintf( stderr, 
1532         "(%d) Error for type MPI_UNSIGNED and op MPI_BOR\n", world_rank );
1533 free( in );
1534 free( out );
1535 free( sol );
1536 }
1537
1538
1539 {
1540 unsigned long *in, *out, *sol;
1541 int  i, fnderr=0;
1542 in = (unsigned long *)malloc( count * sizeof(unsigned long) );
1543 out = (unsigned long *)malloc( count * sizeof(unsigned long) );
1544 sol = (unsigned long *)malloc( count * sizeof(unsigned long) );
1545 for (i=0; i<count; i++) { *(in + i) = rank & 0x3; *(sol + i) = (size < 3) ? size - 1 : 0x3; 
1546         *(out + i) = 0; }
1547 MPI_Allreduce( in, out, count, MPI_UNSIGNED_LONG, MPI_BOR, comm );
1548 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1549 if (fnderr) fprintf( stderr, 
1550         "(%d) Error for type MPI_UNSIGNED_LONG and op MPI_BOR\n", world_rank );
1551 free( in );
1552 free( out );
1553 free( sol );
1554 }
1555
1556
1557 {
1558 unsigned char *in, *out, *sol;
1559 int  i, fnderr=0;
1560 in = (unsigned char *)malloc( count * sizeof(unsigned char) );
1561 out = (unsigned char *)malloc( count * sizeof(unsigned char) );
1562 sol = (unsigned char *)malloc( count * sizeof(unsigned char) );
1563 for (i=0; i<count; i++) { *(in + i) = rank & 0x3; *(sol + i) = (size < 3) ? size - 1 : 0x3; 
1564         *(out + i) = 0; }
1565 MPI_Allreduce( in, out, count, MPI_BYTE, MPI_BOR, comm );
1566 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1567 if (fnderr) fprintf( stderr, 
1568         "(%d) Error for type MPI_BYTE and op MPI_BOR\n", world_rank );
1569 free( in );
1570 free( out );
1571 free( sol );
1572 }
1573
1574
1575 gerr += errcnt;
1576 if (errcnt > 0)
1577         printf( "Found %d errors on %d for MPI_BOR(1)\n", errcnt, rank );
1578 errcnt = 0;
1579
1580 /* Test BAND */
1581 if (world_rank == 0 && verbose) printf( "Testing MPI_BAND...\n" );
1582
1583 {
1584 int *in, *out, *sol;
1585 int  i, fnderr=0;
1586 in = (int *)malloc( count * sizeof(int) );
1587 out = (int *)malloc( count * sizeof(int) );
1588 sol = (int *)malloc( count * sizeof(int) );
1589 for (i=0; i<count; i++) { *(in + i) = (rank == size-1 ? i : ~0); *(sol + i) = i; 
1590         *(out + i) = 0; }
1591 MPI_Allreduce( in, out, count, MPI_INT, MPI_BAND, comm );
1592 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1593 if (fnderr) fprintf( stderr, 
1594         "(%d) Error for type MPI_INT and op MPI_BAND\n", world_rank );
1595 free( in );
1596 free( out );
1597 free( sol );
1598 }
1599
1600
1601 {
1602 long *in, *out, *sol;
1603 int  i, fnderr=0;
1604 in = (long *)malloc( count * sizeof(long) );
1605 out = (long *)malloc( count * sizeof(long) );
1606 sol = (long *)malloc( count * sizeof(long) );
1607 for (i=0; i<count; i++) { *(in + i) = (rank == size-1 ? i : ~0); *(sol + i) = i; 
1608         *(out + i) = 0; }
1609 MPI_Allreduce( in, out, count, MPI_LONG, MPI_BAND, comm );
1610 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1611 if (fnderr) fprintf( stderr, 
1612         "(%d) Error for type MPI_LONG and op MPI_BAND\n", world_rank );
1613 free( in );
1614 free( out );
1615 free( sol );
1616 }
1617
1618
1619 {
1620 short *in, *out, *sol;
1621 int  i, fnderr=0;
1622 in = (short *)malloc( count * sizeof(short) );
1623 out = (short *)malloc( count * sizeof(short) );
1624 sol = (short *)malloc( count * sizeof(short) );
1625 for (i=0; i<count; i++) { *(in + i) = (rank == size-1 ? i : ~0); *(sol + i) = i; 
1626         *(out + i) = 0; }
1627 MPI_Allreduce( in, out, count, MPI_SHORT, MPI_BAND, comm );
1628 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1629 if (fnderr) fprintf( stderr, 
1630         "(%d) Error for type MPI_SHORT and op MPI_BAND\n", world_rank );
1631 free( in );
1632 free( out );
1633 free( sol );
1634 }
1635
1636
1637 {
1638 unsigned short *in, *out, *sol;
1639 int  i, fnderr=0;
1640 in = (unsigned short *)malloc( count * sizeof(unsigned short) );
1641 out = (unsigned short *)malloc( count * sizeof(unsigned short) );
1642 sol = (unsigned short *)malloc( count * sizeof(unsigned short) );
1643 for (i=0; i<count; i++) { *(in + i) = (rank == size-1 ? i : ~0); *(sol + i) = i; 
1644         *(out + i) = 0; }
1645 MPI_Allreduce( in, out, count, MPI_UNSIGNED_SHORT, MPI_BAND, comm );
1646 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1647 if (fnderr) fprintf( stderr, 
1648         "(%d) Error for type MPI_UNSIGNED_SHORT and op MPI_BAND\n", world_rank );
1649 free( in );
1650 free( out );
1651 free( sol );
1652 }
1653
1654
1655 {
1656 unsigned *in, *out, *sol;
1657 int  i, fnderr=0;
1658 in = (unsigned *)malloc( count * sizeof(unsigned) );
1659 out = (unsigned *)malloc( count * sizeof(unsigned) );
1660 sol = (unsigned *)malloc( count * sizeof(unsigned) );
1661 for (i=0; i<count; i++) { *(in + i) = (rank == size-1 ? i : ~0); *(sol + i) = i; 
1662         *(out + i) = 0; }
1663 MPI_Allreduce( in, out, count, MPI_UNSIGNED, MPI_BAND, comm );
1664 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1665 if (fnderr) fprintf( stderr, 
1666         "(%d) Error for type MPI_UNSIGNED and op MPI_BAND\n", world_rank );
1667 free( in );
1668 free( out );
1669 free( sol );
1670 }
1671
1672
1673 {
1674 unsigned long *in, *out, *sol;
1675 int  i, fnderr=0;
1676 in = (unsigned long *)malloc( count * sizeof(unsigned long) );
1677 out = (unsigned long *)malloc( count * sizeof(unsigned long) );
1678 sol = (unsigned long *)malloc( count * sizeof(unsigned long) );
1679 for (i=0; i<count; i++) { *(in + i) = (rank == size-1 ? i : ~0); *(sol + i) = i; 
1680         *(out + i) = 0; }
1681 MPI_Allreduce( in, out, count, MPI_UNSIGNED_LONG, MPI_BAND, comm );
1682 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1683 if (fnderr) fprintf( stderr, 
1684         "(%d) Error for type MPI_UNSIGNED_LONG and op MPI_BAND\n", world_rank );
1685 free( in );
1686 free( out );
1687 free( sol );
1688 }
1689
1690
1691 {
1692 unsigned char *in, *out, *sol;
1693 int  i, fnderr=0;
1694 in = (unsigned char *)malloc( count * sizeof(unsigned char) );
1695 out = (unsigned char *)malloc( count * sizeof(unsigned char) );
1696 sol = (unsigned char *)malloc( count * sizeof(unsigned char) );
1697 for (i=0; i<count; i++) { *(in + i) = (rank == size-1 ? i : ~0); *(sol + i) = i; 
1698         *(out + i) = 0; }
1699 MPI_Allreduce( in, out, count, MPI_BYTE, MPI_BAND, comm );
1700 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1701 if (fnderr) fprintf( stderr, 
1702         "(%d) Error for type MPI_BYTE and op MPI_BAND\n", world_rank );
1703 free( in );
1704 free( out );
1705 free( sol );
1706 }
1707
1708
1709 gerr += errcnt;
1710 if (errcnt > 0)
1711         printf( "Found %d errors on %d for MPI_BAND(1)\n", errcnt, rank );
1712 errcnt = 0;
1713
1714
1715 {
1716 int *in, *out, *sol;
1717 int  i, fnderr=0;
1718 in = (int *)malloc( count * sizeof(int) );
1719 out = (int *)malloc( count * sizeof(int) );
1720 sol = (int *)malloc( count * sizeof(int) );
1721 for (i=0; i<count; i++) { *(in + i) = (rank == size-1 ? i : 0); *(sol + i) = 0; 
1722         *(out + i) = 0; }
1723 MPI_Allreduce( in, out, count, MPI_INT, MPI_BAND, comm );
1724 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1725 if (fnderr) fprintf( stderr, 
1726         "(%d) Error for type MPI_INT and op MPI_BAND\n", world_rank );
1727 free( in );
1728 free( out );
1729 free( sol );
1730 }
1731
1732
1733 {
1734 long *in, *out, *sol;
1735 int  i, fnderr=0;
1736 in = (long *)malloc( count * sizeof(long) );
1737 out = (long *)malloc( count * sizeof(long) );
1738 sol = (long *)malloc( count * sizeof(long) );
1739 for (i=0; i<count; i++) { *(in + i) = (rank == size-1 ? i : 0); *(sol + i) = 0; 
1740         *(out + i) = 0; }
1741 MPI_Allreduce( in, out, count, MPI_LONG, MPI_BAND, comm );
1742 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1743 if (fnderr) fprintf( stderr, 
1744         "(%d) Error for type MPI_LONG and op MPI_BAND\n", world_rank );
1745 free( in );
1746 free( out );
1747 free( sol );
1748 }
1749
1750
1751 {
1752 short *in, *out, *sol;
1753 int  i, fnderr=0;
1754 in = (short *)malloc( count * sizeof(short) );
1755 out = (short *)malloc( count * sizeof(short) );
1756 sol = (short *)malloc( count * sizeof(short) );
1757 for (i=0; i<count; i++) { *(in + i) = (rank == size-1 ? i : 0); *(sol + i) = 0; 
1758         *(out + i) = 0; }
1759 MPI_Allreduce( in, out, count, MPI_SHORT, MPI_BAND, comm );
1760 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1761 if (fnderr) fprintf( stderr, 
1762         "(%d) Error for type MPI_SHORT and op MPI_BAND\n", world_rank );
1763 free( in );
1764 free( out );
1765 free( sol );
1766 }
1767
1768
1769 {
1770 unsigned short *in, *out, *sol;
1771 int  i, fnderr=0;
1772 in = (unsigned short *)malloc( count * sizeof(unsigned short) );
1773 out = (unsigned short *)malloc( count * sizeof(unsigned short) );
1774 sol = (unsigned short *)malloc( count * sizeof(unsigned short) );
1775 for (i=0; i<count; i++) { *(in + i) = (rank == size-1 ? i : 0); *(sol + i) = 0; 
1776         *(out + i) = 0; }
1777 MPI_Allreduce( in, out, count, MPI_UNSIGNED_SHORT, MPI_BAND, comm );
1778 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1779 if (fnderr) fprintf( stderr, 
1780         "(%d) Error for type MPI_UNSIGNED_SHORT and op MPI_BAND\n", world_rank );
1781 free( in );
1782 free( out );
1783 free( sol );
1784 }
1785
1786
1787 {
1788 unsigned *in, *out, *sol;
1789 int  i, fnderr=0;
1790 in = (unsigned *)malloc( count * sizeof(unsigned) );
1791 out = (unsigned *)malloc( count * sizeof(unsigned) );
1792 sol = (unsigned *)malloc( count * sizeof(unsigned) );
1793 for (i=0; i<count; i++) { *(in + i) = (rank == size-1 ? i : 0); *(sol + i) = 0; 
1794         *(out + i) = 0; }
1795 MPI_Allreduce( in, out, count, MPI_UNSIGNED, MPI_BAND, comm );
1796 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1797 if (fnderr) fprintf( stderr, 
1798         "(%d) Error for type MPI_UNSIGNED and op MPI_BAND\n", world_rank );
1799 free( in );
1800 free( out );
1801 free( sol );
1802 }
1803
1804
1805 {
1806 unsigned long *in, *out, *sol;
1807 int  i, fnderr=0;
1808 in = (unsigned long *)malloc( count * sizeof(unsigned long) );
1809 out = (unsigned long *)malloc( count * sizeof(unsigned long) );
1810 sol = (unsigned long *)malloc( count * sizeof(unsigned long) );
1811 for (i=0; i<count; i++) { *(in + i) = (rank == size-1 ? i : 0); *(sol + i) = 0; 
1812         *(out + i) = 0; }
1813 MPI_Allreduce( in, out, count, MPI_UNSIGNED_LONG, MPI_BAND, comm );
1814 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1815 if (fnderr) fprintf( stderr, 
1816         "(%d) Error for type MPI_UNSIGNED_LONG and op MPI_BAND\n", world_rank );
1817 free( in );
1818 free( out );
1819 free( sol );
1820 }
1821
1822
1823 gerr += errcnt;
1824 if (errcnt > 0)
1825         printf( "Found %d errors on %d for MPI_BAND(0)\n", errcnt, rank );
1826 errcnt = 0;
1827
1828 /* Test BXOR */
1829 if (world_rank == 0 && verbose) printf( "Testing MPI_BXOR...\n" );
1830
1831 {
1832 int *in, *out, *sol;
1833 int  i, fnderr=0;
1834 in = (int *)malloc( count * sizeof(int) );
1835 out = (int *)malloc( count * sizeof(int) );
1836 sol = (int *)malloc( count * sizeof(int) );
1837 for (i=0; i<count; i++) { *(in + i) = (rank == 1)*0xf0 ; *(sol + i) = (size > 1)*0xf0 ; 
1838         *(out + i) = 0; }
1839 MPI_Allreduce( in, out, count, MPI_INT, MPI_BXOR, comm );
1840 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1841 if (fnderr) fprintf( stderr, 
1842         "(%d) Error for type MPI_INT and op MPI_BXOR\n", world_rank );
1843 free( in );
1844 free( out );
1845 free( sol );
1846 }
1847
1848
1849 {
1850 long *in, *out, *sol;
1851 int  i, fnderr=0;
1852 in = (long *)malloc( count * sizeof(long) );
1853 out = (long *)malloc( count * sizeof(long) );
1854 sol = (long *)malloc( count * sizeof(long) );
1855 for (i=0; i<count; i++) { *(in + i) = (rank == 1)*0xf0 ; *(sol + i) = (size > 1)*0xf0 ; 
1856         *(out + i) = 0; }
1857 MPI_Allreduce( in, out, count, MPI_LONG, MPI_BXOR, comm );
1858 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1859 if (fnderr) fprintf( stderr, 
1860         "(%d) Error for type MPI_LONG and op MPI_BXOR\n", world_rank );
1861 free( in );
1862 free( out );
1863 free( sol );
1864 }
1865
1866
1867 {
1868 short *in, *out, *sol;
1869 int  i, fnderr=0;
1870 in = (short *)malloc( count * sizeof(short) );
1871 out = (short *)malloc( count * sizeof(short) );
1872 sol = (short *)malloc( count * sizeof(short) );
1873 for (i=0; i<count; i++) { *(in + i) = (rank == 1)*0xf0 ; *(sol + i) = (size > 1)*0xf0 ; 
1874         *(out + i) = 0; }
1875 MPI_Allreduce( in, out, count, MPI_SHORT, MPI_BXOR, comm );
1876 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1877 if (fnderr) fprintf( stderr, 
1878         "(%d) Error for type MPI_SHORT and op MPI_BXOR\n", world_rank );
1879 free( in );
1880 free( out );
1881 free( sol );
1882 }
1883
1884
1885 {
1886 unsigned short *in, *out, *sol;
1887 int  i, fnderr=0;
1888 in = (unsigned short *)malloc( count * sizeof(unsigned short) );
1889 out = (unsigned short *)malloc( count * sizeof(unsigned short) );
1890 sol = (unsigned short *)malloc( count * sizeof(unsigned short) );
1891 for (i=0; i<count; i++) { *(in + i) = (rank == 1)*0xf0 ; *(sol + i) = (size > 1)*0xf0 ; 
1892         *(out + i) = 0; }
1893 MPI_Allreduce( in, out, count, MPI_UNSIGNED_SHORT, MPI_BXOR, comm );
1894 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1895 if (fnderr) fprintf( stderr, 
1896         "(%d) Error for type MPI_UNSIGNED_SHORT and op MPI_BXOR\n", world_rank );
1897 free( in );
1898 free( out );
1899 free( sol );
1900 }
1901
1902
1903 {
1904 unsigned *in, *out, *sol;
1905 int  i, fnderr=0;
1906 in = (unsigned *)malloc( count * sizeof(unsigned) );
1907 out = (unsigned *)malloc( count * sizeof(unsigned) );
1908 sol = (unsigned *)malloc( count * sizeof(unsigned) );
1909 for (i=0; i<count; i++) { *(in + i) = (rank == 1)*0xf0 ; *(sol + i) = (size > 1)*0xf0 ; 
1910         *(out + i) = 0; }
1911 MPI_Allreduce( in, out, count, MPI_UNSIGNED, MPI_BXOR, comm );
1912 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1913 if (fnderr) fprintf( stderr, 
1914         "(%d) Error for type MPI_UNSIGNED and op MPI_BXOR\n", world_rank );
1915 free( in );
1916 free( out );
1917 free( sol );
1918 }
1919
1920
1921 {
1922 unsigned long *in, *out, *sol;
1923 int  i, fnderr=0;
1924 in = (unsigned long *)malloc( count * sizeof(unsigned long) );
1925 out = (unsigned long *)malloc( count * sizeof(unsigned long) );
1926 sol = (unsigned long *)malloc( count * sizeof(unsigned long) );
1927 for (i=0; i<count; i++) { *(in + i) = (rank == 1)*0xf0 ; *(sol + i) = (size > 1)*0xf0 ; 
1928         *(out + i) = 0; }
1929 MPI_Allreduce( in, out, count, MPI_UNSIGNED_LONG, MPI_BXOR, comm );
1930 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1931 if (fnderr) fprintf( stderr, 
1932         "(%d) Error for type MPI_UNSIGNED_LONG and op MPI_BXOR\n", world_rank );
1933 free( in );
1934 free( out );
1935 free( sol );
1936 }
1937
1938
1939 gerr += errcnt;
1940 if (errcnt > 0)
1941         printf( "Found %d errors on %d for MPI_BXOR(1)\n", errcnt, rank );
1942 errcnt = 0;
1943
1944
1945 {
1946 int *in, *out, *sol;
1947 int  i, fnderr=0;
1948 in = (int *)malloc( count * sizeof(int) );
1949 out = (int *)malloc( count * sizeof(int) );
1950 sol = (int *)malloc( count * sizeof(int) );
1951 for (i=0; i<count; i++) { *(in + i) = 0; *(sol + i) = 0; 
1952         *(out + i) = 0; }
1953 MPI_Allreduce( in, out, count, MPI_INT, MPI_BXOR, comm );
1954 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1955 if (fnderr) fprintf( stderr, 
1956         "(%d) Error for type MPI_INT and op MPI_BXOR\n", world_rank );
1957 free( in );
1958 free( out );
1959 free( sol );
1960 }
1961
1962
1963 {
1964 long *in, *out, *sol;
1965 int  i, fnderr=0;
1966 in = (long *)malloc( count * sizeof(long) );
1967 out = (long *)malloc( count * sizeof(long) );
1968 sol = (long *)malloc( count * sizeof(long) );
1969 for (i=0; i<count; i++) { *(in + i) = 0; *(sol + i) = 0; 
1970         *(out + i) = 0; }
1971 MPI_Allreduce( in, out, count, MPI_LONG, MPI_BXOR, comm );
1972 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1973 if (fnderr) fprintf( stderr, 
1974         "(%d) Error for type MPI_LONG and op MPI_BXOR\n", world_rank );
1975 free( in );
1976 free( out );
1977 free( sol );
1978 }
1979
1980
1981 {
1982 short *in, *out, *sol;
1983 int  i, fnderr=0;
1984 in = (short *)malloc( count * sizeof(short) );
1985 out = (short *)malloc( count * sizeof(short) );
1986 sol = (short *)malloc( count * sizeof(short) );
1987 for (i=0; i<count; i++) { *(in + i) = 0; *(sol + i) = 0; 
1988         *(out + i) = 0; }
1989 MPI_Allreduce( in, out, count, MPI_SHORT, MPI_BXOR, comm );
1990 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
1991 if (fnderr) fprintf( stderr, 
1992         "(%d) Error for type MPI_SHORT and op MPI_BXOR\n", world_rank );
1993 free( in );
1994 free( out );
1995 free( sol );
1996 }
1997
1998
1999 {
2000 unsigned short *in, *out, *sol;
2001 int  i, fnderr=0;
2002 in = (unsigned short *)malloc( count * sizeof(unsigned short) );
2003 out = (unsigned short *)malloc( count * sizeof(unsigned short) );
2004 sol = (unsigned short *)malloc( count * sizeof(unsigned short) );
2005 for (i=0; i<count; i++) { *(in + i) = 0; *(sol + i) = 0; 
2006         *(out + i) = 0; }
2007 MPI_Allreduce( in, out, count, MPI_UNSIGNED_SHORT, MPI_BXOR, comm );
2008 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
2009 if (fnderr) fprintf( stderr, 
2010         "(%d) Error for type MPI_UNSIGNED_SHORT and op MPI_BXOR\n", world_rank );
2011 free( in );
2012 free( out );
2013 free( sol );
2014 }
2015
2016
2017 {
2018 unsigned *in, *out, *sol;
2019 int  i, fnderr=0;
2020 in = (unsigned *)malloc( count * sizeof(unsigned) );
2021 out = (unsigned *)malloc( count * sizeof(unsigned) );
2022 sol = (unsigned *)malloc( count * sizeof(unsigned) );
2023 for (i=0; i<count; i++) { *(in + i) = 0; *(sol + i) = 0; 
2024         *(out + i) = 0; }
2025 MPI_Allreduce( in, out, count, MPI_UNSIGNED, MPI_BXOR, comm );
2026 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
2027 if (fnderr) fprintf( stderr, 
2028         "(%d) Error for type MPI_UNSIGNED and op MPI_BXOR\n", world_rank );
2029 free( in );
2030 free( out );
2031 free( sol );
2032 }
2033
2034
2035 {
2036 unsigned long *in, *out, *sol;
2037 int  i, fnderr=0;
2038 in = (unsigned long *)malloc( count * sizeof(unsigned long) );
2039 out = (unsigned long *)malloc( count * sizeof(unsigned long) );
2040 sol = (unsigned long *)malloc( count * sizeof(unsigned long) );
2041 for (i=0; i<count; i++) { *(in + i) = 0; *(sol + i) = 0; 
2042         *(out + i) = 0; }
2043 MPI_Allreduce( in, out, count, MPI_UNSIGNED_LONG, MPI_BXOR, comm );
2044 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
2045 if (fnderr) fprintf( stderr, 
2046         "(%d) Error for type MPI_UNSIGNED_LONG and op MPI_BXOR\n", world_rank );
2047 free( in );
2048 free( out );
2049 free( sol );
2050 }
2051
2052
2053 gerr += errcnt;
2054 if (errcnt > 0)
2055         printf( "Found %d errors on %d for MPI_BXOR(0)\n", errcnt, rank );
2056 errcnt = 0;
2057
2058
2059 {
2060 int *in, *out, *sol;
2061 int  i, fnderr=0;
2062 in = (int *)malloc( count * sizeof(int) );
2063 out = (int *)malloc( count * sizeof(int) );
2064 sol = (int *)malloc( count * sizeof(int) );
2065 for (i=0; i<count; i++) { *(in + i) = ~0; *(sol + i) = 0; 
2066         *(out + i) = 0; }
2067 MPI_Allreduce( in, out, count, MPI_INT, MPI_BXOR, comm );
2068 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
2069 if (fnderr) fprintf( stderr, 
2070         "(%d) Error for type MPI_INT and op MPI_BXOR\n", world_rank );
2071 free( in );
2072 free( out );
2073 free( sol );
2074 }
2075
2076
2077 {
2078 long *in, *out, *sol;
2079 int  i, fnderr=0;
2080 in = (long *)malloc( count * sizeof(long) );
2081 out = (long *)malloc( count * sizeof(long) );
2082 sol = (long *)malloc( count * sizeof(long) );
2083 for (i=0; i<count; i++) { *(in + i) = ~0; *(sol + i) = 0; 
2084         *(out + i) = 0; }
2085 MPI_Allreduce( in, out, count, MPI_LONG, MPI_BXOR, comm );
2086 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
2087 if (fnderr) fprintf( stderr, 
2088         "(%d) Error for type MPI_LONG and op MPI_BXOR\n", world_rank );
2089 free( in );
2090 free( out );
2091 free( sol );
2092 }
2093
2094
2095 {
2096 short *in, *out, *sol;
2097 int  i, fnderr=0;
2098 in = (short *)malloc( count * sizeof(short) );
2099 out = (short *)malloc( count * sizeof(short) );
2100 sol = (short *)malloc( count * sizeof(short) );
2101 for (i=0; i<count; i++) { *(in + i) = ~0; *(sol + i) = 0; 
2102         *(out + i) = 0; }
2103 MPI_Allreduce( in, out, count, MPI_SHORT, MPI_BXOR, comm );
2104 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
2105 if (fnderr) fprintf( stderr, 
2106         "(%d) Error for type MPI_SHORT and op MPI_BXOR\n", world_rank );
2107 free( in );
2108 free( out );
2109 free( sol );
2110 }
2111
2112
2113 {
2114 unsigned short *in, *out, *sol;
2115 int  i, fnderr=0;
2116 in = (unsigned short *)malloc( count * sizeof(unsigned short) );
2117 out = (unsigned short *)malloc( count * sizeof(unsigned short) );
2118 sol = (unsigned short *)malloc( count * sizeof(unsigned short) );
2119 for (i=0; i<count; i++) { *(in + i) = ~0; *(sol + i) = 0; 
2120         *(out + i) = 0; }
2121 MPI_Allreduce( in, out, count, MPI_UNSIGNED_SHORT, MPI_BXOR, comm );
2122 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
2123 if (fnderr) fprintf( stderr, 
2124         "(%d) Error for type MPI_UNSIGNED_SHORT and op MPI_BXOR\n", world_rank );
2125 free( in );
2126 free( out );
2127 free( sol );
2128 }
2129
2130
2131 {
2132 unsigned *in, *out, *sol;
2133 int  i, fnderr=0;
2134 in = (unsigned *)malloc( count * sizeof(unsigned) );
2135 out = (unsigned *)malloc( count * sizeof(unsigned) );
2136 sol = (unsigned *)malloc( count * sizeof(unsigned) );
2137 for (i=0; i<count; i++) { *(in + i) = ~0; *(sol + i) = 0; 
2138         *(out + i) = 0; }
2139 MPI_Allreduce( in, out, count, MPI_UNSIGNED, MPI_BXOR, comm );
2140 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
2141 if (fnderr) fprintf( stderr, 
2142         "(%d) Error for type MPI_UNSIGNED and op MPI_BXOR\n", world_rank );
2143 free( in );
2144 free( out );
2145 free( sol );
2146 }
2147
2148
2149 {
2150 unsigned long *in, *out, *sol;
2151 int  i, fnderr=0;
2152 in = (unsigned long *)malloc( count * sizeof(unsigned long) );
2153 out = (unsigned long *)malloc( count * sizeof(unsigned long) );
2154 sol = (unsigned long *)malloc( count * sizeof(unsigned long) );
2155 for (i=0; i<count; i++) { *(in + i) = ~0; *(sol + i) = 0; 
2156         *(out + i) = 0; }
2157 MPI_Allreduce( in, out, count, MPI_UNSIGNED_LONG, MPI_BXOR, comm );
2158 for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}
2159 if (fnderr) fprintf( stderr, 
2160         "(%d) Error for type MPI_UNSIGNED_LONG and op MPI_BXOR\n", world_rank );
2161 free( in );
2162 free( out );
2163 free( sol );
2164 }
2165
2166
2167 gerr += errcnt;
2168 if (errcnt > 0)
2169         printf( "Found %d errors on %d for MPI_BXOR(1-0)\n", errcnt, rank );
2170 errcnt = 0;
2171
2172 /* Test Maxloc */
2173 if (world_rank == 0 && verbose) printf( "Testing MPI_MAXLOC...\n" );
2174
2175 {
2176 struct int_test { int a; int b; } *in, *out, *sol;
2177 int  i,fnderr=0;
2178 in = (struct int_test *)malloc( count * sizeof(struct int_test) );
2179 out = (struct int_test *)malloc( count * sizeof(struct int_test) );
2180 sol = (struct int_test *)malloc( count * sizeof(struct int_test) );
2181 for (i=0; i<count; i++) { (in + i)->a = (rank + i); (in + i)->b = rank;
2182         (sol + i)->a = (size - 1 + i); (sol + i)->b = (size-1);
2183         (out + i)->a = 0; (out + i)->b = -1; }
2184 MPI_Allreduce( in, out, count, MPI_2INT, MPI_MAXLOC, comm );
2185 for (i=0; i<count; i++) { if ((out + i)->a != (sol + i)->a ||
2186                               (out + i)->b != (sol + i)->b) {
2187         errcnt++; fnderr++; 
2188     fprintf( stderr, "(%d) Expected (%d,%d) got (%d,%d)\n", world_rank,
2189         (int)((sol + i)->a),
2190         (sol+i)->b, (int)((out+i)->a), (out+i)->b );
2191 }}
2192 if (fnderr) fprintf( stderr, 
2193         "(%d) Error for type MPI_2INT and op MPI_MAXLOC (%d of %d wrong)\n",
2194                      world_rank, fnderr, count );
2195 free( in );
2196 free( out );
2197 free( sol );
2198 }
2199
2200
2201 {
2202 struct long_test { long a; int b; } *in, *out, *sol;
2203 int  i,fnderr=0;
2204 in = (struct long_test *)malloc( count * sizeof(struct long_test) );
2205 out = (struct long_test *)malloc( count * sizeof(struct long_test) );
2206 sol = (struct long_test *)malloc( count * sizeof(struct long_test) );
2207 for (i=0; i<count; i++) { (in + i)->a = (rank + i); (in + i)->b = rank;
2208         (sol + i)->a = (size - 1 + i); (sol + i)->b = (size-1);
2209         (out + i)->a = 0; (out + i)->b = -1; }
2210 MPI_Allreduce( in, out, count, MPI_LONG_INT, MPI_MAXLOC, comm );
2211 for (i=0; i<count; i++) { if ((out + i)->a != (sol + i)->a ||
2212                               (out + i)->b != (sol + i)->b) {
2213         errcnt++; fnderr++; 
2214     fprintf( stderr, "(%d) Expected (%d,%d) got (%d,%d)\n", world_rank,
2215         (int)((sol + i)->a),
2216         (sol+i)->b, (int)((out+i)->a), (out+i)->b );
2217 }}
2218 if (fnderr) fprintf( stderr, 
2219         "(%d) Error for type MPI_LONG_INT and op MPI_MAXLOC (%d of %d wrong)\n",
2220                      world_rank, fnderr, count );
2221 free( in );
2222 free( out );
2223 free( sol );
2224 }
2225
2226
2227 {
2228 struct short_test { short a; int b; } *in, *out, *sol;
2229 int  i,fnderr=0;
2230 in = (struct short_test *)malloc( count * sizeof(struct short_test) );
2231 out = (struct short_test *)malloc( count * sizeof(struct short_test) );
2232 sol = (struct short_test *)malloc( count * sizeof(struct short_test) );
2233 for (i=0; i<count; i++) { (in + i)->a = (rank + i); (in + i)->b = rank;
2234         (sol + i)->a = (size - 1 + i); (sol + i)->b = (size-1);
2235         (out + i)->a = 0; (out + i)->b = -1; }
2236 MPI_Allreduce( in, out, count, MPI_SHORT_INT, MPI_MAXLOC, comm );
2237 for (i=0; i<count; i++) { if ((out + i)->a != (sol + i)->a ||
2238                               (out + i)->b != (sol + i)->b) {
2239         errcnt++; fnderr++; 
2240     fprintf( stderr, "(%d) Expected (%d,%d) got (%d,%d)\n", world_rank,
2241         (int)((sol + i)->a),
2242         (sol+i)->b, (int)((out+i)->a), (out+i)->b );
2243 }}
2244 if (fnderr) fprintf( stderr, 
2245         "(%d) Error for type MPI_SHORT_INT and op MPI_MAXLOC (%d of %d wrong)\n",
2246                      world_rank, fnderr, count );
2247 free( in );
2248 free( out );
2249 free( sol );
2250 }
2251
2252
2253 {
2254 struct float_test { float a; int b; } *in, *out, *sol;
2255 int  i,fnderr=0;
2256 in = (struct float_test *)malloc( count * sizeof(struct float_test) );
2257 out = (struct float_test *)malloc( count * sizeof(struct float_test) );
2258 sol = (struct float_test *)malloc( count * sizeof(struct float_test) );
2259 for (i=0; i<count; i++) { (in + i)->a = (rank + i); (in + i)->b = rank;
2260         (sol + i)->a = (size - 1 + i); (sol + i)->b = (size-1);
2261         (out + i)->a = 0; (out + i)->b = -1; }
2262 MPI_Allreduce( in, out, count, MPI_FLOAT_INT, MPI_MAXLOC, comm );
2263 for (i=0; i<count; i++) { if ((out + i)->a != (sol + i)->a ||
2264                               (out + i)->b != (sol + i)->b) {
2265         errcnt++; fnderr++; 
2266     fprintf( stderr, "(%d) Expected (%d,%d) got (%d,%d)\n", world_rank,
2267         (int)((sol + i)->a),
2268         (sol+i)->b, (int)((out+i)->a), (out+i)->b );
2269 }}
2270 if (fnderr) fprintf( stderr, 
2271         "(%d) Error for type MPI_FLOAT_INT and op MPI_MAXLOC (%d of %d wrong)\n",
2272                      world_rank, fnderr, count );
2273 free( in );
2274 free( out );
2275 free( sol );
2276 }
2277
2278
2279 {
2280 struct double_test { double a; int b; } *in, *out, *sol;
2281 int  i,fnderr=0;
2282 in = (struct double_test *)malloc( count * sizeof(struct double_test) );
2283 out = (struct double_test *)malloc( count * sizeof(struct double_test) );
2284 sol = (struct double_test *)malloc( count * sizeof(struct double_test) );
2285 for (i=0; i<count; i++) { (in + i)->a = (rank + i); (in + i)->b = rank;
2286         (sol + i)->a = (size - 1 + i); (sol + i)->b = (size-1);
2287         (out + i)->a = 0; (out + i)->b = -1; }
2288 MPI_Allreduce( in, out, count, MPI_DOUBLE_INT, MPI_MAXLOC, comm );
2289 for (i=0; i<count; i++) { if ((out + i)->a != (sol + i)->a ||
2290                               (out + i)->b != (sol + i)->b) {
2291         errcnt++; fnderr++; 
2292     fprintf( stderr, "(%d) Expected (%d,%d) got (%d,%d)\n", world_rank,
2293         (int)((sol + i)->a),
2294         (sol+i)->b, (int)((out+i)->a), (out+i)->b );
2295 }}
2296 if (fnderr) fprintf( stderr, 
2297         "(%d) Error for type MPI_DOUBLE_INT and op MPI_MAXLOC (%d of %d wrong)\n",
2298                      world_rank, fnderr, count );
2299 free( in );
2300 free( out );
2301 free( sol );
2302 }
2303
2304
2305 gerr += errcnt;
2306 if (errcnt > 0)
2307         printf( "Found %d errors on %d for MPI_MAXLOC\n", errcnt, rank );
2308 errcnt = 0;
2309
2310 /* Test minloc */
2311 if (world_rank == 0 && verbose) printf( "Testing MPI_MINLOC...\n" );
2312
2313
2314 {
2315 struct int_test { int a; int b; } *in, *out, *sol;
2316 int  i,fnderr=0;
2317 in = (struct int_test *)malloc( count * sizeof(struct int_test) );
2318 out = (struct int_test *)malloc( count * sizeof(struct int_test) );
2319 sol = (struct int_test *)malloc( count * sizeof(struct int_test) );
2320 for (i=0; i<count; i++) { (in + i)->a = (rank + i); (in + i)->b = rank;
2321         (sol + i)->a = i; (sol + i)->b = 0;
2322         (out + i)->a = 0; (out + i)->b = -1; }
2323 MPI_Allreduce( in, out, count, MPI_2INT, MPI_MINLOC, comm );
2324 for (i=0; i<count; i++) { if ((out + i)->a != (sol + i)->a ||
2325                               (out + i)->b != (sol + i)->b) {
2326         errcnt++; fnderr++; 
2327     fprintf( stderr, "(%d) Expected (%d,%d) got (%d,%d)\n", world_rank,
2328         (int)((sol + i)->a),
2329         (sol+i)->b, (int)((out+i)->a), (out+i)->b );
2330 }}
2331 if (fnderr) fprintf( stderr, 
2332         "(%d) Error for type MPI_2INT and op MPI_MINLOC (%d of %d wrong)\n",
2333                      world_rank, fnderr, count );
2334 free( in );
2335 free( out );
2336 free( sol );
2337 }
2338
2339
2340 {
2341 struct long_test { long a; int b; } *in, *out, *sol;
2342 int  i,fnderr=0;
2343 in = (struct long_test *)malloc( count * sizeof(struct long_test) );
2344 out = (struct long_test *)malloc( count * sizeof(struct long_test) );
2345 sol = (struct long_test *)malloc( count * sizeof(struct long_test) );
2346 for (i=0; i<count; i++) { (in + i)->a = (rank + i); (in + i)->b = rank;
2347         (sol + i)->a = i; (sol + i)->b = 0;
2348         (out + i)->a = 0; (out + i)->b = -1; }
2349 MPI_Allreduce( in, out, count, MPI_LONG_INT, MPI_MINLOC, comm );
2350 for (i=0; i<count; i++) { if ((out + i)->a != (sol + i)->a ||
2351                               (out + i)->b != (sol + i)->b) {
2352         errcnt++; fnderr++; 
2353     fprintf( stderr, "(%d) Expected (%d,%d) got (%d,%d)\n", world_rank,
2354         (int)((sol + i)->a),
2355         (sol+i)->b, (int)((out+i)->a), (out+i)->b );
2356 }}
2357 if (fnderr) fprintf( stderr, 
2358         "(%d) Error for type MPI_LONG_INT and op MPI_MINLOC (%d of %d wrong)\n",
2359                      world_rank, fnderr, count );
2360 free( in );
2361 free( out );
2362 free( sol );
2363 }
2364
2365
2366 {
2367 struct short_test { short a; int b; } *in, *out, *sol;
2368 int  i,fnderr=0;
2369 in = (struct short_test *)malloc( count * sizeof(struct short_test) );
2370 out = (struct short_test *)malloc( count * sizeof(struct short_test) );
2371 sol = (struct short_test *)malloc( count * sizeof(struct short_test) );
2372 for (i=0; i<count; i++) { (in + i)->a = (rank + i); (in + i)->b = rank;
2373         (sol + i)->a = i; (sol + i)->b = 0;
2374         (out + i)->a = 0; (out + i)->b = -1; }
2375 MPI_Allreduce( in, out, count, MPI_SHORT_INT, MPI_MINLOC, comm );
2376 for (i=0; i<count; i++) { if ((out + i)->a != (sol + i)->a ||
2377                               (out + i)->b != (sol + i)->b) {
2378         errcnt++; fnderr++; 
2379     fprintf( stderr, "(%d) Expected (%d,%d) got (%d,%d)\n", world_rank,
2380         (int)((sol + i)->a),
2381         (sol+i)->b, (int)((out+i)->a), (out+i)->b );
2382 }}
2383 if (fnderr) fprintf( stderr, 
2384         "(%d) Error for type MPI_SHORT_INT and op MPI_MINLOC (%d of %d wrong)\n",
2385                      world_rank, fnderr, count );
2386 free( in );
2387 free( out );
2388 free( sol );
2389 }
2390
2391
2392 {
2393 struct float_test { float a; int b; } *in, *out, *sol;
2394 int  i,fnderr=0;
2395 in = (struct float_test *)malloc( count * sizeof(struct float_test) );
2396 out = (struct float_test *)malloc( count * sizeof(struct float_test) );
2397 sol = (struct float_test *)malloc( count * sizeof(struct float_test) );
2398 for (i=0; i<count; i++) { (in + i)->a = (rank + i); (in + i)->b = rank;
2399         (sol + i)->a = i; (sol + i)->b = 0;
2400         (out + i)->a = 0; (out + i)->b = -1; }
2401 MPI_Allreduce( in, out, count, MPI_FLOAT_INT, MPI_MINLOC, comm );
2402 for (i=0; i<count; i++) { if ((out + i)->a != (sol + i)->a ||
2403                               (out + i)->b != (sol + i)->b) {
2404         errcnt++; fnderr++; 
2405     fprintf( stderr, "(%d) Expected (%d,%d) got (%d,%d)\n", world_rank,
2406         (int)((sol + i)->a),
2407         (sol+i)->b, (int)((out+i)->a), (out+i)->b );
2408 }}
2409 if (fnderr) fprintf( stderr, 
2410         "(%d) Error for type MPI_FLOAT_INT and op MPI_MINLOC (%d of %d wrong)\n",
2411                      world_rank, fnderr, count );
2412 free( in );
2413 free( out );
2414 free( sol );
2415 }
2416
2417
2418 {
2419 struct double_test { double a; int b; } *in, *out, *sol;
2420 int  i,fnderr=0;
2421 in = (struct double_test *)malloc( count * sizeof(struct double_test) );
2422 out = (struct double_test *)malloc( count * sizeof(struct double_test) );
2423 sol = (struct double_test *)malloc( count * sizeof(struct double_test) );
2424 for (i=0; i<count; i++) { (in + i)->a = (rank + i); (in + i)->b = rank;
2425         (sol + i)->a = i; (sol + i)->b = 0;
2426         (out + i)->a = 0; (out + i)->b = -1; }
2427 MPI_Allreduce( in, out, count, MPI_DOUBLE_INT, MPI_MINLOC, comm );
2428 for (i=0; i<count; i++) { if ((out + i)->a != (sol + i)->a ||
2429                               (out + i)->b != (sol + i)->b) {
2430         errcnt++; fnderr++; 
2431     fprintf( stderr, "(%d) Expected (%d,%d) got (%d,%d)\n", world_rank,
2432         (int)((sol + i)->a),
2433         (sol+i)->b, (int)((out+i)->a), (out+i)->b );
2434 }}
2435 if (fnderr) fprintf( stderr, 
2436         "(%d) Error for type MPI_DOUBLE_INT and op MPI_MINLOC (%d of %d wrong)\n",
2437                      world_rank, fnderr, count );
2438 free( in );
2439 free( out );
2440 free( sol );
2441 }
2442
2443
2444 gerr += errcnt;
2445 if (errcnt > 0)
2446         printf( "Found %d errors on %d for MPI_MINLOC\n", errcnt, rank );
2447 errcnt = 0;
2448
2449 }
2450 if (gerr > 0) {
2451         MPI_Comm_rank( MPI_COMM_WORLD, &rank );
2452         printf( "Found %d errors overall on %d\n", gerr, rank );
2453         }
2454 MPI_Allreduce( &gerr, &toterr, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
2455  if (world_rank == 0) {
2456      if (toterr == 0) {
2457          printf( " No Errors\n" );
2458      }
2459      else {
2460          printf (" Found %d errors\n", toterr );
2461      }
2462  }
2463 FreeComms( comms, ncomm );
2464 MPI_Finalize( );
2465 return 0;
2466 }