File: commerrx.cxx

package info (click to toggle)
mpich 4.0.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 423,384 kB
  • sloc: ansic: 1,088,434; cpp: 71,364; javascript: 40,763; f90: 22,829; sh: 17,463; perl: 14,773; xml: 14,418; python: 10,265; makefile: 9,246; fortran: 8,008; java: 4,355; asm: 324; ruby: 176; lisp: 19; php: 8; sed: 4
file content (91 lines) | stat: -rw-r--r-- 2,173 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
/*
 * Copyright (C) by Argonne National Laboratory
 *     See COPYRIGHT in top-level directory
 */

/*
  Tests invocation of error handlers on a variety of communicators, including
  COMM_NULL.
*/

#include "mpitestconf.h"
#include <mpi.h>
#include <iostream>
#include "mpitestcxx.h"

/* returns number of errors found */
int testCommCall(MPI::Comm & comm)
{
    int i;
    bool sawException = false;

    comm.Set_errhandler(MPI::ERRORS_THROW_EXCEPTIONS);
    try {
        // Invalid send
        comm.Send(&i, -1, MPI::DATATYPE_NULL, -1, -10);
    } catch(MPI::Exception & ex) {
        // This is good
        sawException = true;
    }
    catch(...) {
        // This is bad
    }
    if (!sawException) {
        int len;
        char commname[MPI_MAX_OBJECT_NAME];
        comm.Get_name(commname, len);
        std::cout << "Did not see MPI exception on invalid call on communicator " <<
            commname << "\n";
    }
    return sawException ? 0 : 1;
}

int testNullCommCall(void)
{
    int i;
    bool sawException = false;
    const MPI::Comm & comm = MPI::COMM_NULL;

    MPI::COMM_WORLD.Set_errhandler(MPI::ERRORS_THROW_EXCEPTIONS);
    try {
        // Invalid send
        comm.Send(&i, -1, MPI::DATATYPE_NULL, -1, -10);
    } catch(MPI::Exception & ex) {
        // This is good
        sawException = true;
    }
    catch(...) {
        // This is bad
    }
    if (!sawException) {
        std::cout << "Did not see MPI exception on invalid call on communicator COMM_NULL\n";
    }
    return sawException ? 0 : 1;
}

int main(int argc, char *argv[])
{
    int errs = 0;
    bool periods[2] = { false, false };
    int dims[2] = { 0, 0 };

    MTest_Init();

    MPI::Compute_dims(MPI::COMM_WORLD.Get_size(), 2, dims);
    MPI::Cartcomm cart = MPI::COMM_WORLD.Create_cart(2, dims, periods, true);
    cart.Set_name("Cart comm");
    // Graphcomm graph = COMM_WORLD.Create_graph();

    errs += testCommCall(MPI::COMM_WORLD);
    errs += testNullCommCall();
    errs += testCommCall(MPI::COMM_SELF);
    errs += testCommCall(cart);
    //errs += testCommCall(graph);

    cart.Free();
    // graph.Free();

    MTest_Finalize(errs);

    return 0;
}