47 #include "euclid_common.h"
48 #include "Parser_dh.h"
50 #include "TimeLog_dh.h"
51 extern void sigRegister_dh ();
56 bool errFlag_dh =
false;
61 char msgBuf_dh[MSG_BUF_SIZE_DH];
73 void openLogfile_dh (
int argc,
char *argv[]);
74 void closeLogfile_dh ();
75 bool logInfoToStderr =
false;
76 bool logInfoToFile =
false;
77 bool logFuncsToStderr =
false;
78 bool logFuncsToFile =
false;
89 #define MAX_MSG_SIZE 1024
90 #define MAX_STACK_SIZE 20
92 static char errMsg_private[MAX_STACK_SIZE][MAX_MSG_SIZE];
93 static int errCount_private = 0;
95 static char calling_stack[MAX_STACK_SIZE][MAX_MSG_SIZE];
97 static int calling_stack_count = 0;
102 openLogfile_dh (
int argc,
char *argv[])
113 sprintf (buf,
"logFile");
116 if (argc && argv != NULL)
119 for (j = 1; j < argc; ++j)
121 if (strcmp (argv[j],
"-logFile") == 0)
125 sprintf (buf,
"%s", argv[j + 1]);
133 if (strcmp (buf,
"none"))
136 sprintf (a,
".%i", myid_dh);
139 if ((logFile = fopen (buf,
"w")) == NULL)
141 fprintf (stderr,
"can't open >%s< for writing; continuing anyway\n",
152 if (fclose (logFile))
154 fprintf (stderr,
"Error closing logFile\n");
161 setInfo_dh (
char *msg,
char *
function,
char *file,
int line)
163 if (logInfoToFile && logFile != NULL)
165 fprintf (logFile,
"INFO: %s;\n function= %s file=%s line=%i\n",
166 msg,
function, file, line);
171 fprintf (stderr,
"INFO: %s;\n function= %s file=%s line=%i\n",
172 msg,
function, file, line);
181 dh_StartFunc (
char *
function,
char *file,
int line,
int priority)
185 sprintf (calling_stack[calling_stack_count],
186 "[%i] %s file= %s line= %i", myid_dh,
function, file,
189 ++calling_stack_count;
191 if (calling_stack_count == MAX_STACK_SIZE)
194 "_____________ dh_StartFunc: OVERFLOW _____________________\n");
198 "_____________ dh_StartFunc: OVERFLOW _____________________\n");
200 --calling_stack_count;
206 dh_EndFunc (
char *
function,
int priority)
210 --calling_stack_count;
212 if (calling_stack_count < 0)
214 calling_stack_count = 0;
216 "_____________ dh_EndFunc: UNDERFLOW _____________________\n");
220 "_____________ dh_EndFunc: UNDERFLOW _____________________\n");
228 setError_dh (
char *msg,
char *
function,
char *file,
int line)
231 if (!strcmp (msg,
""))
233 sprintf (errMsg_private[errCount_private],
234 "[%i] called from: %s file= %s line= %i",
235 myid_dh,
function, file, line);
239 sprintf (errMsg_private[errCount_private],
240 "[%i] ERROR: %s\n %s file= %s line= %i\n",
241 myid_dh, msg,
function, file, line);
249 if (errCount_private == MAX_STACK_SIZE)
254 printErrorMsg (FILE * fp)
258 fprintf (fp,
"errFlag_dh is not set; nothing to print!\n");
265 "\n============= error stack trace ====================\n");
266 for (i = 0; i < errCount_private; ++i)
268 fprintf (fp,
"%s\n", errMsg_private[i]);
276 printFunctionStack (FILE * fp)
279 for (i = 0; i < calling_stack_count; ++i)
281 fprintf (fp,
"%s\n", calling_stack[i]);
292 #define MAX_ERROR_SPACES 200
293 static char spaces[MAX_ERROR_SPACES];
294 static int nesting = 0;
295 static bool initSpaces =
true;
299 Error_dhStartFunc (
char *
function,
char *file,
int line)
303 memset (spaces,
' ', MAX_ERROR_SPACES *
sizeof (
char));
310 spaces[INDENT_DH * nesting] =
' ';
314 if (nesting > MAX_ERROR_SPACES - 1)
315 nesting = MAX_ERROR_SPACES - 1;
316 spaces[INDENT_DH * nesting] =
'\0';
318 if (logFuncsToStderr)
320 fprintf (stderr,
"%s(%i) %s [file= %s line= %i]\n",
321 spaces, nesting,
function, file, line);
323 if (logFuncsToFile && logFile != NULL)
325 fprintf (logFile,
"%s(%i) %s [file= %s line= %i]\n",
326 spaces, nesting,
function, file, line);
332 Error_dhEndFunc (
char *
function)
337 spaces[INDENT_DH * nesting] =
'\0';
344 static bool EuclidIsActive =
false;
347 #define __FUNC__ "EuclidIsInitialized"
349 EuclidIsInitialized ()
351 return EuclidIsActive;
355 #define __FUNC__ "EuclidInitialize"
357 EuclidInitialize (
int argc,
char *argv[],
char *help)
361 MPI_Comm_size (comm_dh, &np_dh);
362 MPI_Comm_rank (comm_dh, &myid_dh);
363 openLogfile_dh (argc, argv);
366 Mem_dhCreate (&mem_dh);
371 TimeLog_dhCreate (&tlog_dh);
374 if (parser_dh == NULL)
376 Parser_dhCreate (&parser_dh);
379 Parser_dhInit (parser_dh, argc, argv);
381 if (Parser_dhHasSwitch (parser_dh,
"-sig_dh"))
386 if (Parser_dhHasSwitch (parser_dh,
"-help"))
389 printf (
"%s\n\n", help);
392 if (Parser_dhHasSwitch (parser_dh,
"-logFuncsToFile"))
394 logFuncsToFile =
true;
396 if (Parser_dhHasSwitch (parser_dh,
"-logFuncsToStderr"))
398 logFuncsToStderr =
true;
401 EuclidIsActive =
true;
409 #define __FUNC__ "EuclidFinalize"
418 if (parser_dh != NULL)
420 Parser_dhDestroy (parser_dh);
425 TimeLog_dhDestroy (tlog_dh);
430 Mem_dhPrint (mem_dh, logFile,
true);
436 Mem_dhDestroy (mem_dh);
444 EuclidIsActive =
false;
454 #define __FUNC__ "printf_dh"
456 printf_dh (
char *fmt, ...)
458 START_FUNC_DH va_list args;
459 char *buf = msgBuf_dh;
461 va_start (args, fmt);
462 vsprintf (buf, fmt, args);
465 fprintf (stdout,
"%s", buf);
471 #define __FUNC__ "fprintf_dh"
473 fprintf_dh (FILE * fp,
char *fmt, ...)
475 START_FUNC_DH va_list args;
476 char *buf = msgBuf_dh;
478 va_start (args, fmt);
479 vsprintf (buf, fmt, args);
482 fprintf (fp,
"%s", buf);
489 #define __FUNC__ "echoInvocation_dh"
491 echoInvocation_dh (MPI_Comm comm,
char *prefix,
int argc,
char *argv[])
493 START_FUNC_DH
int i, id;
495 MPI_Comm_rank (comm, &
id);
499 printf_dh (
"\n%s ", prefix);
506 printf_dh (
"program invocation: ");
507 for (i = 0; i < argc; ++i)
509 printf_dh (
"%s ", argv[i]);