GHOST
1.1.2
General, Hybrid, and Optimized Sparse Toolkit
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Groups
Pages
include
ghost
log.h
Go to the documentation of this file.
1
6
#ifndef GHOST_LOG_H
7
#define GHOST_LOG_H
8
9
#ifdef GHOST_FUJITSU
10
#define __func__ "unknown"
11
#endif
12
13
#include "config.h"
14
15
#ifdef GHOST_HAVE_MPI
16
#include <mpi.h>
17
#endif
18
19
#ifdef __cplusplus
20
#include <cstdio>
21
#include <cstring>
22
#else
23
#include <stdio.h>
24
#include <string.h>
25
#endif
26
27
#define GHOST_ANSI_COLOR_RED "\x1b[31m"
28
#define GHOST_ANSI_COLOR_GREEN "\x1b[32m"
29
#define GHOST_ANSI_COLOR_YELLOW "\x1b[33m"
30
#define GHOST_ANSI_COLOR_BLUE "\x1b[34m"
31
#define GHOST_ANSI_COLOR_MAGENTA "\x1b[35m"
32
#define GHOST_ANSI_COLOR_CYAN "\x1b[36m"
33
#define GHOST_ANSI_COLOR_RESET "\x1b[0m"
34
35
#define GHOST_IF_DEBUG(level) if(GHOST_VERBOSITY > level)
36
#define GHOST_FILE_BASENAME (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
37
38
/* taken from http://stackoverflow.com/a/11172679 */
39
/* expands to the first argument */
40
#define GHOST_FIRST(...) GHOST_FIRST_HELPER(__VA_ARGS__, throwaway)
41
#define GHOST_FIRST_HELPER(first, ...) first
42
43
/*
44
* if there's only one argument, expands to nothing. if there is more
45
* than one argument, expands to a comma followed by everything but
46
* the first argument. only supports up to 9 arguments but can be
47
* trivially expanded.
48
*/
49
#define REST(...) REST_HELPER(NUM(__VA_ARGS__), __VA_ARGS__)
50
#define REST_HELPER(qty, ...) REST_HELPER2(qty, __VA_ARGS__)
51
#define REST_HELPER2(qty, ...) REST_HELPER_##qty(__VA_ARGS__)
52
#define REST_HELPER_ONE(first)
53
#define REST_HELPER_TWOORMORE(first, ...) , __VA_ARGS__
54
#define NUM(...) \
55
SELECT_20TH(__VA_ARGS__, TWOORMORE, TWOORMORE, TWOORMORE, TWOORMORE,\
56
TWOORMORE, TWOORMORE, TWOORMORE, TWOORMORE, TWOORMORE, TWOORMORE, TWOORMORE, TWOORMORE, TWOORMORE, TWOORMORE, TWOORMORE, TWOORMORE, TWOORMORE, TWOORMORE, ONE, throwaway)
57
#define SELECT_20TH(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, ...) a20
58
59
#ifdef GHOST_HAVE_MPI
60
61
#ifdef GHOST_LOG_TIMESTAMP
62
63
#define GHOST_LOG(type,color,...) {\
64
double logmacrotime;\
65
ghost_timing_elapsed(&logmacrotime);\
66
int logmacrome;\
67
int logmacroerr = MPI_Comm_rank(MPI_COMM_WORLD,&logmacrome);\
68
if (logmacroerr != MPI_SUCCESS) {\
69
logmacrome = -1;\
70
}\
71
if (logmacrome == GHOST_LOG_RANK || -1 == GHOST_LOG_RANK) {\
72
fprintf(stderr, color "[GHOST] PE%d %.3f " #type " at %s() <%s:%d>: " GHOST_FIRST(__VA_ARGS__) GHOST_ANSI_COLOR_RESET "\n", logmacrome, logmacrotime, __func__, GHOST_FILE_BASENAME, __LINE__ REST(__VA_ARGS__)); \
73
fflush(stderr);\
74
}\
75
}\
76
77
#else
78
79
#define GHOST_LOG(type,color,...) {\
80
int logmacrome;\
81
int logmacroerr = MPI_Comm_rank(MPI_COMM_WORLD,&logmacrome);\
82
if (logmacroerr != MPI_SUCCESS) {\
83
logmacrome = -1;\
84
}\
85
if (logmacrome == GHOST_LOG_RANK || -1 == GHOST_LOG_RANK) {\
86
fprintf(stderr, color "[GHOST] PE%d " #type " at %s() <%s:%d>: " GHOST_FIRST(__VA_ARGS__) GHOST_ANSI_COLOR_RESET "\n", logmacrome, __func__, GHOST_FILE_BASENAME, __LINE__ REST(__VA_ARGS__)); \
87
fflush(stderr);\
88
}\
89
}\
90
91
#endif
92
93
#else
94
95
#ifdef GHOST_LOG_TIMESTAMP
96
97
#define GHOST_LOG(type,color,...) {\
98
double locmacrotime;\
99
ghost_timing_elapsed(&logmacrotime);\
100
fprintf(stderr, color "[GHOST] %.3f " #type " at %s() <%s:%d>: " GHOST_FIRST(__VA_ARGS__) GHOST_ANSI_COLOR_RESET "\n", logmacrotime, __func__, GHOST_FILE_BASENAME, __LINE__ REST(__VA_ARGS__));\
101
}\
102
103
#else
104
105
#define GHOST_LOG(type,color,...) {\
106
fprintf(stderr, color "[GHOST] " #type " at %s() <%s:%d>: " GHOST_FIRST(__VA_ARGS__) GHOST_ANSI_COLOR_RESET "\n", __func__, GHOST_FILE_BASENAME, __LINE__ REST(__VA_ARGS__));\
107
}\
108
109
#endif
110
111
#endif
112
113
114
#define GHOST_DEBUG_LOG(level,...) {if(GHOST_VERBOSITY > level) { GHOST_LOG(DEBUG,GHOST_ANSI_COLOR_RESET,__VA_ARGS__) }}
115
116
#ifdef GHOST_LOG_ONLYFIRST
117
#define GHOST_INFO_LOG(...) {static int __printed = 0; if(!__printed && GHOST_VERBOSITY) { GHOST_LOG(INFO,GHOST_ANSI_COLOR_BLUE,__VA_ARGS__); __printed=1; }}
118
#define GHOST_WARNING_LOG(...) {static int __printed = 0; if(!__printed && GHOST_VERBOSITY) { GHOST_LOG(WARNING,GHOST_ANSI_COLOR_YELLOW,__VA_ARGS__); __printed=1; }}
119
#define GHOST_PERFWARNING_LOG(...) {static int __printed = 0; if(!__printed && GHOST_VERBOSITY) { GHOST_LOG(PERFWARNING,GHOST_ANSI_COLOR_MAGENTA,__VA_ARGS__); __printed=1; }}
120
#define GHOST_ERROR_LOG(...) {static int __printed = 0; if(!__printed && GHOST_VERBOSITY) { GHOST_LOG(ERROR,GHOST_ANSI_COLOR_RED,__VA_ARGS__); __printed=1; }}
121
#else
122
#define GHOST_INFO_LOG(...) {if (GHOST_VERBOSITY) { GHOST_LOG(INFO,GHOST_ANSI_COLOR_BLUE,__VA_ARGS__); }}
123
#define GHOST_WARNING_LOG(...) {if (GHOST_VERBOSITY) { GHOST_LOG(WARNING,GHOST_ANSI_COLOR_YELLOW,__VA_ARGS__); }}
124
#define GHOST_PERFWARNING_LOG(...) {if (GHOST_VERBOSITY) { GHOST_LOG(PERFWARNING,GHOST_ANSI_COLOR_MAGENTA,__VA_ARGS__); }}
125
#define GHOST_ERROR_LOG(...) {if (GHOST_VERBOSITY) { GHOST_LOG(ERROR,GHOST_ANSI_COLOR_RED,__VA_ARGS__); }}
126
#endif
127
128
#endif
Generated on Thu Dec 13 2018 20:56:02 for GHOST by
1.8.6