escript Revision_
Assert.h
Go to the documentation of this file.
1
2/*****************************************************************************
3*
4* Copyright (c) 2003-2020 by The University of Queensland
5* http://www.uq.edu.au
6*
7* Primary Business: Queensland, Australia
8* Licensed under the Apache License, version 2.0
9* http://www.apache.org/licenses/LICENSE-2.0
10*
11* Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12* Development 2012-2013 by School of Earth Sciences
13* Development from 2014-2017 by Centre for Geoscience Computing (GeoComp)
14* Development from 2019 by School of Earth and Environmental Sciences
15**
16*****************************************************************************/
17
18#ifndef __ESCRIPT_ASSERT_H__
19#define __ESCRIPT_ASSERT_H__
20
32#if DOASSERT
33
34//
35// DOASSERT is defined, evaluate assertions and abort on failure.
36//
37
38#include <escript/EsysException.h>
39#include <iostream>
40#include <sstream>
41
42#if ESYS_MPI
43
44#include <mpi.h>
45
46#define ESYS_ASSERT(assert_test, assert_msg)\
47 do {\
48 const bool result = (assert_test);\
49 if (!result) {\
50 std::ostringstream message;\
51 message << assert_msg << "\n\n"\
52 << __FILE__ << ":" << __LINE__ << ": " << #assert_test << "\n";\
53 std::cerr << message.str();\
54 MPI_Abort(MPI_COMM_WORLD, 455347);\
55 }\
56 } while (0)
57
58#else
59
60#define ESYS_ASSERT(assert_test, assert_msg)\
61 do {\
62 const bool result = (assert_test);\
63 if (!result) {\
64 std::ostringstream message;\
65 message << assert_msg << "\n\n"\
66 << __FILE__ << ":" << __LINE__ << ": " << #assert_test << "\n";\
67 throw escript::AssertException(message.str());\
68 }\
69 } while (0)
70
71#endif // ESYS_MPI
72
73#else // !DOASSERT
74
75//
76// DOASSERT is not defined, replace ESYS_ASSERT macro with no-op
77//
78
79#define ESYS_ASSERT(a,b)
80
81#endif
82
83#endif // __ESCRIPT_ASSERT_H__
84