File: uoplong.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 (114 lines) | stat: -rw-r--r-- 3,489 bytes parent folder | download | duplicates (3)
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
/*
 * Copyright (C) by Argonne National Laboratory
 *     See COPYRIGHT in top-level directory
 */

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

#ifdef OP_LARGE
#define COUNT_TYPE MPI_Count
#define MPI_Op_create MPI_Op_create_c
#else
#define COUNT_TYPE int
#endif

/*
 * Test user-defined operations with a large number of elements.
 * Added because a talk at EuroMPI'12 claimed that these failed with
 * more than 64k elements
 */

#define MAX_ERRS 10
#define MAX_COUNT 1200000

void myop(void *cinPtr, void *coutPtr, COUNT_TYPE * count, MPI_Datatype * dtype);

/*
 * myop takes a datatype that is a triple of doubles, and computes
 * the sum, max, min of the respective elements of the triple.
 */
void myop(void *cinPtr, void *coutPtr, COUNT_TYPE * count, MPI_Datatype * dtype)
{
    int i, n = *count;
    double const *cin = (double *) cinPtr;
    double *cout = (double *) coutPtr;

    for (i = 0; i < n; i++) {
        cout[0] += cin[0];
        cout[1] = (cout[1] > cin[1]) ? cout[1] : cin[1];
        cout[2] = (cout[2] < cin[2]) ? cout[2] : cin[2];
        cin += 3;
        cout += 3;
    }
}

int main(int argc, char *argv[])
{
    int errs = 0;
    int wsize, wrank, i, count;
    MPI_Datatype tripleType;
    double *inVal, *outVal;
    double maxval, sumval, minval;
    MPI_Op op;

    MTest_Init(&argc, &argv);
    MPI_Op_create(myop, 0, &op);
    MPI_Type_contiguous(3, MPI_DOUBLE, &tripleType);
    MPI_Type_commit(&tripleType);

    MPI_Comm_size(MPI_COMM_WORLD, &wsize);
    MPI_Comm_rank(MPI_COMM_WORLD, &wrank);

    for (count = 1; count < MAX_COUNT; count += count) {
        if (wrank == 0)
            MTestPrintfMsg(1, "Count = %d\n", count);
        inVal = (double *) malloc(3 * count * sizeof(double));
        outVal = (double *) malloc(3 * count * sizeof(double));
        if (!inVal || !outVal) {
            fprintf(stderr, "Unable to allocate %d words for data\n", 3 * count);
            MPI_Abort(MPI_COMM_WORLD, 1);
        }
        for (i = 0; i < count * 3; i++) {
            outVal[i] = -1;
            inVal[i] = 1 + (i & 0x3);
        }
        MPI_Reduce(inVal, outVal, count, tripleType, op, 0, MPI_COMM_WORLD);
        /* Check Result values */
        if (wrank == 0) {
            for (i = 0; i < 3 * count; i += 3) {
                sumval = wsize * (1 + (i & 0x3));
                maxval = 1 + ((i + 1) & 0x3);
                minval = 1 + ((i + 2) & 0x3);
                if (outVal[i] != sumval) {
                    if (errs < MAX_ERRS)
                        fprintf(stderr, "%d: outval[%d] = %f, expected %f (sum)\n",
                                count, i, outVal[i], sumval);
                    errs++;
                }
                if (outVal[i + 1] != maxval) {
                    if (errs < MAX_ERRS)
                        fprintf(stderr, "%d: outval[%d] = %f, expected %f (max)\n",
                                count, i + 1, outVal[i + 1], maxval);
                    errs++;
                }
                if (outVal[i + 2] != minval) {
                    if (errs < MAX_ERRS)
                        fprintf(stderr, "%d: outval[%d] = %f, expected %f (min)\n",
                                count, i + 2, outVal[i + 2], minval);
                    errs++;
                }
            }
        }

        free(inVal);
        free(outVal);
    }

    MPI_Op_free(&op);
    MPI_Type_free(&tripleType);
    MTest_Finalize(errs);
    return MTestReturnValue(errs);
}