Commit 12ad4a22 authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Add no-fail wrapper for MPI calls.

parent 481cd34d
......@@ -56,8 +56,13 @@
#include <config.h>
#endif
#include <stdio.h>
#include <cfortran.h>
#ifdef USE_MPI
#include <mpi.h>
#endif
#include "core.h"
#include "symprefix.h"
......@@ -116,6 +121,43 @@ FCALLSCSUB0(SymPrefix(restore_default_abort_handler),
SYMPREFIX(RESTORE_DEFAULT_ABORT_HNDL),
symprefix(restore_default_abort_hndl))
#ifdef USE_MPI
static inline int
callsToMPIAreAllowed()
{
int init_flag = 0, finished_flag = 0;
return MPI_Initialized(&init_flag) == MPI_SUCCESS && init_flag
&& MPI_Finalized(&finished_flag) == MPI_SUCCESS && !finished_flag;
}
static inline int
getMPICommWorldRank()
{
int rank = -1;
if (callsToMPIAreAllowed())
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
return rank;
}
void
SymPrefix(xmpi)(int errcode, const char *source, int line)
{
char errorString[2][MPI_MAX_ERROR_STRING + 1];
int lenES, lenEC, errorClass, rank = getMPICommWorldRank();
MPI_Error_class(errcode, &errorClass);
MPI_Error_string(errorClass, errorString[0], &lenEC);
MPI_Error_string(errcode, errorString[1], &lenES);
errorString[0][MPI_MAX_ERROR_STRING] = 0;
errorString[1][MPI_MAX_ERROR_STRING] = 0;
fprintf(stderr, "MPI ERROR, pe%d, %s, line %d,"
"errorClass: \"%*s\""
"errorString: \"%*s\"\n",
rank, source, line,
lenEC, errorString[0], lenES, errorString[1]);
MPI_Abort(MPI_COMM_WORLD, 1);
}
#endif
/*
* Local Variables:
* license-project-url: "https://www.dkrz.de/redmine/projects/show/scales-ppm"
......
......@@ -46,6 +46,10 @@
#include <stdio.h>
#include <stdlib.h>
#ifdef USE_MPI
#include <mpi.h>
#endif
#include "core/symprefix.h"
void *
......@@ -79,6 +83,16 @@ SymPrefix(xfputc)(int c, FILE *stream, const char *source, int line);
#define xfputc(c,stream) SymPrefix(xfputc)((c),(stream), __FILE__, __LINE__)
#ifdef USE_MPI
void SymPrefix(xmpi)(int errcode, const char *source, int line);
#define xmpi(errcode) \
do { \
if (errcode == MPI_SUCCESS) ; else \
PPM_xmpi(errcode, __FILE__, __LINE__); \
} while (0)
#endif
#endif
/*
* Local Variables:
......
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