Peano
Loading...
Searching...
No Matches
NonCriticalAssertions.cpp
Go to the documentation of this file.
2
3#include "tarch/logging/Log.h"
6#include "tarch/mpi/Rank.h"
8#include "tarch/Assertions.h"
9
10
12
13
14namespace {
19 int rankWhichHasSetNonCriticalAssertion = -1;
20
25 tarch::multicore::BooleanSemaphore assertionSemaphore;
26
27 #if defined(Parallel)
32 int assertionExchangeTag;
33 #endif
34
35 bool useNonCriticalAssertions = true;
36}
37
38
40 useNonCriticalAssertions = value;
41}
42
43
45 #if defined(Parallel)
46 tarch::mpi::Rank::releaseTag( assertionExchangeTag );
47 #endif
48}
49
50
52 #if defined(Parallel)
53 assertionExchangeTag = tarch::mpi::Rank::reserveFreeTag( "mpi::noncriticalassertion" );
54 #endif
55}
56
57
58void tarch::triggerNonCriticalAssertion( std::string file, int line, std::string expression, std::string parameterValuePairs ) {
59 static tarch::logging::Log _log("tarch");
60
61 tarch::multicore::Lock lock( assertionSemaphore );
62
63 if (rankWhichHasSetNonCriticalAssertion>=0 and useNonCriticalAssertions) {
64 logDebug( "triggerNonCriticalAssertion(...)", "noncritical assertion " << expression << " failed in (" << file << ":" << line << ")" );
65 //logError( "triggerNonCriticalAssertion(...)", parameterValuePairs );
66 logDebug( "triggerNonCriticalAssertion(...)", "there has been a non-critical assertion before, so node should already be in shutdown mode" );
67 }
68 if (rankWhichHasSetNonCriticalAssertion<0 and useNonCriticalAssertions) {
69 logError( "triggerNonCriticalAssertion(...)", "noncritical assertion " << expression << " failed in (" << file << ":" << line << ")" );
70 logError( "triggerNonCriticalAssertion(...)", parameterValuePairs );
71 logError( "triggerNonCriticalAssertion(...)", "inform rank 0 to dump solution and to shutdown application" );
72
73 rankWhichHasSetNonCriticalAssertion = tarch::mpi::Rank::getInstance().getRank();
74
75 if (not tarch::mpi::Rank::getInstance().isGlobalMaster()) {
76 #if defined(Parallel)
78 tarch::mpi::IntegerMessage message( rank );
80 message,
82 assertionExchangeTag,
83 tarch::mpi::Rank::getInstance().getCommunicator()
84 );
85 #endif
86 }
87 }
88}
89
90
92 #if defined(Parallel)
93 static tarch::logging::Log _log("tarch");
94
95 if (rankWhichHasSetNonCriticalAssertion<0) {
96 int flag = 0;
97 MPI_Status status;
98 MPI_Iprobe(MPI_ANY_SOURCE, assertionExchangeTag, tarch::mpi::Rank::getInstance().getCommunicator(), &flag, &status );
99 if (flag) {
102 message,
103 status.MPI_SOURCE,
104 assertionExchangeTag,
106 );
107 rankWhichHasSetNonCriticalAssertion = message.getValue();
108 logError( "triggerNonCriticalAssertion(...)", "received non-critical assertion from rank " << status.MPI_SOURCE );
109 }
110 }
111 #endif
112
113 return rankWhichHasSetNonCriticalAssertion>=0;
114}
#define logError(methodName, logMacroMessageStream)
Wrapper macro around tarch::tarch::logging::Log to improve logging.
Definition Log.h:464
#define logDebug(methodName, logMacroMessageStream)
Definition Log.h:50
Log Device.
Definition Log.h:516
static int getGlobalMasterRank()
Get the global master.
Definition Rank.cpp:415
static Rank & getInstance()
This operation returns the singleton instance.
Definition Rank.cpp:539
int getRank() const
Return rank of this node.
Definition Rank.cpp:529
static int reserveFreeTag(const std::string &fullQualifiedMessageName, int numberOfTags=1)
Return a Free Tag.
Definition Rank.cpp:39
static void releaseTag(int tag)
Definition Rank.cpp:32
MPI_Comm getCommunicator() const
Definition Rank.cpp:545
Create a lock around a boolean semaphore region.
Definition Lock.h:19
tarch::logging::Log _log("exahype2::fv")
bool hasNonCriticalAssertionBeenViolated()
void shutdownNonCriticalAssertionEnvironment()
peano4::shutdownParallelEnvironment().
void initNonCriticalAssertionEnvironment()
Register the assertion tag from the global communicator.
void enableNonCriticalAssertions(bool value)
Switch noncritical assertions on/off.
void triggerNonCriticalAssertion(std::string file, int line, std::string expression, std::string parameterValuePairs)
Trigger a non-critical assertion.
static void receive(tarch::mpi::IntegerMessage &buffer, int source, int tag, MPI_Comm communicator)
static void send(const tarch::mpi::IntegerMessage &buffer, int destination, int tag, MPI_Comm communicator)
In DaStGen (the first version), I had a non-static version of the send as well as the receive.