Peano
Loading...
Searching...
No Matches
Rank.h
Go to the documentation of this file.
1// This file is part of the Peano project. For conditions of distribution and
2// use, please see the copyright notice at www.peano-framework.org
3#pragma once
4
5
6#include "tarch/logging/Log.h"
7
8#include <ctime>
9#include <functional>
10
11
12#include "mpi.h"
13
14
15
16namespace tarch {
17 namespace mpi {
18 class Rank;
19 }
20}
21
49 public:
50 static const int DEADLOCK_EXIT_CODE = -2;
51
52 private:
57
59
64
68 int _rank;
69
74
76
77 #ifdef Parallel
81 MPI_Comm _communicator;
82 #endif
83
102 std::chrono::seconds _timeOutWarning;
103
110 std::chrono::seconds _deadlockTimeOut;
111
112 std::chrono::system_clock::time_point _globalTimeOutWarning;
113 std::chrono::system_clock::time_point _globalTimeOutDeadlock;
114
123
127 static int _maxTags;
128
132 static int _tagCounter;
133
140
144 Rank( const Rank& node ) = delete;
145
160
161 public:
169
191 static int reserveFreeTag(const std::string& fullQualifiedMessageName, int numberOfTags = 1);
192 static void releaseTag(int tag);
193
226 void barrier(std::function<void()> waitor = []() -> void {} );
227
228 #ifdef Parallel
293 const void *sendbuf, void *recvbuf, int count,
294 MPI_Datatype datatype,
295 MPI_Op op,
296 std::function<void()> waitor = []() -> void {}
297 );
298
299
305 void reduce(
306 const void *sendbuf, void *recvbuf, int count,
307 MPI_Datatype datatype,
308 MPI_Op op, int root,
309 std::function<void()> waitor = []() -> void {}
310 );
311 #endif
312
321 bool isMessageInQueue(int tag) const;
322
327 void logStatus() const;
328
335 static Rank& getInstance();
336
340 virtual ~Rank();
341
369 bool init(int* argc, char*** argv);
370
392 void shutdown();
393
400 int getRank() const;
401
414
415 #ifdef Parallel
419 MPI_Comm getCommunicator() const;
420 #endif
421
425 int getNumberOfRanks() const;
426
434 bool isGlobalMaster() const;
435
455 const std::string& className,
456 const std::string& methodName,
457 int communicationPartnerRank,
458 int tag,
459 int numberOfExpectedMessages = 1,
460 const std::string& comment = ""
461 );
462
478 const std::string& className,
479 const std::string& methodName,
480 int communicationPartnerRank,
481 int tag,
482 int numberOfExpectedMessages = 1
483 );
484
486
488
490
494 void ensureThatMessageQueuesAreEmpty( int fromRank, int tag );
495
500
506
507 bool isInitialised() const;
508
516 void setTimeOutWarning( int valueInSeconds );
517
532 void setDeadlockTimeOut( int valueInSeconds );
533
534 #ifdef Parallel
538 void setCommunicator( MPI_Comm communicator, bool recomputeRankAndWorld=true );
539 #endif
540
541 void suspendTimeouts( bool timeoutsDisabled );
542
549 static void abort(int errorCode);
550
563
564};
565
Log Device.
Definition Log.h:517
Represents a program instance within a cluster.
Definition Rank.h:48
void setCommunicator(MPI_Comm communicator, bool recomputeRankAndWorld=true)
Set communicator to be used by Peano.
Rank()
The standard constructor assignes the attributes default values and checks whether the program is com...
Rank(const Rank &node)=delete
You may not copy a singleton.
std::chrono::system_clock::time_point _globalTimeOutDeadlock
Definition Rank.h:113
static bool validateMaxTagIsSupported()
Just try to find out if a tag is actually supported.
int getProvidedThreadLevelSupport() const
Information on supported thread-level support.
void setDeadlockTimeOut(int valueInSeconds)
Set deadlock time out.
static int _tagCounter
Count the tags that have already been handed out.
Definition Rank.h:132
static Rank & getInstance()
This operation returns the singleton instance.
virtual ~Rank()
The standard destructor calls MPI_Finalize().
int getNumberOfRanks() const
bool isInitialised() const
void triggerDeadlockTimeOut(const std::string &className, const std::string &methodName, int communicationPartnerRank, int tag, int numberOfExpectedMessages=1, const std::string &comment="")
Triggers a time out and shuts down the cluster if a timeout is violated.
bool isGlobalMaster() const
Is this node the global master process, i.e.
void setDeadlockWarningTimeStamp()
Memorise global timeout.
bool exceededTimeOutWarningThreshold() const
static int _maxTags
Set by init() and actually stores the number of valid tags.
Definition Rank.h:127
MPI_Comm _communicator
MPI Communicator this process belongs to.
Definition Rank.h:81
void writeTimeOutWarning(const std::string &className, const std::string &methodName, int communicationPartnerRank, int tag, int numberOfExpectedMessages=1)
Writes a warning if relevant.
int _numberOfProcessors
Number of processors available.
Definition Rank.h:73
std::chrono::system_clock::time_point _globalTimeOutWarning
Definition Rank.h:112
static int getGlobalMasterRank()
Get the global master.
void setDeadlockTimeOutTimeStamp()
void ensureThatMessageQueuesAreEmpty(int fromRank, int tag)
Ensure that there are no messages anymore from the specified rank.
int _rank
Rank (id) of this process.
Definition Rank.h:68
void reduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, std::function< void()> waitor=[]() -> void {})
Blocking reduction.
std::chrono::seconds _deadlockTimeOut
Time to timeout.
Definition Rank.h:110
bool isMessageInQueue(int tag) const
In older DaStGen version, I tried to find out whether a particular message type is in the MPI queue.
void setTimeOutWarning(int valueInSeconds)
Set time out warning.
bool _areTimeoutsEnabled
Global toggle to enable/disable timeouts.
Definition Rank.h:122
int getRank() const
Return rank of this node.
void receiveDanglingMessagesFromReceiveBuffers()
Receive any Message Pending in the MPI/Receive Buffers.
bool init(int *argc, char ***argv)
This operation initializes the MPI environment and the program instance.
void allReduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, std::function< void()> waitor=[]() -> void {})
void suspendTimeouts(bool timeoutsDisabled)
static tarch::logging::Log _log
Logging device.
Definition Rank.h:56
std::chrono::seconds _timeOutWarning
Timeout warning.
Definition Rank.h:102
void barrier(std::function< void()> waitor=[]() -> void {})
static int reserveFreeTag(const std::string &fullQualifiedMessageName, int numberOfTags=1)
Return a Free Tag.
bool _initIsCalled
Is set true if init() is called.
Definition Rank.h:63
void logStatus() const
Logs the status of the process onto the log device.
static void releaseTag(int tag)
static Rank _singleton
Definition Rank.h:58
int _providedThreadLevelSupport
Definition Rank.h:75
void plotMessageQueues()
bool exceededDeadlockThreshold() const
void shutdown()
Shuts down the application.
static void abort(int errorCode)
A proper abort in an MPI context has to use MPI_Abort.
MPI_Comm getCommunicator() const
static const int DEADLOCK_EXIT_CODE
Definition Rank.h:50
Have to include this header, as I need access to the SYCL_EXTERNAL keyword.
Definition accelerator.h:19