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 #ifdef Parallel
25 std::string MPIStatusToString( const MPI_Status& status );
26
27 std::string MPIReturnValueToString( int result );
28 #endif
29 }
30}
31
59 public:
60 static const int DEADLOCK_EXIT_CODE = -2;
61
62 private:
67
69
74
78 int _rank;
79
84
85 #ifdef Parallel
89 MPI_Comm _communicator;
90 #endif
91
110 std::chrono::seconds _timeOutWarning;
111
118 std::chrono::seconds _deadlockTimeOut;
119
120 std::chrono::system_clock::time_point _globalTimeOutWarning;
121 std::chrono::system_clock::time_point _globalTimeOutDeadlock;
122
131
135 static int _maxTags;
136
140 static int _tagCounter;
141
147 Rank();
148
152 Rank( const Rank& node ) = delete;
153
168
169 public:
176 static bool validateMaxTagIsSupported();
177
199 static int reserveFreeTag(const std::string& fullQualifiedMessageName, int numberOfTags = 1);
200 static void releaseTag(int tag);
201
234 void barrier(std::function<void()> waitor = []() -> void {} );
235
236 #ifdef Parallel
300 void allReduce(
301 const void *sendbuf, void *recvbuf, int count,
302 MPI_Datatype datatype,
303 MPI_Op op,
304 std::function<void()> waitor = []() -> void {}
305 );
306
307
311 void reduce(
312 const void *sendbuf, void *recvbuf, int count,
313 MPI_Datatype datatype,
314 MPI_Op op, int root,
315 std::function<void()> waitor = []() -> void {}
316 );
317 #endif
318
327 bool isMessageInQueue(int tag) const;
328
333 void logStatus() const;
334
341 static Rank& getInstance();
342
346 virtual ~Rank();
347
375 bool init(int* argc, char*** argv);
376
398 void shutdown();
399
406 int getRank() const;
407
419 static int getGlobalMasterRank();
420
421 #ifdef Parallel
425 MPI_Comm getCommunicator() const;
426 #endif
427
431 int getNumberOfRanks() const;
432
440 bool isGlobalMaster() const;
441
461 const std::string& className,
462 const std::string& methodName,
463 int communicationPartnerRank,
464 int tag,
465 int numberOfExpectedMessages = 1,
466 const std::string& comment = ""
467 );
468
484 const std::string& className,
485 const std::string& methodName,
486 int communicationPartnerRank,
487 int tag,
488 int numberOfExpectedMessages = 1
489 );
490
492
493 bool exceededDeadlockThreshold() const;
494
495 void plotMessageQueues();
496
500 void ensureThatMessageQueuesAreEmpty( int fromRank, int tag );
501
506
512
513 bool isInitialised() const;
514
522 void setTimeOutWarning( int valueInSeconds );
523
531 void setDeadlockTimeOut( int valueInSeconds );
532
533 #ifdef Parallel
537 void setCommunicator( MPI_Comm communicator, bool recomputeRankAndWorld=true );
538 #endif
539
540 void suspendTimeouts( bool timeoutsDisabled );
541
548 static void abort(int errorCode);
549};
550
Log Device.
Definition Log.h:516
Represents a program instance within a cluster.
Definition Rank.h:58
void setCommunicator(MPI_Comm communicator, bool recomputeRankAndWorld=true)
Set communicator to be used by Peano.
Definition Rank.cpp:576
Rank()
The standard constructor assignes the attributes default values and checks whether the program is com...
Definition Rank.cpp:263
Rank(const Rank &node)=delete
You may not copy a singleton.
std::chrono::system_clock::time_point _globalTimeOutDeadlock
Definition Rank.h:121
void setDeadlockTimeOut(int valueInSeconds)
Set deadlock time out.
Definition Rank.cpp:566
static int _tagCounter
Count the tags that have already been handed out.
Definition Rank.h:140
static int getGlobalMasterRank()
Get the global master.
Definition Rank.cpp:415
int getNumberOfRanks() const
Definition Rank.cpp:552
bool isInitialised() const
Definition Rank.cpp:69
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.
Definition Rank.cpp:124
bool isGlobalMaster() const
Is this node the global master process, i.e.
Definition Rank.cpp:420
void setDeadlockWarningTimeStamp()
Memorise global timeout.
Definition Rank.cpp:193
bool exceededTimeOutWarningThreshold() const
Definition Rank.cpp:106
static int _maxTags
Set by init() and actually stores the number of valid tags.
Definition Rank.h:135
MPI_Comm _communicator
MPI Communicator this process belongs to.
Definition Rank.h:89
void writeTimeOutWarning(const std::string &className, const std::string &methodName, int communicationPartnerRank, int tag, int numberOfExpectedMessages=1)
Writes a warning if relevant.
Definition Rank.cpp:148
int _numberOfProcessors
Number of processors available.
Definition Rank.h:83
std::chrono::system_clock::time_point _globalTimeOutWarning
Definition Rank.h:120
void setDeadlockTimeOutTimeStamp()
Definition Rank.cpp:198
void ensureThatMessageQueuesAreEmpty(int fromRank, int tag)
Ensure that there are no messages anymore from the specified rank.
Definition Rank.cpp:74
int _rank
Rank (id) of this process.
Definition Rank.h:78
void reduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, std::function< void()> waitor=[]() -> void {})
Definition Rank.cpp:318
static Rank & getInstance()
This operation returns the singleton instance.
Definition Rank.cpp:539
std::chrono::seconds _deadlockTimeOut
Time to timeout.
Definition Rank.h:118
bool isMessageInQueue(int tag) const
In older DaStGen version, I tried to find out whether a particular message type is in the MPI queue.
Definition Rank.cpp:382
void setTimeOutWarning(int valueInSeconds)
Set time out warning.
Definition Rank.cpp:560
bool _areTimeoutsEnabled
Global toggle to enable/disable timeouts.
Definition Rank.h:130
int getRank() const
Return rank of this node.
Definition Rank.cpp:529
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.
Definition Rank.cpp:472
void allReduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, std::function< void()> waitor=[]() -> void {})
Definition Rank.cpp:284
void suspendTimeouts(bool timeoutsDisabled)
Definition Rank.cpp:203
static tarch::logging::Log _log
Logging device.
Definition Rank.h:66
std::chrono::seconds _timeOutWarning
Timeout warning.
Definition Rank.h:110
void barrier(std::function< void()> waitor=[]() -> void {})
Definition Rank.cpp:352
bool _initIsCalled
Is set true if init() is called.
Definition Rank.h:73
void logStatus() const
Logs the status of the process onto the log device.
Definition Rank.cpp:430
static bool validateMaxTagIsSupported()
Just try to find out if a tag is actually supported.
Definition Rank.cpp:454
static int reserveFreeTag(const std::string &fullQualifiedMessageName, int numberOfTags=1)
Return a Free Tag.
Definition Rank.cpp:39
void plotMessageQueues()
Definition Rank.cpp:86
virtual ~Rank()
The standard destructor calls MPI_Finalize().
Definition Rank.cpp:281
static void releaseTag(int tag)
Definition Rank.cpp:32
bool exceededDeadlockThreshold() const
Definition Rank.cpp:115
void shutdown()
Shuts down the application.
Definition Rank.cpp:395
static void abort(int errorCode)
A proper abort in an MPI context has to use MPI_Abort.
Definition Rank.cpp:592
MPI_Comm getCommunicator() const
Definition Rank.cpp:545
static Rank _singleton
Definition Rank.h:68
static const int DEADLOCK_EXIT_CODE
Definition Rank.h:60
std::string MPIStatusToString(const MPI_Status &status)
Returns a string representation of the mpi status.
Definition Rank.cpp:250
std::string MPIReturnValueToString(int result)
Definition Rank.cpp:209
Have to include this header, as I need access to the SYCL_EXTERNAL keyword.
Definition accelerator.h:19