Commit 92a1f01d authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Make abort wrapper overridable.

parent b01623a3
......@@ -7,10 +7,7 @@
#include <stdarg.h>
#include <errno.h>
#ifdef USE_MPI
#include "pio_util.h"
#include <mpi.h>
#endif
#include "namespace.h"
int _ExitOnError = 1; /* If set to 1, exit on error */
int _Verbose = 1; /* If set to 1, errors are reported */
......@@ -53,39 +50,35 @@ void Error_(const char *caller, const char *fmt, ...)
if ( _ExitOnError ) exit(EXIT_FAILURE);
}
typedef void (*cdiAbortCFunc)(const char * caller, const char * filename,
const char *functionname, int line,
const char * errorString, va_list ap)
__attribute__((noreturn));
void cdiAbortC(const char * caller, const char * filename,
const char *functionname, int line,
const char * errorString, ... )
{
va_list ap;
va_start(ap, errorString);
#ifdef USE_MPI
{
int rank = getMPICommWorldRank();
fprintf(stderr, "ERROR, pe%d in %s, %s, line %d%s"
"%s\nerrorString: \"", rank, functionname, filename, line,
caller?", called from ":"", caller?caller:"");
}
vfprintf(stderr, errorString, ap);
fputs("\"\n", stderr);
if (callsToMPIAreAllowed())
MPI_Abort(MPI_COMM_WORLD, 1);
else
abort();
#else
cdiAbortCFunc cdiAbortC_p = namespaceSwitchGet(NSSWITCH_ABORT);
cdiAbortC_p(caller, filename, functionname, line, errorString, ap);
va_end(ap);
}
void
cdiAbortC_serial(const char *caller, const char *filename,
const char *functionname, int line,
const char *errorString, va_list ap)
{
fprintf(stderr, "ERROR, %s, %s, line %d%s%s\nerrorString: \"",
functionname, filename, line, caller?", called from ":"",
caller?caller:"");
vfprintf(stderr, errorString, ap);
fputs("\"\n", stderr);
#endif
exit ( EXIT_FAILURE );
va_end(ap);
exit(EXIT_FAILURE);
}
void Warning_(const char *caller, const char *fmt, ...)
{
va_list args;
......
#ifndef _ERROR_H
#define _ERROR_H
#include <stdarg.h>
#include <stdlib.h>
#ifndef WITH_CALLER_NAME
#define WITH_CALLER_NAME
#endif
......@@ -55,6 +58,12 @@ void cdiAbortC(const char *caller, const char *filename,
xabort("assertion failed");} \
} while(0)
void
cdiAbortC_serial(const char *caller, const char *filename,
const char *functionname, int line,
const char *errorString, va_list ap)
__attribute__((noreturn));
#endif /* _ERROR_H */
/*
* Local Variables:
......
......@@ -6,12 +6,14 @@
#include "resource_handle.h"
#include "pio_util.h"
#include "serialize.h"
#include "error.h"
static int nNamespaces = 1;
static int activeNamespace = 0;
#define defaultSwitches { \
serializeGetSizeInCore, \
#define defaultSwitches { \
cdiAbortC_serial, \
serializeGetSizeInCore, \
serializePackInCore, \
serializeUnpackInCore, \
}
......
......@@ -16,6 +16,7 @@ typedef struct {
enum namespaceSwitch
{
NSSWITCH_NO_SUCH_SWITCH = -1,
NSSWITCH_ABORT,
NSSWITCH_SERIALIZE_GET_SIZE,
NSSWITCH_SERIALIZE_PACK,
NSSWITCH_SERIALIZE_UNPACK,
......
......@@ -817,6 +817,7 @@ pioInit(MPI_Comm commGlob, int nProcsIO, int IOMode,
if ( commInqIsProcIO ())
{
serializeSetMPI();
namespaceSwitchSet(NSSWITCH_ABORT, cdiAbortC_MPI);
IOServer ();
namespaceDelete(0);
commDestroy ();
......
......@@ -20,6 +20,30 @@ char commands[][13] = { "FINALIZE\0",
#endif
/*****************************************************************************/
#ifdef USE_MPI
void
cdiAbortC_MPI(const char *caller, const char *filename,
const char *functionname, int line,
const char *errorString, va_list ap)
{
{
int rank = getMPICommWorldRank();
fprintf(stderr, "ERROR, pe%d in %s, %s, line %d%s"
"%s\nerrorString: \"", rank, functionname, filename, line,
caller?", called from ":"", caller?caller:"");
}
vfprintf(stderr, errorString, ap);
fputs("\"\n", stderr);
if (callsToMPIAreAllowed())
MPI_Abort(MPI_COMM_WORLD, 1);
else
abort();
exit(EXIT_FAILURE);
va_end(ap);
}
#endif
/*****************************************************************************/
void * pcdiXmalloc ( size_t size, const char *filename, const char *functionname,
......
......@@ -19,6 +19,13 @@
#define debugString "#####"
#ifdef USE_MPI
void
cdiAbortC_MPI(const char * caller, const char * filename,
const char *functionname, int line,
const char * errorString, va_list ap)
__attribute__((noreturn));
#endif
#ifdef USE_MPI
static inline int
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment