File: opbor.c

package info (click to toggle)
mpich 4.3.0%2Breally4.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 419,120 kB
  • sloc: ansic: 1,215,557; cpp: 74,755; javascript: 40,763; f90: 20,649; sh: 18,463; xml: 14,418; python: 14,397; perl: 13,772; makefile: 9,279; fortran: 8,063; java: 4,553; asm: 324; ruby: 176; lisp: 19; php: 8; sed: 4
file content (389 lines) | stat: -rw-r--r-- 11,538 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
/*
 * Copyright (C) by Argonne National Laboratory
 *     See COPYRIGHT in top-level directory
 */

#include "mpi.h"
#include "mpitestconf.h"
#include <stdio.h>
#include "mpitest.h"

/*
static char MTEST_Descrip[] = "Test MPI_BOR operations on optional datatypes dupported by MPICH";
*/

/*
 * This test looks at the handling of logical and for types that are not
 * integers or are not required integers (e.g., long long).  MPICH allows
 * these as well.  A strict MPI test should not include this test.
 */
int main(int argc, char *argv[])
{
    int errs = 0;
    int rc;
    int rank, size;
    MPI_Comm comm;
    char cinbuf[3], coutbuf[3];
    signed char scinbuf[3], scoutbuf[3];
    unsigned char ucinbuf[3], ucoutbuf[3];
    short sinbuf[3], soutbuf[3];
    unsigned short usinbuf[3], usoutbuf[3];
    long linbuf[3], loutbuf[3];
    unsigned long ulinbuf[3], uloutbuf[3];
    unsigned uinbuf[3], uoutbuf[3];
    int iinbuf[3], ioutbuf[3];


    MTest_Init(&argc, &argv);

    comm = MPI_COMM_WORLD;
    /* Set errors return so that we can provide better information
     * should a routine reject one of the operand/datatype pairs */
    MPI_Comm_set_errhandler(comm, MPI_ERRORS_RETURN);

    MPI_Comm_rank(comm, &rank);
    MPI_Comm_size(comm, &size);

#ifndef USE_STRICT_MPI
    /* char */
    MTestPrintfMsg(10, "Reduce of MPI_CHAR\n");
    cinbuf[0] = 0xff;
    cinbuf[1] = 0;
    cinbuf[2] = (rank > 0) ? 0x3c : 0xc3;

    coutbuf[0] = 0;
    coutbuf[1] = 1;
    coutbuf[2] = 1;
    rc = MPI_Reduce(cinbuf, coutbuf, 3, MPI_CHAR, MPI_BOR, 0, comm);
    if (rc) {
        MTestPrintErrorMsg("MPI_BOR and MPI_CHAR", rc);
        errs++;
    } else {
        if (rank == 0) {
            if (coutbuf[0] != (char) 0xff) {
                errs++;
                fprintf(stderr, "char BOR(1) test failed\n");
            }
            if (coutbuf[1]) {
                errs++;
                fprintf(stderr, "char BOR(0) test failed\n");
            }
            if (coutbuf[2] != (char) 0xff && size > 1) {
                errs++;
                fprintf(stderr, "char BOR(>) test failed\n");
            }
        }
    }
#endif /* USE_STRICT_MPI */

    /* signed char */
    MTestPrintfMsg(10, "Reduce of MPI_SIGNED_CHAR\n");
    scinbuf[0] = 0xff;
    scinbuf[1] = 0;
    scinbuf[2] = (rank > 0) ? 0x3c : 0xc3;

    scoutbuf[0] = 0;
    scoutbuf[1] = 1;
    scoutbuf[2] = 1;
    rc = MPI_Reduce(scinbuf, scoutbuf, 3, MPI_SIGNED_CHAR, MPI_BOR, 0, comm);
    if (rc) {
        MTestPrintErrorMsg("MPI_BOR and MPI_SIGNED_CHAR", rc);
        errs++;
    } else {
        if (rank == 0) {
            if (scoutbuf[0] != (signed char) 0xff) {
                errs++;
                fprintf(stderr, "signed char BOR(1) test failed\n");
            }
            if (scoutbuf[1]) {
                errs++;
                fprintf(stderr, "signed char BOR(0) test failed\n");
            }
            if (scoutbuf[2] != (signed char) 0xff && size > 1) {
                errs++;
                fprintf(stderr, "signed char BOR(>) test failed\n");
            }
        }
    }

    /* unsigned char */
    MTestPrintfMsg(10, "Reduce of MPI_UNSIGNED_CHAR\n");
    ucinbuf[0] = 0xff;
    ucinbuf[1] = 0;
    ucinbuf[2] = (rank > 0) ? 0x3c : 0xc3;

    ucoutbuf[0] = 0;
    ucoutbuf[1] = 1;
    ucoutbuf[2] = 1;
    rc = MPI_Reduce(ucinbuf, ucoutbuf, 3, MPI_UNSIGNED_CHAR, MPI_BOR, 0, comm);
    if (rc) {
        MTestPrintErrorMsg("MPI_BOR and MPI_UNSIGNED_CHAR", rc);
        errs++;
    } else {
        if (rank == 0) {
            if (ucoutbuf[0] != 0xff) {
                errs++;
                fprintf(stderr, "unsigned char BOR(1) test failed\n");
            }
            if (ucoutbuf[1]) {
                errs++;
                fprintf(stderr, "unsigned char BOR(0) test failed\n");
            }
            if (ucoutbuf[2] != 0xff && size > 1) {
                errs++;
                fprintf(stderr, "unsigned char BOR(>) test failed\n");
            }
        }
    }

    /* bytes */
    MTestPrintfMsg(10, "Reduce of MPI_BYTE\n");
    cinbuf[0] = 0xff;
    cinbuf[1] = 0;
    cinbuf[2] = (rank > 0) ? 0x3c : 0xc3;

    coutbuf[0] = 0;
    coutbuf[1] = 1;
    coutbuf[2] = 1;
    rc = MPI_Reduce(cinbuf, coutbuf, 3, MPI_BYTE, MPI_BOR, 0, comm);
    if (rc) {
        MTestPrintErrorMsg("MPI_BOR and MPI_BYTE", rc);
        errs++;
    } else {
        if (rank == 0) {
            if (coutbuf[0] != (char) 0xff) {
                errs++;
                fprintf(stderr, "byte BOR(1) test failed\n");
            }
            if (coutbuf[1]) {
                errs++;
                fprintf(stderr, "byte BOR(0) test failed\n");
            }
            if (coutbuf[2] != (char) 0xff && size > 1) {
                errs++;
                fprintf(stderr, "byte BOR(>) test failed\n");
            }
        }
    }

    /* short */
    MTestPrintfMsg(10, "Reduce of MPI_SHORT\n");
    sinbuf[0] = 0xffff;
    sinbuf[1] = 0;
    sinbuf[2] = (rank > 0) ? 0x3c3c : 0xc3c3;

    soutbuf[0] = 0;
    soutbuf[1] = 1;
    soutbuf[2] = 1;
    rc = MPI_Reduce(sinbuf, soutbuf, 3, MPI_SHORT, MPI_BOR, 0, comm);
    if (rc) {
        MTestPrintErrorMsg("MPI_BOR and MPI_SHORT", rc);
        errs++;
    } else {
        if (rank == 0) {
            if (soutbuf[0] != (short) 0xffff) {
                errs++;
                fprintf(stderr, "short BOR(1) test failed\n");
            }
            if (soutbuf[1]) {
                errs++;
                fprintf(stderr, "short BOR(0) test failed\n");
            }
            if (soutbuf[2] != (short) 0xffff && size > 1) {
                errs++;
                fprintf(stderr, "short BOR(>) test failed\n");
            }
        }
    }

    /* unsigned short */
    MTestPrintfMsg(10, "Reduce of MPI_UNSIGNED_SHORT\n");
    usinbuf[0] = 0xffff;
    usinbuf[1] = 0;
    usinbuf[2] = (rank > 0) ? 0x3c3c : 0xc3c3;

    usoutbuf[0] = 0;
    usoutbuf[1] = 1;
    usoutbuf[2] = 1;
    rc = MPI_Reduce(usinbuf, usoutbuf, 3, MPI_UNSIGNED_SHORT, MPI_BOR, 0, comm);
    if (rc) {
        MTestPrintErrorMsg("MPI_BOR and MPI_UNSIGNED_SHORT", rc);
        errs++;
    } else {
        if (rank == 0) {
            if (usoutbuf[0] != 0xffff) {
                errs++;
                fprintf(stderr, "short BOR(1) test failed\n");
            }
            if (usoutbuf[1]) {
                errs++;
                fprintf(stderr, "short BOR(0) test failed\n");
            }
            if (usoutbuf[2] != 0xffff && size > 1) {
                errs++;
                fprintf(stderr, "short BOR(>) test failed\n");
            }
        }
    }

    /* unsigned */
    MTestPrintfMsg(10, "Reduce of MPI_UNSIGNED\n");
    uinbuf[0] = 0xffffffff;
    uinbuf[1] = 0;
    uinbuf[2] = (rank > 0) ? 0x3c3c3c3c : 0xc3c3c3c3;

    uoutbuf[0] = 0;
    uoutbuf[1] = 1;
    uoutbuf[2] = 1;
    rc = MPI_Reduce(uinbuf, uoutbuf, 3, MPI_UNSIGNED, MPI_BOR, 0, comm);
    if (rc) {
        MTestPrintErrorMsg("MPI_BOR and MPI_UNSIGNED", rc);
        errs++;
    } else {
        if (rank == 0) {
            if (uoutbuf[0] != 0xffffffff) {
                errs++;
                fprintf(stderr, "unsigned BOR(1) test failed\n");
            }
            if (uoutbuf[1]) {
                errs++;
                fprintf(stderr, "unsigned BOR(0) test failed\n");
            }
            if (uoutbuf[2] != 0xffffffff && size > 1) {
                errs++;
                fprintf(stderr, "unsigned BOR(>) test failed\n");
            }
        }
    }

    /* int */
    MTestPrintfMsg(10, "Reduce of MPI_INT\n");
    iinbuf[0] = 0xffffffff;
    iinbuf[1] = 0;
    iinbuf[2] = (rank > 0) ? 0x3c3c3c3c : 0xc3c3c3c3;

    ioutbuf[0] = 0;
    ioutbuf[1] = 1;
    ioutbuf[2] = 1;
    rc = MPI_Reduce(iinbuf, ioutbuf, 3, MPI_INT, MPI_BOR, 0, comm);
    if (rc) {
        MTestPrintErrorMsg("MPI_BOR and MPI_INT", rc);
        errs++;
    } else {
        if (rank == 0) {
            if (ioutbuf[0] != 0xffffffff) {
                errs++;
                fprintf(stderr, "int BOR(1) test failed\n");
            }
            if (ioutbuf[1]) {
                errs++;
                fprintf(stderr, "int BOR(0) test failed\n");
            }
            if (ioutbuf[2] != 0xffffffff && size > 1) {
                errs++;
                fprintf(stderr, "int BOR(>) test failed\n");
            }
        }
    }

    /* long */
    MTestPrintfMsg(10, "Reduce of MPI_LONG\n");
    linbuf[0] = 0xffffffff;
    linbuf[1] = 0;
    linbuf[2] = (rank > 0) ? 0x3c3c3c3c : 0xc3c3c3c3;

    loutbuf[0] = 0;
    loutbuf[1] = 1;
    loutbuf[2] = 1;
    rc = MPI_Reduce(linbuf, loutbuf, 3, MPI_LONG, MPI_BOR, 0, comm);
    if (rc) {
        MTestPrintErrorMsg("MPI_BOR and MPI_LONG", rc);
        errs++;
    } else {
        if (rank == 0) {
            if (loutbuf[0] != 0xffffffff) {
                errs++;
                fprintf(stderr, "long BOR(1) test failed\n");
            }
            if (loutbuf[1]) {
                errs++;
                fprintf(stderr, "long BOR(0) test failed\n");
            }
            if (loutbuf[2] != 0xffffffff && size > 1) {
                errs++;
                fprintf(stderr, "long BOR(>) test failed\n");
            }
        }
    }

    /* unsigned long */
    MTestPrintfMsg(10, "Reduce of MPI_UNSIGNED_LONG\n");
    ulinbuf[0] = 0xffffffff;
    ulinbuf[1] = 0;
    ulinbuf[2] = (rank > 0) ? 0x3c3c3c3c : 0xc3c3c3c3;

    uloutbuf[0] = 0;
    uloutbuf[1] = 1;
    uloutbuf[2] = 1;
    rc = MPI_Reduce(ulinbuf, uloutbuf, 3, MPI_UNSIGNED_LONG, MPI_BOR, 0, comm);
    if (rc) {
        MTestPrintErrorMsg("MPI_BOR and MPI_UNSIGNED_LONG", rc);
        errs++;
    } else {
        if (rank == 0) {
            if (uloutbuf[0] != 0xffffffff) {
                errs++;
                fprintf(stderr, "unsigned long BOR(1) test failed\n");
            }
            if (uloutbuf[1]) {
                errs++;
                fprintf(stderr, "unsigned long BOR(0) test failed\n");
            }
            if (uloutbuf[2] != 0xffffffff && size > 1) {
                errs++;
                fprintf(stderr, "unsigned long BOR(>) test failed\n");
            }
        }
    }

#ifdef HAVE_LONG_LONG
    {
        long long llinbuf[3], lloutbuf[3];
        /* long long */
        llinbuf[0] = 0xffffffff;
        llinbuf[1] = 0;
        llinbuf[2] = (rank > 0) ? 0x3c3c3c3c : 0xc3c3c3c3;

        lloutbuf[0] = 0;
        lloutbuf[1] = 1;
        lloutbuf[2] = 1;
        if (MPI_LONG_LONG != MPI_DATATYPE_NULL) {
            MTestPrintfMsg(10, "Reduce of MPI_LONG_LONG\n");
            rc = MPI_Reduce(llinbuf, lloutbuf, 3, MPI_LONG_LONG, MPI_BOR, 0, comm);
            if (rc) {
                MTestPrintErrorMsg("MPI_BOR and MPI_LONG_LONG", rc);
                errs++;
            } else {
                if (rank == 0) {
                    if (lloutbuf[0] != 0xffffffff) {
                        errs++;
                        fprintf(stderr, "long long BOR(1) test failed\n");
                    }
                    if (lloutbuf[1]) {
                        errs++;
                        fprintf(stderr, "long long BOR(0) test failed\n");
                    }
                    if (lloutbuf[2] != 0xffffffff && size > 1) {
                        errs++;
                        fprintf(stderr, "long long BOR(>) test failed\n");
                    }
                }
            }
        }
    }
#endif

    MPI_Comm_set_errhandler(comm, MPI_ERRORS_ARE_FATAL);
    MTest_Finalize(errs);
    return MTestReturnValue(errs);
}