File: userdup.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 (142 lines) | stat: -rw-r--r-- 4,154 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
/*
 * Copyright (C) by Argonne National Laboratory
 *     See COPYRIGHT in top-level directory
 */

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

/* Check that user-define error codes and classes are correctly handled by
   the attribute copy routines.

   Note that this behavior is not required by the MPI specification
   but is a quality of implementation issues - users will expect
   to be able to control the class and code that comes back from
   MPI_Comm_dup (and MPI_Comm_free) in this case.
*/

void abortMsg(const char *, int);
int copybomb_fn(MPI_Comm, int, void *, void *, void *, int *);

static int myErrClass, myErrCode;
static int nCall = 0;

void abortMsg(const char *str, int code)
{
    char msg[MPI_MAX_ERROR_STRING];
    int class, resultLen;

    MPI_Error_class(code, &class);
    MPI_Error_string(code, msg, &resultLen);
    fprintf(stderr, "%s: errcode = %d, class = %d, msg = %s\n", str, code, class, msg);
    MPI_Abort(MPI_COMM_WORLD, code);
}

int copybomb_fn(MPI_Comm oldcomm, int keyval, void *extra_state,
                void *attribute_val_in, void *attribute_val_out, int *flag)
{
    int err;
    /* We always fail to copy */
    *flag = 1;

    /* Return either the class (as a code) or the code */
    if (nCall == 0)
        err = myErrClass;
    else
        err = myErrCode;
    nCall++;
    return err;
}


int main(int argc, char *argv[])
{
    MPI_Comm dupWorld, dup2;
    int myRank, key, err, errs = 0;

    MTest_Init(&argc, &argv);

    MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN);

    /* Create my error class and code */
    MPI_Add_error_class(&myErrClass);
    MPI_Add_error_code(myErrClass, &myErrCode);
    MPI_Add_error_string(myErrClass, (char *) "My error class");
    MPI_Add_error_string(myErrCode, (char *) "My error code");

    MPI_Comm_dup(MPI_COMM_WORLD, &dupWorld);

    MPI_Comm_rank(MPI_COMM_WORLD, &myRank);
    err = MPI_Comm_create_keyval(copybomb_fn, MPI_COMM_NULL_DELETE_FN, &key, NULL);
    if (err) {
        errs++;
        abortMsg("Comm_create_keyval", err);
    }

    err = MPI_Comm_set_attr(dupWorld, key, &myRank);
    if (err) {
        errs++;
        abortMsg("Comm_set_attr", err);
    }

    err = MPI_Comm_dup(dupWorld, &dup2);
    if (err == MPI_SUCCESS) {
        errs++;
        fprintf(stderr, "Comm_dup did not fail\n");
        MPI_Comm_free(&dup2);
    } else {
        int eclass, resultLen;
        char msg[MPI_MAX_ERROR_STRING];
        /* Check for expected error class */
        MPI_Error_class(err, &eclass);
        if (eclass != myErrClass) {
            errs++;
            fprintf(stderr, "Unexpected error class = %d, expected user-defined class %d\n", eclass,
                    myErrClass);
        } else {
            MPI_Error_string(err, msg, &resultLen);
            if (strcmp(msg, "My error class") != 0) {
                errs++;
                fprintf(stderr, "Unexpected error string %s\n", msg);
            }
        }
    }

    err = MPI_Comm_dup(dupWorld, &dup2);
    if (err == MPI_SUCCESS) {
        errs++;
        fprintf(stderr, "Comm_dup did not fail (2)\n");
        MPI_Comm_free(&dup2);
    } else {
        int eclass, resultLen;
        char msg[MPI_MAX_ERROR_STRING];
        /* Check for expected error class */
        MPI_Error_class(err, &eclass);
        if (eclass != myErrClass) {
            errs++;
            fprintf(stderr, "Unexpected error class = %d, expected user-defined class %d\n", eclass,
                    myErrClass);
        }
        if (err != myErrCode) {
            errs++;
            fprintf(stderr, "Unexpected error code = %d, expected user-defined code %d\n", err,
                    myErrCode);
        } else {
            MPI_Error_string(err, msg, &resultLen);
            if (strcmp(msg, "My error code") != 0) {
                errs++;
                fprintf(stderr, "Unexpected error string %s, expected user-defined error string\n",
                        msg);
            }
        }
    }

    MPI_Comm_free(&dupWorld);
    MPI_Comm_free_keyval(&key);

    MTest_Finalize(errs);

    return MTestReturnValue(errs);
}