From 145c71f7c394bde881114f946fb450bc64f60780 Mon Sep 17 00:00:00 2001 From: "Julian M. Kunkel" Date: Sun, 28 Jun 2020 17:16:35 +0100 Subject: [PATCH] Trivial cleanup: Extracted debug-related stuff into new header. --- src/aiori-debug.h | 117 ++++++++++++++++++++++++++++++++++++++++++++++ src/aiori.h | 1 + src/iordef.h | 115 --------------------------------------------- src/utilities.c | 5 +- src/utilities.h | 3 -- 5 files changed, 120 insertions(+), 121 deletions(-) create mode 100644 src/aiori-debug.h diff --git a/src/aiori-debug.h b/src/aiori-debug.h new file mode 100644 index 0000000..0fa20d6 --- /dev/null +++ b/src/aiori-debug.h @@ -0,0 +1,117 @@ +#ifndef _AIORI_UTIL_H +#define _AIORI_UTIL_H + +/* This file contains only debug relevant helpers */ + +#include + +extern FILE * out_logfile; +extern int verbose; /* verbose output */ + +#define FAIL(...) FailMessage(rank, ERROR_LOCATION, __VA_ARGS__) +void FailMessage(int rank, const char *location, char *format, ...); + +/******************************** M A C R O S *********************************/ + +/******************************************************************************/ +/* + * WARN_RESET will display a custom error message and set value to default + */ +#define WARN_RESET(MSG, TO_STRUCT_PTR, FROM_STRUCT_PTR, MEMBER) do { \ + (TO_STRUCT_PTR)->MEMBER = (FROM_STRUCT_PTR)->MEMBER; \ + if (rank == 0) { \ + fprintf(out_logfile, "WARNING: %s. Using value of %d.\n", \ + MSG, (TO_STRUCT_PTR)->MEMBER); \ + } \ + fflush(out_logfile); \ +} while (0) + +extern int aiori_warning_as_errors; + +#define WARN(MSG) do { \ + if(aiori_warning_as_errors){ ERR(MSG); } \ + if (verbose > VERBOSE_2) { \ + fprintf(out_logfile, "WARNING: %s, (%s:%d).\n", \ + MSG, __FILE__, __LINE__); \ + } else { \ + fprintf(out_logfile, "WARNING: %s.\n", MSG); \ + } \ + fflush(out_logfile); \ +} while (0) + + +/* warning with format string and errno printed */ +#define EWARNF(FORMAT, ...) do { \ + if(aiori_warning_as_errors){ ERRF(FORMAT, __VA_ARGS__); } \ + if (verbose > VERBOSE_2) { \ + fprintf(out_logfile, "WARNING: " FORMAT ", (%s:%d).\n", \ + __VA_ARGS__, __FILE__, __LINE__); \ + } else { \ + fprintf(out_logfile, "WARNING: " FORMAT "\n", \ + __VA_ARGS__); \ + } \ + fflush(out_logfile); \ +} while (0) + + +/* warning with errno printed */ +#define EWARN(MSG) do { \ + EWARNF("%s", MSG); \ +} while (0) + + +/* display error message with format string and terminate execution */ +#define ERRF(FORMAT, ...) do { \ + fprintf(out_logfile, "ERROR: " FORMAT ", (%s:%d)\n", \ + __VA_ARGS__, __FILE__, __LINE__); \ + fflush(out_logfile); \ + MPI_Abort(MPI_COMM_WORLD, -1); \ +} while (0) + + +/* display error message and terminate execution */ +#define ERR_ERRNO(MSG) do { \ + ERRF("%s", MSG); \ +} while (0) + + +/* display a simple error message (i.e. errno is not set) and terminate execution */ +#define ERR(MSG) do { \ + fprintf(out_logfile, "ERROR: %s, (%s:%d)\n", \ + MSG, __FILE__, __LINE__); \ + fflush(out_logfile); \ + MPI_Abort(MPI_COMM_WORLD, -1); \ +} while (0) + + +/******************************************************************************/ +/* + * MPI_CHECKF will display a custom format string as well as an error string + * from the MPI_STATUS and then exit the program + */ + +#define MPI_CHECKF(MPI_STATUS, FORMAT, ...) do { \ + char resultString[MPI_MAX_ERROR_STRING]; \ + int resultLength; \ + \ + if (MPI_STATUS != MPI_SUCCESS) { \ + MPI_Error_string(MPI_STATUS, resultString, &resultLength); \ + fprintf(out_logfile, "ERROR: " FORMAT ", MPI %s, (%s:%d)\n", \ + __VA_ARGS__, resultString, __FILE__, __LINE__); \ + fflush(out_logfile); \ + MPI_Abort(MPI_COMM_WORLD, -1); \ + } \ +} while(0) + + +/******************************************************************************/ +/* + * MPI_CHECK will display a custom error message as well as an error string + * from the MPI_STATUS and then exit the program + */ + +#define MPI_CHECK(MPI_STATUS, MSG) do { \ + MPI_CHECKF(MPI_STATUS, "%s", MSG); \ +} while(0) + +#endif diff --git a/src/aiori.h b/src/aiori.h index ad10e4d..e5f0e5e 100755 --- a/src/aiori.h +++ b/src/aiori.h @@ -25,6 +25,7 @@ #include #include "iordef.h" /* IOR Definitions */ +#include "aiori-debug.h" #include "option.h" /*************************** D E F I N I T I O N S ****************************/ diff --git a/src/iordef.h b/src/iordef.h index 0805208..eb10306 100755 --- a/src/iordef.h +++ b/src/iordef.h @@ -18,8 +18,6 @@ #include #include #include -#include -#include #ifdef _WIN32 # define _CRT_SECURE_NO_WARNINGS @@ -52,13 +50,6 @@ # include #endif -/************************** D E C L A R A T I O N S ***************************/ - -extern int numTasks; /* MPI variables */ -extern int rank; -extern int rankOffset; -extern int verbose; /* verbose output */ - /*************************** D E F I N I T I O N S ****************************/ enum OutputFormat_t{ @@ -120,112 +111,6 @@ typedef long long int IOR_size_t; #define IOR_format "%016llx" -extern FILE * out_logfile; - -/******************************** M A C R O S *********************************/ - -/******************************************************************************/ -/* - * WARN_RESET will display a custom error message and set value to default - */ -#define WARN_RESET(MSG, TO_STRUCT_PTR, FROM_STRUCT_PTR, MEMBER) do { \ - (TO_STRUCT_PTR)->MEMBER = (FROM_STRUCT_PTR)->MEMBER; \ - if (rank == 0) { \ - fprintf(out_logfile, "ior WARNING: %s. Using value of %d.\n", \ - MSG, (TO_STRUCT_PTR)->MEMBER); \ - } \ - fflush(out_logfile); \ -} while (0) - -extern int aiori_warning_as_errors; - -#define WARN(MSG) do { \ - if(aiori_warning_as_errors){ ERR(MSG); } \ - if (verbose > VERBOSE_2) { \ - fprintf(out_logfile, "ior WARNING: %s, (%s:%d).\n", \ - MSG, __FILE__, __LINE__); \ - } else { \ - fprintf(out_logfile, "ior WARNING: %s.\n", MSG); \ - } \ - fflush(out_logfile); \ -} while (0) - - -/* warning with format string and errno printed */ -#define EWARNF(FORMAT, ...) do { \ - if(aiori_warning_as_errors){ ERRF(FORMAT, __VA_ARGS__); } \ - if (verbose > VERBOSE_2) { \ - fprintf(out_logfile, "ior WARNING: " FORMAT ", (%s:%d).\n", \ - __VA_ARGS__, __FILE__, __LINE__); \ - } else { \ - fprintf(out_logfile, "ior WARNING: " FORMAT "\n", \ - __VA_ARGS__); \ - } \ - fflush(out_logfile); \ -} while (0) - - -/* warning with errno printed */ -#define EWARN(MSG) do { \ - EWARNF("%s", MSG); \ -} while (0) - - -/* display error message with format string and terminate execution */ -#define ERRF(FORMAT, ...) do { \ - fprintf(out_logfile, "ior ERROR: " FORMAT ", (%s:%d)\n", \ - __VA_ARGS__, __FILE__, __LINE__); \ - fflush(out_logfile); \ - MPI_Abort(MPI_COMM_WORLD, -1); \ -} while (0) - - -/* display error message and terminate execution */ -#define ERR_ERRNO(MSG) do { \ - ERRF("%s", MSG); \ -} while (0) - - -/* display a simple error message (i.e. errno is not set) and terminate execution */ -#define ERR(MSG) do { \ - fprintf(out_logfile, "ior ERROR: %s, (%s:%d)\n", \ - MSG, __FILE__, __LINE__); \ - fflush(out_logfile); \ - MPI_Abort(MPI_COMM_WORLD, -1); \ -} while (0) - - -/******************************************************************************/ -/* - * MPI_CHECKF will display a custom format string as well as an error string - * from the MPI_STATUS and then exit the program - */ - -#define MPI_CHECKF(MPI_STATUS, FORMAT, ...) do { \ - char resultString[MPI_MAX_ERROR_STRING]; \ - int resultLength; \ - \ - if (MPI_STATUS != MPI_SUCCESS) { \ - MPI_Error_string(MPI_STATUS, resultString, &resultLength); \ - fprintf(out_logfile, "ior ERROR: " FORMAT ", MPI %s, (%s:%d)\n", \ - __VA_ARGS__, resultString, __FILE__, __LINE__); \ - fflush(out_logfile); \ - MPI_Abort(MPI_COMM_WORLD, -1); \ - } \ -} while(0) - - -/******************************************************************************/ -/* - * MPI_CHECK will display a custom error message as well as an error string - * from the MPI_STATUS and then exit the program - */ - -#define MPI_CHECK(MPI_STATUS, MSG) do { \ - MPI_CHECKF(MPI_STATUS, "%s", MSG); \ -} while(0) - - /******************************************************************************/ /* * System info for Windows. diff --git a/src/utilities.c b/src/utilities.c index 715e30d..19ef0d6 100755 --- a/src/utilities.c +++ b/src/utilities.c @@ -81,8 +81,8 @@ void FailMessage(int rank, const char *location, char *format, ...) { va_start(args, format); vsnprintf(msg, 4096, format, args); va_end(args); - fprintf(out_logfile, "%s: Process %d: FAILED in %s, %s: %s\n", - PrintTimestamp(), rank, location, msg, strerror(errno)); + fprintf(out_logfile, "%s: Process %d: FAILED in %s, %s\n", + PrintTimestamp(), rank, location, msg); fflush(out_logfile); MPI_Abort(testComm, 1); } @@ -889,4 +889,3 @@ unsigned long GetProcessorAndCore(int *chip, int *core){ return ((unsigned long)a) | (((unsigned long)d) << 32);; } #endif - diff --git a/src/utilities.h b/src/utilities.h index 32292a4..020f27b 100755 --- a/src/utilities.h +++ b/src/utilities.h @@ -23,7 +23,6 @@ extern int rankOffset; extern int verbose; extern MPI_Comm testComm; extern MPI_Comm mpi_comm_world; -extern FILE * out_logfile; extern FILE * out_resultfile; extern enum OutputFormat_t outputFormat; /* format of the output */ @@ -39,8 +38,6 @@ extern enum OutputFormat_t outputFormat; /* format of the output */ #define ERROR_LOCATION __LINE__ #endif -#define FAIL(...) FailMessage(rank, ERROR_LOCATION, __VA_ARGS__) -void FailMessage(int rank, const char *location, char *format, ...); void* safeMalloc(uint64_t size); void set_o_direct_flag(int *fd);