-
Notifications
You must be signed in to change notification settings - Fork 3
/
toolsdebug.h
53 lines (41 loc) · 2.2 KB
/
toolsdebug.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. See the enclosed file LICENSE for a copy or if
* that was not distributed with this file, You can obtain one at
* http://mozilla.org/MPL/2.0/.
*
* Copyright 2017 Max H. Gerlach
*
* */
#ifndef TOOLSDEBUG_H
#define TOOLSDEBUG_H
// as suggested by
// http://www.open-mpi.org/faq/?category=debugging
// this can be used to attach to one running MPI process
// via
// ssh $hostname gdb $executable --pid $pid
#define FREEZE_FOR_DEBUGGER() \
do { \
int i = 0; \
char hostname[256]; \
gethostname(hostname, sizeof(hostname)); \
std::cout << "PID " << getpid() << " on " << hostname << " ready for attach" << std::endl; \
while (0 == i) \
/*sleep(5)*/; \
} while(false)
#define CHECK_NAN(mat) for (uint32_t y = 0; y < mat.n_rows; ++y) { \
for (uint32_t x = 0; x < mat.n_cols; ++x) { \
if (std::isnan(std::real(mat(y, x))) or \
std::isnan(std::imag(mat(y, x)))) { \
std::cout << #mat << " " << y << " " << x << "\n"; \
FREEZE_FOR_DEBUGGER(); \
} \
} \
}
#define CHECK_VEC_NAN(vec) for (uint32_t y = 0; y < vec.n_elem; ++y) { \
if (std::isnan(std::real(vec[y])) or \
std::isnan(std::imag(vec[y]))) { \
std::cout << __FILE__ << ":" << __LINE__ << " " << #vec << " " << y << "\n"; \
FREEZE_FOR_DEBUGGER(); \
} \
}
#endif /* TOOLSDEBUG_H */