Logo AND Algorithmique Numérique Distribuée

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