Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge pull request #181 from bcamus/master
[simgrid.git] / teshsuite / smpi / isp / umpire / collective-exhaustive-no-error.c
1 /* -*- Mode: C; -*- */
2 /* Creator: Bronis R. de Supinski (bronis@llnl.gov) Thu Oct 17 2002 */
3 /* collective-exhaustive-no-error.c -- do some many collective operations */
4
5 #ifndef lint
6 static char *rcsid =
7   "$Header: /usr/gapps/asde/cvs-vault/umpire/tests/collective-exhaustive-no-error.c,v 1.1 2002/10/24 17:04:54 bronis Exp $";
8 #endif
9
10 #include <stdio.h>
11 #include <string.h>
12 #include <assert.h>
13 #include "mpi.h"
14
15
16 #define RUN_BARRIER
17 #define RUN_BCAST
18 #define RUN_GATHER
19 #define RUN_GATHERV
20 #define RUN_SCATTER
21 #define RUN_SCATTERV
22 #define RUN_ALLGATHER
23 #define RUN_ALLGATHERV
24 #define RUN_ALLTOALL
25 #define RUN_ALLTOALLV
26 #define RUN_REDUCE
27 #define RUN_ALLREDUCE
28 #define RUN_REDUCE_SCATTER
29 #define RUN_SCAN
30
31
32 #define RUN_MAX
33 #define RUN_MIN
34 #define RUN_SUM
35 #define RUN_PROD
36 #define RUN_LAND
37 #define RUN_BAND
38 #define RUN_LOR
39 #define RUN_BOR
40 #define RUN_LXOR
41 #define RUN_BXOR
42 #define RUN_MAXLOC
43 #define RUN_MINLOC
44 #define RUN_USEROP
45
46
47 #define buf_size 128
48 #define OP_COUNT 10
49
50
51 #ifdef RUN_USEROP
52 typedef struct {
53   double real, imag;
54 } complex_t;
55
56 void
57 complex_prod (void *inp, void *inoutp, int *len, MPI_Datatype *dptr)
58 {
59   int i;
60   complex_t c;
61   complex_t *in = (complex_t *) inp;
62   complex_t *inout = (complex_t *) inoutp;
63
64   for (i = 0; i < *len; i++) {
65     c.real = inout->real * in->real - inout->imag * in->imag;
66     c.imag = inout->real * in->imag + inout->imag * in->real;
67     *inout = c;
68     in++;
69     inout++;
70   }
71
72   return;
73 }
74 #endif
75
76
77 int
78 main (int argc, char **argv)
79 {
80   int i, nprocs = -1;
81   int rank = -1;
82   MPI_Comm comm = MPI_COMM_WORLD;
83   char processor_name[128];
84   int namelen = 128;
85   int *buf0, *buf1, *displs, *counts, *rcounts, *alltoallvcounts;
86 #ifdef RUN_USEROP
87   MPI_Op user_op;
88   complex_t *a, *answer;
89   MPI_Datatype ctype;
90 #endif
91
92   /* init */
93   MPI_Init (&argc, &argv);
94   MPI_Comm_size (comm, &nprocs);
95   MPI_Comm_rank (comm, &rank);
96   MPI_Get_processor_name (processor_name, &namelen);
97   printf ("(%d) is alive on %s\n", rank, processor_name);
98   fflush (stdout);
99
100   buf0 = (int *) malloc (buf_size * nprocs * sizeof(int));
101   assert (buf0);
102   for (i = 0; i < buf_size * nprocs; i++)
103     buf0[i] = rank;
104
105 #ifdef RUN_ALLTOALLV
106   alltoallvcounts = (int *) malloc (nprocs * sizeof(int));
107   assert (alltoallvcounts);
108   for (i = 0; i < nprocs; i++)
109     if ((i + rank) < buf_size)
110       alltoallvcounts[i] = i + rank;
111     else
112       alltoallvcounts[i] = buf_size;
113 #endif
114
115 #ifdef RUN_USEROP
116   a = (complex_t *) malloc (buf_size * nprocs * sizeof(complex_t));
117   for (i = 0; i < buf_size * nprocs; i++) {
118     a[i].real = ((double) rank)/((double) nprocs);
119     a[i].imag = ((double) (-rank))/((double) nprocs);
120   }
121
122   MPI_Type_contiguous (2, MPI_DOUBLE, &ctype);
123   MPI_Type_commit (&ctype);
124
125   MPI_Op_create (complex_prod, 1 /* TRUE */, &user_op);
126 #endif
127
128   if (rank == 0) {
129     buf1 = (int *) malloc (buf_size * nprocs * sizeof(int));
130     assert (buf1);
131     for (i = 0; i < buf_size * nprocs; i++)
132       buf1[i] = i;
133
134     displs = (int *) malloc (nprocs * sizeof(int));
135     counts = (int *) malloc (nprocs * sizeof(int));
136     rcounts = (int *) malloc (nprocs * sizeof(int));
137     assert (displs && counts && rcounts);
138     for (i = 0; i < nprocs; i++) {
139       displs[i] = i * buf_size;
140       if (i < buf_size)
141         rcounts[i] = counts[i] = i;
142       else
143         rcounts[i] = counts[i] = buf_size;
144     }
145
146 #ifdef RUN_USEROP
147     answer = (complex_t *) malloc (buf_size * nprocs * sizeof(complex_t));
148 #endif
149   }
150
151 #ifdef RUN_BARRIER
152   for (i = 0; i < OP_COUNT; i++)
153     MPI_Barrier (comm);
154 #endif
155
156 #ifdef RUN_BCAST
157   for (i = 0; i < OP_COUNT; i++)
158     MPI_Bcast (buf0, buf_size, MPI_INT, 0, comm);
159 #endif
160
161 #ifdef RUN_GATHER
162   for (i = 0; i < OP_COUNT; i++)
163     MPI_Gather (&buf0[rank*buf_size], buf_size,
164                 MPI_INT, buf1, buf_size, MPI_INT, 0, comm);
165 #endif
166
167 #ifdef RUN_SCATTER
168   for (i = 0; i < OP_COUNT; i++)
169     MPI_Scatter (buf1, buf_size, MPI_INT, buf0, buf_size, MPI_INT, 0, comm);
170 #endif
171
172 #ifdef RUN_GATHERV
173   for (i = 0; i < OP_COUNT; i++)
174     MPI_Gatherv (&buf0[rank*buf_size],
175                  (rank < buf_size) ? rank : buf_size,
176                  MPI_INT, buf1, rcounts, displs, MPI_INT, 0, comm);
177 #endif
178
179 #ifdef RUN_SCATTERV
180   for (i = 0; i < OP_COUNT; i++)
181     MPI_Scatterv (buf1, counts, displs, MPI_INT, buf0,
182                   (rank < buf_size) ? rank : buf_size, MPI_INT, 0, comm);
183 #endif
184
185 #ifdef RUN_REDUCE
186 #ifdef RUN_MAX
187   for (i = 0; i < OP_COUNT; i++)
188     MPI_Reduce (buf0, buf1, buf_size, MPI_INT, MPI_MAX, 0, comm);
189 #endif
190
191 #ifdef RUN_MIN
192   for (i = 0; i < OP_COUNT; i++)
193     MPI_Reduce (buf0, buf1, buf_size, MPI_INT, MPI_MIN, 0, comm);
194 #endif
195
196 #ifdef RUN_SUM
197   for (i = 0; i < OP_COUNT; i++)
198     MPI_Reduce (buf0, buf1, buf_size, MPI_INT, MPI_SUM, 0, comm);
199 #endif
200
201 #ifdef RUN_PROD
202   for (i = 0; i < OP_COUNT; i++)
203     MPI_Reduce (buf0, buf1, buf_size, MPI_INT, MPI_PROD, 0, comm);
204 #endif
205
206 #ifdef RUN_LAND
207   for (i = 0; i < OP_COUNT; i++)
208     MPI_Reduce (buf0, buf1, buf_size, MPI_INT, MPI_LAND, 0, comm);
209 #endif
210
211 #ifdef RUN_BAND
212   for (i = 0; i < OP_COUNT; i++)
213     MPI_Reduce (buf0, buf1, buf_size, MPI_INT, MPI_BAND, 0, comm);
214 #endif
215
216 #ifdef RUN_LOR
217   for (i = 0; i < OP_COUNT; i++)
218     MPI_Reduce (buf0, buf1, buf_size, MPI_INT, MPI_LOR, 0, comm);
219 #endif
220
221 #ifdef RUN_BOR
222   for (i = 0; i < OP_COUNT; i++)
223     MPI_Reduce (buf0, buf1, buf_size, MPI_INT, MPI_BOR, 0, comm);
224 #endif
225
226 #ifdef RUN_LXOR
227   for (i = 0; i < OP_COUNT; i++)
228     MPI_Reduce (buf0, buf1, buf_size, MPI_INT, MPI_LXOR, 0, comm);
229 #endif
230
231 #ifdef RUN_BXOR
232   for (i = 0; i < OP_COUNT; i++)
233     MPI_Reduce (buf0, buf1, buf_size, MPI_INT, MPI_BXOR, 0, comm);
234 #endif
235
236 #ifdef RUN_MAXLOC
237   if (nprocs > 1)
238     for (i = 0; i < OP_COUNT; i++)
239       MPI_Reduce (buf0, buf1, buf_size, MPI_2INT, MPI_MAXLOC, 0, comm);
240   else
241     fprintf (stderr, "Not enough tasks for MAXLOC test\n");
242 #endif
243
244 #ifdef RUN_MINLOC
245   if (nprocs > 1)
246     for (i = 0; i < OP_COUNT; i++)
247       MPI_Reduce (buf0, buf1, buf_size, MPI_2INT, MPI_MINLOC, 0, comm);
248   else
249     fprintf (stderr, "Not enough tasks for MINLOC test\n");
250 #endif
251
252 #ifdef RUN_USEROP
253   for (i = 0; i < OP_COUNT; i++)
254     MPI_Reduce (a, answer, buf_size, ctype, user_op, 0, comm);
255 #endif
256 #endif
257
258   if (rank != 0) {
259     buf1 = (int *) malloc (buf_size * nprocs * sizeof(int));
260     assert (buf1);
261     for (i = 0; i < buf_size * nprocs; i++)
262       buf1[i] = i;
263
264     displs = (int *) malloc (nprocs * sizeof(int));
265     counts = (int *) malloc (nprocs * sizeof(int));
266     rcounts = (int *) malloc (nprocs * sizeof(int));
267     assert (displs && counts && rcounts);
268     for (i = 0; i < nprocs; i++) {
269       displs[i] = i * buf_size;
270       if (i < buf_size)
271         rcounts[i] = counts[i] = i;
272       else
273         rcounts[i] = counts[i] = buf_size;
274     }
275
276 #ifdef RUN_USEROP
277     answer = (complex_t *) malloc (buf_size * nprocs * sizeof(complex_t));
278 #endif
279   }
280
281 #ifdef RUN_ALLGATHER
282   for (i = 0; i < OP_COUNT; i++)
283     MPI_Allgather (buf0, buf_size, MPI_INT, buf1, buf_size, MPI_INT, comm);
284 #endif
285
286 #ifdef RUN_ALLTOALL
287   for (i = 0; i < OP_COUNT; i++)
288     MPI_Alltoall (buf1, buf_size, MPI_INT, buf0, buf_size, MPI_INT, comm);
289 #endif
290
291 #ifdef RUN_ALLGATHERV
292   for (i = 0; i < OP_COUNT; i++)
293     MPI_Allgatherv (buf0,
294                     (rank < buf_size) ? rank : buf_size,
295                     MPI_INT, buf1, rcounts, displs, MPI_INT, comm);
296 #endif
297
298 #ifdef RUN_ALLTOALLV
299   for (i = 0; i < OP_COUNT; i++)
300     MPI_Alltoallv (buf1, alltoallvcounts, displs, MPI_INT,
301                    buf0, alltoallvcounts, displs, MPI_INT, comm);
302 #endif
303
304 #ifdef RUN_ALLREDUCE
305 #ifdef RUN_MAX
306   for (i = 0; i < OP_COUNT; i++)
307     MPI_Allreduce (buf0, buf1, buf_size, MPI_INT, MPI_MAX, comm);
308 #endif
309
310 #ifdef RUN_MIN
311   for (i = 0; i < OP_COUNT; i++)
312     MPI_Allreduce (buf0, buf1, buf_size, MPI_INT, MPI_MIN, comm);
313 #endif
314
315 #ifdef RUN_SUM
316   for (i = 0; i < OP_COUNT; i++)
317     MPI_Allreduce (buf0, buf1, buf_size, MPI_INT, MPI_SUM, comm);
318 #endif
319
320 #ifdef RUN_PROD
321   for (i = 0; i < OP_COUNT; i++)
322     MPI_Allreduce (buf0, buf1, buf_size, MPI_INT, MPI_PROD, comm);
323 #endif
324
325 #ifdef RUN_LAND
326   for (i = 0; i < OP_COUNT; i++)
327     MPI_Allreduce (buf0, buf1, buf_size, MPI_INT, MPI_LAND, comm);
328 #endif
329
330 #ifdef RUN_BAND
331   for (i = 0; i < OP_COUNT; i++)
332     MPI_Allreduce (buf0, buf1, buf_size, MPI_INT, MPI_BAND, comm);
333 #endif
334
335 #ifdef RUN_LOR
336   for (i = 0; i < OP_COUNT; i++)
337     MPI_Allreduce (buf0, buf1, buf_size, MPI_INT, MPI_LOR, comm);
338 #endif
339
340 #ifdef RUN_BOR
341   for (i = 0; i < OP_COUNT; i++)
342     MPI_Allreduce (buf0, buf1, buf_size, MPI_INT, MPI_BOR, comm);
343 #endif
344
345 #ifdef RUN_LXOR
346   for (i = 0; i < OP_COUNT; i++)
347     MPI_Allreduce (buf0, buf1, buf_size, MPI_INT, MPI_LXOR, comm);
348 #endif
349
350 #ifdef RUN_BXOR
351   for (i = 0; i < OP_COUNT; i++)
352     MPI_Allreduce (buf0, buf1, buf_size, MPI_INT, MPI_BXOR, comm);
353 #endif
354
355 #ifdef RUN_MAXLOC
356   if (nprocs > 1)
357     for (i = 0; i < OP_COUNT; i++)
358       MPI_Allreduce (buf0, buf1, buf_size, MPI_2INT, MPI_MAXLOC, comm);
359   else
360     fprintf (stderr, "Not enough tasks for MAXLOC test\n");
361 #endif
362
363 #ifdef RUN_MINLOC
364   if (nprocs > 1)
365     for (i = 0; i < OP_COUNT; i++)
366       MPI_Allreduce (buf0, buf1, buf_size, MPI_2INT, MPI_MINLOC, comm);
367   else
368     fprintf (stderr, "Not enough tasks for MINLOC test\n");
369 #endif
370
371 #ifdef RUN_USEROP
372   for (i = 0; i < OP_COUNT; i++)
373     MPI_Allreduce (a, answer, buf_size, ctype, user_op, comm);
374 #endif
375 #endif
376
377 #ifdef RUN_REDUCE_SCATTER
378 #ifdef RUN_MAX
379   for (i = 0; i < OP_COUNT; i++)
380     MPI_Reduce_scatter (buf0, buf1, rcounts, MPI_INT, MPI_MAX, comm);
381 #endif
382
383 #ifdef RUN_MIN
384   for (i = 0; i < OP_COUNT; i++)
385     MPI_Reduce_scatter (buf0, buf1, rcounts, MPI_INT, MPI_MIN, comm);
386 #endif
387
388 #ifdef RUN_SUM
389   for (i = 0; i < OP_COUNT; i++)
390     MPI_Reduce_scatter (buf0, buf1, rcounts, MPI_INT, MPI_SUM, comm);
391 #endif
392
393 #ifdef RUN_PROD
394   for (i = 0; i < OP_COUNT; i++)
395     MPI_Reduce_scatter (buf0, buf1, rcounts, MPI_INT, MPI_PROD, comm);
396 #endif
397
398 #ifdef RUN_LAND
399   for (i = 0; i < OP_COUNT; i++)
400     MPI_Reduce_scatter (buf0, buf1, rcounts, MPI_INT, MPI_LAND, comm);
401 #endif
402
403 #ifdef RUN_BAND
404   for (i = 0; i < OP_COUNT; i++)
405     MPI_Reduce_scatter (buf0, buf1, rcounts, MPI_INT, MPI_BAND, comm);
406 #endif
407
408 #ifdef RUN_LOR
409   for (i = 0; i < OP_COUNT; i++)
410     MPI_Reduce_scatter (buf0, buf1, rcounts, MPI_INT, MPI_LOR, comm);
411 #endif
412
413 #ifdef RUN_BOR
414   for (i = 0; i < OP_COUNT; i++)
415     MPI_Reduce_scatter (buf0, buf1, rcounts, MPI_INT, MPI_BOR, comm);
416 #endif
417
418 #ifdef RUN_LXOR
419   for (i = 0; i < OP_COUNT; i++)
420     MPI_Reduce_scatter (buf0, buf1, rcounts, MPI_INT, MPI_LXOR, comm);
421 #endif
422
423 #ifdef RUN_BXOR
424   for (i = 0; i < OP_COUNT; i++)
425     MPI_Reduce_scatter (buf0, buf1, rcounts, MPI_INT, MPI_BXOR, comm);
426 #endif
427
428 #ifdef RUN_MAXLOC
429   if (nprocs > 1)
430     for (i = 0; i < OP_COUNT; i++)
431       MPI_Reduce_scatter (buf0, buf1, rcounts, MPI_2INT, MPI_MAXLOC, comm);
432   else
433     fprintf (stderr, "Not enough tasks for MAXLOC test\n");
434 #endif
435
436 #ifdef RUN_MINLOC
437   if (nprocs > 1)
438     for (i = 0; i < OP_COUNT; i++)
439       MPI_Reduce_scatter (buf0, buf1, rcounts, MPI_2INT, MPI_MINLOC, comm);
440   else
441     fprintf (stderr, "Not enough tasks for MINLOC test\n");
442 #endif
443
444 #ifdef RUN_USEROP
445   for (i = 0; i < OP_COUNT; i++)
446     MPI_Reduce_scatter (a, answer, rcounts, ctype, user_op, comm);
447 #endif
448 #endif
449
450 #ifdef RUN_SCAN
451 #ifdef RUN_MAX
452   for (i = 0; i < OP_COUNT; i++)
453     MPI_Scan (buf0, buf1, buf_size, MPI_INT, MPI_MAX, comm);
454 #endif
455
456 #ifdef RUN_MIN
457   for (i = 0; i < OP_COUNT; i++)
458     MPI_Scan (buf0, buf1, buf_size, MPI_INT, MPI_MIN, comm);
459 #endif
460
461 #ifdef RUN_SUM
462   for (i = 0; i < OP_COUNT; i++)
463     MPI_Scan (buf0, buf1, buf_size, MPI_INT, MPI_SUM, comm);
464 #endif
465
466 #ifdef RUN_PROD
467   for (i = 0; i < OP_COUNT; i++)
468     MPI_Scan (buf0, buf1, buf_size, MPI_INT, MPI_PROD, comm);
469 #endif
470
471 #ifdef RUN_LAND
472   for (i = 0; i < OP_COUNT; i++)
473     MPI_Scan (buf0, buf1, buf_size, MPI_INT, MPI_LAND, comm);
474 #endif
475
476 #ifdef RUN_BAND
477   for (i = 0; i < OP_COUNT; i++)
478     MPI_Scan (buf0, buf1, buf_size, MPI_INT, MPI_BAND, comm);
479 #endif
480
481 #ifdef RUN_LOR
482   for (i = 0; i < OP_COUNT; i++)
483     MPI_Scan (buf0, buf1, buf_size, MPI_INT, MPI_LOR, comm);
484 #endif
485
486 #ifdef RUN_BOR
487   for (i = 0; i < OP_COUNT; i++)
488     MPI_Scan (buf0, buf1, buf_size, MPI_INT, MPI_BOR, comm);
489 #endif
490
491 #ifdef RUN_LXOR
492   for (i = 0; i < OP_COUNT; i++)
493     MPI_Scan (buf0, buf1, buf_size, MPI_INT, MPI_LXOR, comm);
494 #endif
495
496 #ifdef RUN_BXOR
497   for (i = 0; i < OP_COUNT; i++)
498     MPI_Scan (buf0, buf1, buf_size, MPI_INT, MPI_BXOR, comm);
499 #endif
500
501 #ifdef RUN_MAXLOC
502   if (nprocs > 1)
503     for (i = 0; i < OP_COUNT; i++)
504       MPI_Scan (buf0, buf1, buf_size, MPI_2INT, MPI_MAXLOC, comm);
505   else
506     fprintf (stderr, "Not enough tasks for MAXLOC test\n");
507 #endif
508
509 #ifdef RUN_MINLOC
510   if (nprocs > 1)
511     for (i = 0; i < OP_COUNT; i++)
512       MPI_Scan (buf0, buf1, buf_size, MPI_2INT, MPI_MINLOC, comm);
513   else
514     fprintf (stderr, "Not enough tasks for MINLOC test\n");
515 #endif
516
517 #ifdef RUN_USEROP
518   for (i = 0; i < OP_COUNT; i++)
519     MPI_Scan (a, answer, buf_size, ctype, user_op, comm);
520 #endif
521 #endif
522
523 #ifdef RUN_BARRIER
524   MPI_Barrier (comm);
525 #endif
526
527 #ifdef RUN_USEROP
528   free (a);
529   free (answer);
530   MPI_Op_free (&user_op);
531   MPI_Type_free (&ctype);
532 #endif
533
534 #ifdef RUN_ALLTOALLV
535   free (alltoallvcounts);
536 #endif
537
538   free (buf0);
539   free (buf1);
540   free (displs);
541   free (counts);
542   free (rcounts);
543
544   MPI_Finalize ();
545   printf ("(%d) Finished normally\n", rank);
546
547   return 0;
548 }
549
550 /* EOF */