40 #define _XOPEN_SOURCE 700
51 #define SIONDEBFUNCNAMELEN 50
52 #define MAXOMPTHREADS 300
55 int _sion_get_thread_num_default(
void);
56 static int (*_sion_my_get_thread_num)(void) = _sion_get_thread_num_default;
59 static int _sion_debug_first[MAXOMPTHREADS] = {1,1,1,1,1, 1,1,1,1,1, 1,1,1,1,1, 1,1,1,1,1,
60 1,1,1,1,1, 1,1,1,1,1, 1,1,1,1,1, 1,1,1,1,1,
61 1,1,1,1,1, 1,1,1,1,1, 1,1,1,1,1, 1,1,1,1,1,
62 1,1,1,1,1, 1,1,1,1,1, 1,1,1,1,1, 1,1,1,1,1,
63 1,1,1,1,1, 1,1,1,1,1, 1,1,1,1,1, 1,1,1,1,1,
65 1,1,1,1,1, 1,1,1,1,1, 1,1,1,1,1, 1,1,1,1,1,
66 1,1,1,1,1, 1,1,1,1,1, 1,1,1,1,1, 1,1,1,1,1,
67 1,1,1,1,1, 1,1,1,1,1, 1,1,1,1,1, 1,1,1,1,1,
68 1,1,1,1,1, 1,1,1,1,1, 1,1,1,1,1, 1,1,1,1,1,
69 1,1,1,1,1, 1,1,1,1,1, 1,1,1,1,1, 1,1,1,1,1,
71 1,1,1,1,1, 1,1,1,1,1, 1,1,1,1,1, 1,1,1,1,1,
72 1,1,1,1,1, 1,1,1,1,1, 1,1,1,1,1, 1,1,1,1,1,
73 1,1,1,1,1, 1,1,1,1,1, 1,1,1,1,1, 1,1,1,1,1,
74 1,1,1,1,1, 1,1,1,1,1, 1,1,1,1,1, 1,1,1,1,1,
75 1,1,1,1,1, 1,1,1,1,1, 1,1,1,1,1, 1,1,1,1,1};
78 static FILE *_sion_debug_out[MAXOMPTHREADS] = {NULL,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,NULL,
79 NULL,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,NULL,
80 NULL,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,NULL,
81 NULL,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,NULL,
82 NULL,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,NULL,
83 NULL,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,NULL,
84 NULL,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,NULL,
85 NULL,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,NULL,
86 NULL,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,NULL,
87 NULL,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,NULL,
89 NULL,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,NULL,
90 NULL,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,NULL,
91 NULL,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,NULL,
92 NULL,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,NULL,
93 NULL,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,NULL,
94 NULL,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,NULL,
95 NULL,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,NULL,
96 NULL,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,NULL,
97 NULL,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,NULL,
98 NULL,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,NULL,
100 NULL,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,NULL,
101 NULL,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,NULL,
102 NULL,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,NULL,
103 NULL,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,NULL,
104 NULL,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,NULL,
105 NULL,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,NULL,
106 NULL,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,NULL,
107 NULL,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,NULL,
108 NULL,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,NULL,
109 NULL,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,NULL};
112 static int _sion_debug_isdebug[MAXOMPTHREADS] = {0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,
113 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,
114 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,
115 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,
116 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,
118 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,
119 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,
120 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,
121 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,
122 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,
124 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,
125 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,
126 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,
127 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,
128 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0};
131 static int _sion_debug_myrank[MAXOMPTHREADS] = {-1,-1,-1,-1,-1, -1,-1,-1,-1,-1, -1,-1,-1,-1,-1, -1,-1,-1,-1,-1,
132 -1,-1,-1,-1,-1, -1,-1,-1,-1,-1, -1,-1,-1,-1,-1, -1,-1,-1,-1,-1,
133 -1,-1,-1,-1,-1, -1,-1,-1,-1,-1, -1,-1,-1,-1,-1, -1,-1,-1,-1,-1,
134 -1,-1,-1,-1,-1, -1,-1,-1,-1,-1, -1,-1,-1,-1,-1, -1,-1,-1,-1,-1,
135 -1,-1,-1,-1,-1, -1,-1,-1,-1,-1, -1,-1,-1,-1,-1, -1,-1,-1,-1,-1,
137 -1,-1,-1,-1,-1, -1,-1,-1,-1,-1, -1,-1,-1,-1,-1, -1,-1,-1,-1,-1,
138 -1,-1,-1,-1,-1, -1,-1,-1,-1,-1, -1,-1,-1,-1,-1, -1,-1,-1,-1,-1,
139 -1,-1,-1,-1,-1, -1,-1,-1,-1,-1, -1,-1,-1,-1,-1, -1,-1,-1,-1,-1,
140 -1,-1,-1,-1,-1, -1,-1,-1,-1,-1, -1,-1,-1,-1,-1, -1,-1,-1,-1,-1,
141 -1,-1,-1,-1,-1, -1,-1,-1,-1,-1, -1,-1,-1,-1,-1, -1,-1,-1,-1,-1,
143 -1,-1,-1,-1,-1, -1,-1,-1,-1,-1, -1,-1,-1,-1,-1, -1,-1,-1,-1,-1,
144 -1,-1,-1,-1,-1, -1,-1,-1,-1,-1, -1,-1,-1,-1,-1, -1,-1,-1,-1,-1,
145 -1,-1,-1,-1,-1, -1,-1,-1,-1,-1, -1,-1,-1,-1,-1, -1,-1,-1,-1,-1,
146 -1,-1,-1,-1,-1, -1,-1,-1,-1,-1, -1,-1,-1,-1,-1, -1,-1,-1,-1,-1,
147 -1,-1,-1,-1,-1, -1,-1,-1,-1,-1, -1,-1,-1,-1,-1, -1,-1,-1,-1,-1};
149 static int _sion_debug_debmask = 1023;
150 static int _sion_debug_debrank1 = -1;
151 static int _sion_debug_debrank2 = -1;
152 static int _sion_debug_silent = 0;
153 static int _sion_debug_isinit = 0;
154 static char * _sion_debug_fn = NULL;
156 #define _DEBUG_INIT_THREAD \
158 threadid = _sion_my_get_thread_num(); \
159 if(threadid>MAXOMPTHREADS) threadid=(MAXOMPTHREADS-1);
163 int _sion_get_thread_num_default(
void) {
168 int _sion_debug_set_query_thread_num_function(
int (*get_thread_num)(
void) ) {
170 _sion_my_get_thread_num=get_thread_num;
184 if (_sion_debug_first[threadid])
187 if ((!_sion_debug_isdebug[threadid]) || !(mask & _sion_debug_debmask))
190 fprintf(_sion_debug_out[threadid],
" ");
192 va_start(ap, format);
194 vfprintf(_sion_debug_out[threadid], format, ap);
205 int sion_dprintfp(
int mask,
const char *callfunction,
int rank,
const char *format, ...)
208 char tmpfuncname[SIONDEBFUNCNAMELEN + 1];
210 int setrank = 0, norank = 0;
213 if ((_sion_debug_myrank[threadid] < 0) && (rank < 0)) {
219 rank = _sion_debug_myrank[threadid];
224 if (_sion_debug_myrank[threadid] < 0) {
225 _sion_debug_myrank[threadid] = rank;
231 if (_sion_debug_first[threadid])
236 if ((!_sion_debug_isdebug[threadid]) || !(mask & _sion_debug_debmask))
238 if ((_sion_debug_debrank1 >= 0) && (_sion_debug_debrank2 >= 0)) {
239 if ((rank != _sion_debug_debrank1) && (rank != _sion_debug_debrank2))
242 else if (_sion_debug_debrank1 >= 0) {
243 if (rank != _sion_debug_debrank1)
247 if (strlen(callfunction) > SIONDEBFUNCNAMELEN) {
248 strncpy(tmpfuncname, callfunction, SIONDEBFUNCNAMELEN);
249 tmpfuncname[SIONDEBFUNCNAMELEN] =
'\0';
252 strcpy(tmpfuncname, callfunction);
254 sprintf(spec,
"SION[%s%s%%5d][%%-%ds] ", (setrank ?
"S" :
" "), (norank ?
"N" :
" "), SIONDEBFUNCNAMELEN);
255 fprintf(_sion_debug_out[threadid], spec, rank, tmpfuncname);
257 fprintf(_sion_debug_out[threadid],
" ");
259 fprintf(_sion_debug_out[threadid],
" ");
261 fprintf(_sion_debug_out[threadid],
" ");
263 va_start(ap, format);
265 vfprintf(_sion_debug_out[threadid], format, ap);
269 fflush(_sion_debug_out[threadid]);
280 if (_sion_debug_first[threadid])
283 return _sion_debug_out[threadid];
292 if (_sion_debug_out[threadid] && (_sion_debug_out[threadid] != stdout) && (_sion_debug_out[threadid] != stderr)) {
293 fclose(_sion_debug_out[threadid]);
294 _sion_debug_out[threadid] = NULL;
295 _sion_debug_first[threadid] = 1;
299 int sion_isdebug(
void)
302 if (_sion_debug_first[threadid])
305 return _sion_debug_isdebug[threadid] ? _sion_debug_debmask : 0;
320 if (_sion_debug_out[threadid])
323 _sion_debug_first[threadid] = 0;
326 fname = (
char *) malloc((strlen(filename) + 1) *
sizeof(char));
327 strcpy(fname, filename);
331 if (!fname || (strlen(fname) == 0) || !strcmp(fname,
"stderr")) {
332 _sion_debug_out[threadid] = stderr;
334 else if (!strcmp(fname,
"stdout")) {
335 _sion_debug_out[threadid] = stdout;
337 else if (!(_sion_debug_out[threadid] = fopen(fname,
"w"))) {
338 fprintf(stderr,
"sion_dprintf: failed to open '%s' for writing\n", fname);
339 _sion_debug_out[threadid] = stderr;
342 #ifdef SION_DEBUG_EXTREME
343 fprintf(stderr,
"Warning: you are using a version of SION that is configured with -DEBUG (current debug-mask is %d\n", debmask);
346 if ((_sion_debug_out[threadid] != stdout) && (_sion_debug_out[threadid] != stderr))
347 fprintf(stderr,
"Writing debug output to %s\n", fname);
352 _sion_debug_debmask = mask;
353 _sion_debug_isdebug[threadid] = 1;
356 void sion_debug_off(
void)
359 _sion_debug_isdebug[threadid] = 0;
376 if (_sion_debug_first[threadid]) {
379 _sion_debug_first[threadid] = 0;
380 _sion_debug_isdebug[threadid] = 0;
384 if(_sion_debug_isinit) {
391 _sion_debug_debrank1 = atoi(t);
395 _sion_debug_debrank1 = atoi(t);
399 _sion_debug_debrank2 = atoi(t);
403 _sion_debug_fn = (
char *) t;
408 _sion_debug_debmask = atoi(t);
412 _sion_debug_silent = atoi(t);
414 _sion_debug_isinit=1;
418 if (_sion_debug_fn) {
419 _sion_debug_isdebug[threadid] = 1;
422 if ((_sion_debug_debrank1 >= 0) && (_sion_debug_debrank2 >= 0)) {
423 if ((_sion_debug_myrank[threadid] != _sion_debug_debrank1) && (_sion_debug_myrank[threadid] != _sion_debug_debrank2))
424 _sion_debug_isdebug[threadid] = 0;
426 else if (_sion_debug_debrank1 >= 0) {
427 if (_sion_debug_myrank[threadid] != _sion_debug_debrank1)
428 _sion_debug_isdebug[threadid] = 0;
431 if ((_sion_debug_debrank1 == -2) && (_sion_debug_debrank2 == -2)) {
432 _sion_debug_isdebug[threadid] = 1;
434 if (_sion_debug_isdebug[threadid]) {
436 if ((_sion_debug_fn == 0) || (strlen(_sion_debug_fn) == 0) || !strcmp(_sion_debug_fn,
"stderr")) {
437 _sion_debug_out[threadid] = stderr;
439 else if (!strcmp(_sion_debug_fn,
"stdout")) {
440 _sion_debug_out[threadid] = stdout;
443 filename=malloc((strlen(_sion_debug_fn) + 1 + 10) *
sizeof(
char));
444 sprintf(filename,
"%s.%05d", _sion_debug_fn, _sion_debug_myrank[threadid]);
446 if (!(_sion_debug_out[threadid] = fopen(filename,
"a"))) {
447 fprintf(_sion_debug_out[threadid],
"sion_dprintf: failed to open '%s' for writing\n", filename);
451 if( rvalue && ((_sion_debug_out[threadid] != stdout) && (_sion_debug_out[threadid] != stderr)) && (!_sion_debug_silent) )
452 fprintf(stderr,
"Writing debug output to %s\n", filename);
456 if (filename) free(filename);
460 #ifdef SION_DEBUG_EXTREME
461 fprintf(stderr,
"Warning: you are using a version of SION that is configured with --with-debug (current debug-mask is %d)\n", _sion_debug_debmask);
callback wrappers for OMP thread safe fd manipulation
int sion_dprintfp(int mask, const char *callfunction, int rank, const char *format,...)
Print debugging info formating the message like printf and including the name of the calling function...
FILE * sion_get_dfile(void)
int _sion_debug_init(void)
initialize the debug environment
void sion_debug_on(int mask, const char *filename)
sets debug mode.
int sion_dprintf(int mask, const char *format,...)
Print debugging info formating the message like printf.
char * _sion_getenv(const char *name)