CoDiPack  2.2.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
exceptions.hpp
1/*
2 * CoDiPack, a Code Differentiation Package
3 *
4 * Copyright (C) 2015-2024 Chair for Scientific Computing (SciComp), University of Kaiserslautern-Landau
5 * Homepage: http://scicomp.rptu.de
6 * Contact: Prof. Nicolas R. Gauger (codi@scicomp.uni-kl.de)
7 *
8 * Lead developers: Max Sagebaum, Johannes Blühdorn (SciComp, University of Kaiserslautern-Landau)
9 *
10 * This file is part of CoDiPack (http://scicomp.rptu.de/software/codi).
11 *
12 * CoDiPack is free software: you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, either version 3 of the
15 * License, or (at your option) any later version.
16 *
17 * CoDiPack is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty
19 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20 *
21 * See the GNU General Public License for more details.
22 * You should have received a copy of the GNU
23 * General Public License along with CoDiPack.
24 * If not, see <http://www.gnu.org/licenses/>.
25 *
26 * For other licensing options please contact us.
27 *
28 * Authors:
29 * - SciComp, University of Kaiserslautern-Landau:
30 * - Max Sagebaum
31 * - Johannes Blühdorn
32 * - Former members:
33 * - Tim Albring
34 */
35#pragma once
36
37#include <cstdarg>
38#include <cstdio>
39#include <cstdlib>
40#include <iostream>
41
42#include "../tools/cuda/cudaFunctionAttributes.hpp"
43
45namespace codi {
46
59 CODI_CUDAFunctionAttributes inline void checkAndOutputAssert(bool const condition, char const* conditionString,
60 char const* function, char const* file, int line) {
61#if !CODI_CUDA
62 if (!condition) {
63 std::cerr << "codiAssertion failed: " << conditionString << " in function " << function << " at " << file << ":"
64 << line << std::endl;
65 abort();
66 }
67#endif
68 }
69
82 CODI_CUDAFunctionAttributes inline void outputExceptionOrWarning(char const function[], char const file[],
83 int const line, bool warning, char const* message,
84 ...) {
85#if !CODI_CUDA
86 char const* kind = (warning) ? "Warning" : "Error";
87 fprintf(stderr, "%s in function %s (%s:%d)\nThe message is: ", kind, function, file, line);
88
89 va_list vl;
90 va_start(vl, message);
91 vfprintf(stderr, message, vl);
92 va_end(vl);
93
94 fprintf(stderr, "\n");
95 if (!warning) {
96 exit(-1);
97 }
98#endif
99 }
100
106#define CODI_EXCEPTION(...) ::codi::outputExceptionOrWarning(__func__, __FILE__, __LINE__, false, __VA_ARGS__)
107
113#define CODI_WARNING(...) ::codi::outputExceptionOrWarning(__func__, __FILE__, __LINE__, true, __VA_ARGS__)
114
115#if defined(__GNUC__) || defined(__clang__) || defined(__INTEL_COMPILER)
116 #define DEPRECATE(foo, msg) foo __attribute__((deprecated(msg)))
117#elif defined(_MSC_VER)
118 #define DEPRECATE(foo, msg) __declspec(deprecated(msg)) foo
119#else
120 #error This compiler is not supported.
121#endif
122
125 struct Warning {
126 public:
128 template<bool v>
129 static void implicitCast() {
130 implicitCastStatic(::std::integral_constant<bool, v>());
131 }
132
134 DEPRECATE(static void implicitCastStatic(::std::false_type const&),
135 "static_warning: Implicit conversion of CoDiPack type to real.") {}
136
138 static void implicitCastStatic(::std::true_type const&) {}
139 };
140}
CoDiPack - Code Differentiation Package.
Definition codi.hpp:90
void outputExceptionOrWarning(char const function[], char const file[], int const line, bool warning, char const *message,...)
Prints the positions and the message of the exception.
Definition exceptions.hpp:82
void checkAndOutputAssert(bool const condition, char const *conditionString, char const *function, char const *file, int line)
Checks the assert statement and aborts the program if the statement is false.
Definition exceptions.hpp:59
Definition exceptions.hpp:125
static void implicitCast()
Show a warning about an implicit cast of an active real type.
Definition exceptions.hpp:129
static void implicitCastStatic(::std::true_type const &)
Implementation that ignores the warning.
Definition exceptions.hpp:138
DEPRECATE(static void implicitCastStatic(::std::false_type const &), "static_warning: Implicit conversion of CoDiPack type to real.")
Implementation that displayes the warning.
Definition exceptions.hpp:134