IOR
aiori-debug.h
Go to the documentation of this file.
1 #ifndef _AIORI_UTIL_H
2 #define _AIORI_UTIL_H
3 
4 /* This file contains only debug relevant helpers */
5 
6 #include <stdio.h>
7 #include <mpi.h>
8 
9 /* output log file */
10 extern FILE * out_logfile;
11 /* verbosity level */
12 extern int verbose;
13 /* treat warnings as errors */
14 extern int aiori_warning_as_errors;
15 
16 #define FAIL(...) FailMessage(rank, ERROR_LOCATION, __VA_ARGS__)
17 void FailMessage(int rank, const char *location, char *format, ...);
18 
19 /* display simple warning message and reset member value to default */
20 #define WARN_RESET(MSG, TO_STRUCT_PTR, FROM_STRUCT_PTR, MEMBER) do { \
21  (TO_STRUCT_PTR)->MEMBER = (FROM_STRUCT_PTR)->MEMBER; \
22  if (rank == 0) { \
23  fprintf(out_logfile, "WARNING: %s. Using value of %d.\n", \
24  MSG, (TO_STRUCT_PTR)->MEMBER); \
25  } \
26  fflush(out_logfile); \
27 } while (0)
28 
29 /* display warning message with format string */
30 #define WARNF(FORMAT, ...) do { \
31  if(aiori_warning_as_errors){ \
32  ERRF(FORMAT, __VA_ARGS__); \
33  } \
34  if (verbose > VERBOSE_2) { \
35  fprintf(out_logfile, "WARNING: " FORMAT ", (%s:%d).\n", \
36  __VA_ARGS__, __FILE__, __LINE__); \
37  } else { \
38  fprintf(out_logfile, "WARNING: " FORMAT "\n", \
39  __VA_ARGS__); \
40  } \
41  fflush(out_logfile); \
42 } while (0)
43 
44 /* display simple warning message */
45 #define WARN(MSG) do { \
46  WARNF("%s", MSG); \
47 } while (0)
48 
49 /* display info message with format string */
50 #define INFOF(FORMAT, ...) do { \
51  if (verbose > VERBOSE_2) { \
52  fprintf(out_logfile, "INFO: " FORMAT ", (%s:%d).\n", \
53  __VA_ARGS__, __FILE__, __LINE__); \
54  } else { \
55  fprintf(out_logfile, "INFO: " FORMAT "\n", \
56  __VA_ARGS__); \
57  } \
58  fflush(out_logfile); \
59 } while (0)
60 
61 /* display simple info message */
62 #define INFO(MSG) do { \
63  INFOF("%s", MSG); \
64 } while (0)
65 
66 /* display error message with format string and terminate execution */
67 #define ERRF(FORMAT, ...) do { \
68  fprintf(out_logfile, "ERROR: " FORMAT ", (%s:%d)\n", \
69  __VA_ARGS__, __FILE__, __LINE__); \
70  fflush(out_logfile); \
71  MPI_Abort(MPI_COMM_WORLD, -1); \
72 } while (0)
73 
74 /* display simple error message and terminate execution */
75 #define ERR(MSG) do { \
76  ERRF("%s", MSG); \
77 } while (0)
78 
79 /* if MPI_STATUS indicates error, display error message with format */
80 /* string and error string from MPI_STATUS and terminate execution */
81 #define MPI_CHECKF(MPI_STATUS, FORMAT, ...) do { \
82  char resultString[MPI_MAX_ERROR_STRING]; \
83  int resultLength; \
84  int _MPI_STATUS = (MPI_STATUS); \
85  \
86  if (_MPI_STATUS != MPI_SUCCESS) { \
87  MPI_Error_string(_MPI_STATUS, resultString, &resultLength); \
88  fprintf(out_logfile, "ERROR: " FORMAT ", MPI %s, (%s:%d)\n", \
89  __VA_ARGS__, resultString, __FILE__, __LINE__); \
90  fflush(out_logfile); \
91  MPI_Abort(MPI_COMM_WORLD, -1); \
92  } \
93 } while(0)
94 
95 /* if MPI_STATUS indicates error, display simple error message with */
96 /* error string from MPI_STATUS and terminate execution */
97 #define MPI_CHECK(MPI_STATUS, MSG) do { \
98  MPI_CHECKF(MPI_STATUS, "%s", MSG); \
99 } while(0)
100 
101 #endif
void FailMessage(int rank, const char *location, char *format,...)
Definition: utilities.c:247
FILE * out_logfile
Definition: utilities.c:74
int verbose
Definition: utilities.c:72
int aiori_warning_as_errors
Definition: ior.c:93
int rank
Definition: utilities.c:70