Zoltan2
Loading...
Searching...
No Matches
ErrorHandlingForTests.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Zoltan2: A package of combinatorial algorithms for scientific computing
4//
5// Copyright 2012 NTESS and the Zoltan2 contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#ifndef ERRORHANDLINGFORTESTS_HPP
11#define ERRORHANDLINGFORTESTS_HPP
12
13#include <Zoltan2_config.h>
14#include <iostream>
15#include <string>
16#include <exception>
17
18#include <Teuchos_RCP.hpp>
19#include <Teuchos_Comm.hpp>
20#include <Teuchos_CommHelpers.hpp>
21
22using Teuchos::RCP;
23using Teuchos::Comm;
24using Teuchos::reduceAll;
25
26#define TEST_FAIL_AND_THROW(comm, ok, s){ \
27int gval, lval=( (ok) ? 0 : 1); \
28reduceAll<int,int>(comm, Teuchos::REDUCE_SUM, 1, &lval, &gval);\
29if (gval){ \
30 throw std::runtime_error(std::string(s)); \
31} \
32}
33
34#define TEST_FAIL_AND_EXIT(comm, ok, s, code){ \
35int gval, lval=( (ok) ? 0 : 1); \
36reduceAll<int,int>(comm, Teuchos::REDUCE_SUM, 1, &lval, &gval);\
37if (gval){ \
38 if ((comm).getRank() == 0){\
39 std::cerr << "Error: " << s << std::endl;\
40 std::cout << "Error: " << s << std::endl;\
41 std::cout << "FAIL" << std::endl;\
42 } \
43 exit(code);\
44} \
45}
46
47#define TEST_FAIL_AND_RETURN(comm, ok, s){ \
48int gval, lval=( (ok) ? 0 : 1); \
49reduceAll<int,int>(comm, Teuchos::REDUCE_SUM, 1, &lval, &gval);\
50if (gval){ \
51 if ((comm).getRank() == 0){\
52 std::cerr << "Error: " << s << std::endl;\
53 std::cout << "Error: " << s << std::endl;\
54 std::cout << "FAIL" << std::endl;\
55 } \
56 return; \
57} \
58}
59
60#define TEST_FAIL_AND_RETURN_VALUE(comm, ok, s, rc){ \
61int gval, lval=( (ok) ? 0 : 1); \
62reduceAll<int,int>(comm, Teuchos::REDUCE_SUM, 1, &lval, &gval);\
63if (gval){ \
64 if ((comm).getRank() == 0){\
65 std::cerr << "Error: " << s << std::endl;\
66 std::cout << "Error: " << s << std::endl;\
67 std::cout << "FAIL" << std::endl;\
68 } \
69 return (rc); \
70} \
71}
72
73int globalFail(const Comm<int> &comm, int fail)
74{
75 int gfail=0;
76 reduceAll<int,int>(comm, Teuchos::REDUCE_SUM, 1, &fail, &gfail);
77 return gfail;
78}
79
80void printFailureCode(const Comm<int> &comm, int fail)
81{
82 int rank = comm.getRank();
83 int nprocs = comm.getSize();
84 comm.barrier();
85 for (int p=0; p < nprocs; p++){
86 if (p == rank)
87 std::cout << rank << ": " << fail << std::endl;
88 comm.barrier();
89 }
90 comm.barrier();
91 if (rank==0) std::cout << "FAIL" << std::endl;
92 exit(1);
93}
94
95#endif
int globalFail(const Comm< int > &comm, int fail)
void printFailureCode(const Comm< int > &comm, int fail)
static const std::string fail