1 /*
2 * Copyright (C) by Argonne National Laboratory
3 * See COPYRIGHT in top-level directory
4 */
5
6 /*
7 Tests invocation of error handlers on a variety of communicators, including
8 COMM_NULL.
9 */
10
11 #include "mpitestconf.h"
12 #include <mpi.h>
13 #include <iostream>
14 #include "mpitestcxx.h"
15
16 /* returns number of errors found */
testCommCall(MPI::Comm & comm)17 int testCommCall(MPI::Comm & comm)
18 {
19 int i;
20 bool sawException = false;
21
22 comm.Set_errhandler(MPI::ERRORS_THROW_EXCEPTIONS);
23 try {
24 // Invalid send
25 comm.Send(&i, -1, MPI::DATATYPE_NULL, -1, -10);
26 } catch(MPI::Exception & ex) {
27 // This is good
28 sawException = true;
29 }
30 catch(...) {
31 // This is bad
32 }
33 if (!sawException) {
34 int len;
35 char commname[MPI_MAX_OBJECT_NAME];
36 comm.Get_name(commname, len);
37 std::cout << "Did not see MPI exception on invalid call on communicator " <<
38 commname << "\n";
39 }
40 return sawException ? 0 : 1;
41 }
42
testNullCommCall(void)43 int testNullCommCall(void)
44 {
45 int i;
46 bool sawException = false;
47 const MPI::Comm & comm = MPI::COMM_NULL;
48
49 MPI::COMM_WORLD.Set_errhandler(MPI::ERRORS_THROW_EXCEPTIONS);
50 try {
51 // Invalid send
52 comm.Send(&i, -1, MPI::DATATYPE_NULL, -1, -10);
53 } catch(MPI::Exception & ex) {
54 // This is good
55 sawException = true;
56 }
57 catch(...) {
58 // This is bad
59 }
60 if (!sawException) {
61 std::cout << "Did not see MPI exception on invalid call on communicator COMM_NULL\n";
62 }
63 return sawException ? 0 : 1;
64 }
65
main(int argc,char * argv[])66 int main(int argc, char *argv[])
67 {
68 int errs = 0;
69 bool periods[2] = { false, false };
70 int dims[2] = { 0, 0 };
71
72 MTest_Init();
73
74 MPI::Compute_dims(MPI::COMM_WORLD.Get_size(), 2, dims);
75 MPI::Cartcomm cart = MPI::COMM_WORLD.Create_cart(2, dims, periods, true);
76 cart.Set_name("Cart comm");
77 // Graphcomm graph = COMM_WORLD.Create_graph();
78
79 errs += testCommCall(MPI::COMM_WORLD);
80 errs += testNullCommCall();
81 errs += testCommCall(MPI::COMM_SELF);
82 errs += testCommCall(cart);
83 //errs += testCommCall(graph);
84
85 cart.Free();
86 // graph.Free();
87
88 MTest_Finalize(errs);
89
90 return 0;
91 }
92