-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommon.h
75 lines (65 loc) · 1.66 KB
/
common.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/sysinfo.h>
#include <math.h>
#include <string.h>
#include <errno.h>
#include <limits.h>
#include <mpi.h>
#ifdef __cplusplus
extern "C" {
#endif
#define TRUE 1
#define FALSE 0
#define ERROR -1
#define PATH_MAX 4096
#define DEBUG_PRINT 0
#define CHK(_hr) \
{ \
int hr = _hr; \
if(hr != MPI_SUCCESS) \
{ \
errno = (errno == MPI_SUCCESS) ? EPERM : errno; \
return hr; \
} \
}
#define CHKPRINT(_hr) \
{ \
int hr = _hr; \
if(hr != MPI_SUCCESS) \
{ \
fprintf(stderr, "Error in %s:%d (%d / %s)\n", __FILE__, __LINE__, hr, strerror(errno)); \
return hr; \
} \
}
#define CHKB(b) { if(b) { CHK(ERROR); } }
#if DEBUG_PRINT
#define PREFIX "[P%d] %s:%d -> %s() / "
#define SUFFIX "\n"
#define DBGPRINTF(input, ...) \
{ \
int _rank_dbg = 0; \
MPI_Comm_rank(MPI_COMM_WORLD, &_rank_dbg); \
if (DEBUG_PRINT < 0 || (_rank_dbg + 1) == DEBUG_PRINT) \
fprintf(stderr, PREFIX input SUFFIX, _rank_dbg, __FILE__, __LINE__, __func__, __VA_ARGS__); \
}
#define DBGPRINT(input) \
{ \
int _rank_dbg = 0; \
MPI_Comm_rank(MPI_COMM_WORLD, &_rank_dbg); \
if (DEBUG_PRINT < 0 || (_rank_dbg + 1) == DEBUG_PRINT) \
fprintf(stderr, PREFIX input SUFFIX, _rank_dbg, __FILE__, __LINE__, __func__); \
}
#else
#define DBGPRINTF(input, ...) { }
#define DBGPRINT(input) { }
#endif
#ifdef __cplusplus
}
#endif