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
303 void reduce(
304 const void *sendbuf, void *recvbuf, int count,
305 MPI_Datatype datatype,
306 MPI_Op op, int root,
307 std::function<void()> waitor = []() -> void {}
308 );
309 #endif
310
319 bool isMessageInQueue(int tag) const;
320
325 void logStatus() const;
326
333 static Rank& getInstance();
334
338 virtual ~Rank();
339
367 bool init(int* argc, char*** argv);
368
390 void shutdown();
391
398 int getRank() const;
399
412
413 #ifdef Parallel
417 MPI_Comm getCommunicator() const;
418 #endif
419
423 int getNumberOfRanks() const;
424
432 bool isGlobalMaster() const;
433
453 const std::string& className,
454 const std::string& methodName,
455 int communicationPartnerRank,
456 int tag,
457 int numberOfExpectedMessages = 1,
458 const std::string& comment = ""
459 );
460
476 const std::string& className,
477 const std::string& methodName,
478 int communicationPartnerRank,
479 int tag,
480 int numberOfExpectedMessages = 1
481 );
482
484
486
488
492 void ensureThatMessageQueuesAreEmpty( int fromRank, int tag );
493
498
504
505 bool isInitialised() const;
506
514 void setTimeOutWarning( int valueInSeconds );
515
530 void setDeadlockTimeOut( int valueInSeconds );
531
532 #ifdef Parallel
536 void setCommunicator( MPI_Comm communicator, bool recomputeRankAndWorld=true );
537 #endif
538
539 void suspendTimeouts( bool timeoutsDisabled );
540
547 static void abort(int errorCode);
548
561
562};
563
Log Device.
Definition Log.h:516
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 {})
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