FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
assertion.hpp
Go to the documentation of this file.
1// FEAT3: Finite Element Analysis Toolbox, Version 3
2// Copyright (C) 2010 by Stefan Turek & the FEAT group
3// FEAT3 is released under the GNU General Public License version 3,
4// see the file 'copyright.txt' in the top level directory for details.
5
6#pragma once
7
8// The following line is necessary - otherwise doxygen won't document the #define's in this file.
11// includes, FEAT
13#include <kernel/runtime.hpp>
14
15// includes, system
16#include <string>
17
18namespace FEAT
19{
38 CUDA_HOST_DEVICE [[noreturn]] inline void abortion(
39 const char * const func,
40 const char * const file,
41 const int line,
42 const char * const msg)
43 {
44 #ifndef __CUDA_ARCH__
45 // write error message if available
46 if(msg != nullptr)
47 fprintf(stderr, "\n>>> FATAL ERROR: %s\n\n", msg);
48 else
49 fprintf(stderr, "\n>>> FATAL ERROR: UNSPECIFIED ABORTION\n\n");
50
51 // write basic information
52 fprintf(stderr, "Function: %s\n", func);
53 fprintf(stderr, "File....: %s\n", file);
54 fprintf(stderr, "Line....: %i\n", line);
55
56 // flush stderr
57 fflush(stderr);
58
59 // abort execution;
60 // this may also write a call-stack dump if possible
62 #else
63 // write error message if available
64 if(msg != nullptr)
65 printf("\n>>> FATAL ERROR: %s\n\n", msg);
66 else
67 printf("\n>>> FATAL ERROR: UNSPECIFIED ABORTION\n\n");
68
69 // write basic information
70 printf("Function: %s\n", func);
71 printf("File....: %s\n", file);
72 printf("Line....: %i\n", line);
73
74 // and trap the process
75 __trap();
76 #endif
77 }
78
79 CUDA_HOST [[noreturn]] inline void abortion(const char* const func, const char* const file, const int line, const std::string& msg)
80 {
81 abortion(func, file, line, msg.c_str());
82 }
83
114 CUDA_HOST_DEVICE void inline assertion(
115 bool expr,
116 const char * const expr_str,
117 const char * const func,
118 const char * const file,
119 const int line,
120 const char * const msg = nullptr)
121 {
122 // alright?
123 if(expr)
124 return;
125 #ifndef __CUDA_ARCH__
126 // write error message if available
127 if(msg != nullptr)
128 fprintf(stderr, "\n>>> FATAL ERROR: ASSERTION FAILED: %s\n", msg);
129 else
130 fprintf(stderr, "\n>>> FATAL ERROR: ASSERTION FAILED\n");
131
132 // write basic information
133 fprintf(stderr, "Expression: %s\n", expr_str);
134 fprintf(stderr, "Function..: %s\n", func);
135 fprintf(stderr, "File......: %s\n", file);
136 fprintf(stderr, "Line......: %i\n", line);
137
138 // flush stderr
139 fflush(stderr);
140
141 // abort execution;
142 // this may also write a call-stack dump if possible
144 #else
145 // cuda does only know printf
146 if(msg != nullptr)
147 printf("\n>>> FATAL ERROR: ASSERTION FAILED: %s\n", msg);
148 else
149 printf("\n>>> FATAL ERROR: ASSERTION FAILED\n");
150
151 // write basic information
152 printf("Expression: %s\n", expr_str);
153 printf("Function..: %s\n", func);
154 printf("File......: %s\n", file);
155 printf("Line......: %i\n", line);
156
157 // also cuda should and can not abort our runtime, so we use an internal trap
158 // to send an interupt signal... warning, this could (in theory) be catched and ignored
159 __trap();
160 #endif
161 }
162
163 CUDA_HOST inline void assertion(
164 bool expr,
165 const char* const expr_str,
166 const char* const func,
167 const char* const file,
168 const int line,
169 const std::string& msg)
170 {
171 assertion(expr, expr_str, func, file, line, msg.c_str());
172 }
173
189#if defined(FEAT_COMPILER_INTEL) && (FEAT_COMPILER_INTEL < 2000)
190# define XABORTM(msg) do {FEAT::abortion(__func__, __FILE__, __LINE__, msg); std::abort();} while(false)
191#else // any smart C++ compiler
192# define XABORTM(msg) FEAT::abortion(__func__, __FILE__, __LINE__, msg)
193#endif
194
195
225#if defined(DEBUG)
226# define ASSERT(expr) FEAT::assertion(expr, #expr, __func__, __FILE__, __LINE__)
227# define ASSERTM(expr, msg) FEAT::assertion(expr, #expr, __func__, __FILE__, __LINE__, msg)
228#else
229# define ASSERT(expr) void(0)
230# define ASSERTM(expr, msg) void(0)
231#endif
232
262#define XASSERT(expr) FEAT::assertion(expr, #expr, __func__, __FILE__, __LINE__)
263#define XASSERTM(expr, msg) FEAT::assertion(expr, #expr, __func__, __FILE__, __LINE__, msg)
264
265} // namespace FEAT
FEAT Kernel base header.
static void abort(bool dump_call_stack=true)
FEAT abortion.
Definition: runtime.cpp:413
FEAT namespace.
Definition: adjactor.hpp:12
CUDA_HOST_DEVICE void assertion(bool expr, const char *const expr_str, const char *const func, const char *const file, const int line, const char *const msg=nullptr)
Assertion function.
Definition: assertion.hpp:114
CUDA_HOST_DEVICE void abortion(const char *const func, const char *const file, const int line, const char *const msg)
Abortion function.
Definition: assertion.hpp:38