1 // --------------------------------------------------------------------------
4 // Markus Wittmann, 2016-2017
5 // RRZE, University of Erlangen-Nuremberg, Germany
6 // markus.wittmann -at- fau.de or hpc -at- rrze.fau.de
9 // LSS, University of Erlangen-Nuremberg, Germany
11 // This file is part of the Lattice Boltzmann Benchmark Kernels (LbmBenchKernels).
13 // LbmBenchKernels is free software: you can redistribute it and/or modify
14 // it under the terms of the GNU General Public License as published by
15 // the Free Software Foundation, either version 3 of the License, or
16 // (at your option) any later version.
18 // LbmBenchKernels is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 // GNU General Public License for more details.
23 // You should have received a copy of the GNU General Public License
24 // along with LbmBenchKernels. If not, see <http://www.gnu.org/licenses/>.
26 // --------------------------------------------------------------------------
37 static inline double Time()
41 gettimeofday(&time, NULL);
43 return (time.tv_sec + 1e-6 * time.tv_usec);
47 #define STRINGIFYX(x) #x
48 #define STRINGIFY(x) STRINGIFYX(x)
50 // See top of BoostJoin.h for Boost Licence.
51 #include "BoostJoin.h"
52 #define JOIN(X, Y) BOOST_DO_JOIN(X, Y)
55 // Some macro fu to remove the first comma.
56 // "x" is an empty macro agrument in EXPAND2
57 // before the first comma which is skipped
59 #define EXPAND2(x, ...) __VA_ARGS__
60 #define EXPAND(x, ...) EXPAND2(x, ## __VA_ARGS__)
65 #define Assert(expression) \
67 if (!(expression)) { \
68 Error("%s:%d assertion \"%s\" failed with code %d\n", \
70 #expression, expression); \
71 __asm__ ("int $3\n"); \
76 #define AssertMsg(expression, formatString, ...) \
78 if (!(expression)) { \
79 Error("%s:%d assertion \"%s\" failed with code %d\n", \
81 #expression, expression); \
82 Error(formatString, ##__VA_ARGS__); \
83 __asm__ ("int $3\n"); \
89 #define Assert(expression)
90 #define AssertMsg(expression, formatString, ...)
94 #define Verify(expression) \
96 if (!(expression)) { \
97 Error("%s:%d verify \"%s\" failed with code %d\n", \
99 #expression, expression); \
100 __asm__ ("int $3\n"); \
105 #define VerifyMsg(expression, formatString, ...) \
107 if (!(expression)) { \
108 Error("%s:%d verify \"%s\" failed with code %d\n", \
109 __FILE__, __LINE__, \
110 #expression, expression); \
111 Error(formatString, ##__VA_ARGS__); \
112 __asm__ ("int $3\n"); \
117 #define Print(formatString, ...) \
118 fprintf(stdout, SHC_MAGENTA formatString SHC_NC, ##__VA_ARGS__)
120 #define Warning(formatString, ...) \
121 fprintf(stdout, SHC_BROWN "WARNING: " SHC_NC formatString, ##__VA_ARGS__)
123 #define Error(formatString, ...) \
124 fprintf(stderr, SHC_RED "ERROR: " formatString SHC_NC , ##__VA_ARGS__)
126 #define DebugPrint(formatString, ...) \
127 fprintf(stderr, "DEBUG: " formatString, ##__VA_ARGS__)
129 #ifndef NO_SHELL_COLORS
135 #define SHC_NC ESC "[0m"
137 #define SHC_BLACK ESC "[0;30m"
138 #define SHC_MAGENTA ESC "[0;35m"
139 #define SHC_RED ESC "[0;31m"
140 #define SHC_DARK_RED ESC "[1;31m"
141 #define SHC_CYAN ESC "[0;36m"
142 #define SHC_BROWN ESC "[0;33m"
143 #define SHC_DARK_GREEN ESC "[1;32m"
145 #else // NO_SHELL_COLORS
151 #define SHC_MAGENTA ""
153 #define SHC_DARK_RED ""
156 #define SHC_DARK_GREEN ""
158 #endif // NO_SHELL_COLORS
161 #define N_ELEMS(x) (sizeof(x) / sizeof((x)[0]))
164 #define MIN(a, b) ((a) <= (b) ? (a) : (b))
166 static inline int MinI(int a, int b) { return a <= b ? a : b; }
168 // Raises a breakpoint if a debugger is attached, else SIG_TRAP is raised.
169 #define DEBUG_BREAK_POINT() __asm__ ("int $3\n")
171 #define UNUSED(variable) (void)(variable)
174 static inline char * ByteToHuman(size_t bytes)
176 static char buffer[256] = { 0 };
179 snprintf(buffer, sizeof(buffer), "%lu b", bytes);
183 double KiB = bytes / 1024.0;
186 snprintf(buffer, sizeof(buffer), "%9.2e KiB", KiB);
190 double MiB = KiB / 1024.0;
192 snprintf(buffer, sizeof(buffer), "%9.2e MiB", MiB);
196 double GiB = MiB / 1024.0;
197 snprintf(buffer, sizeof(buffer), "%9.2e GiB", GiB);