KratosMultiphysics
KRATOS Multiphysics (Kratos) is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.
|
Wrapper for common MPI calls within Kratos. More...
#include <mpi_data_communicator.h>
Public Member Functions | |
Type Definitions | |
KRATOS_CLASS_POINTER_DEFINITION (MPIDataCommunicator) | |
Pointer definition of MPIDataCommunicator. More... | |
Life Cycle | |
MPIDataCommunicator (MPI_Comm MPIComm) | |
Constructor accepting an MPI_Comm object. More... | |
~MPIDataCommunicator () override | |
Destructor. More... | |
Inquiry | |
int | Rank () const override |
Get the parallel rank for this DataCommunicator. More... | |
int | Size () const override |
Get the parallel size of this DataCommunicator. More... | |
bool | IsDistributed () const override |
Check whether this DataCommunicator is aware of parallelism. More... | |
bool | IsDefinedOnThisRank () const override |
Check whether this DataCommunicator involves the current rank. More... | |
bool | IsNullOnThisRank () const override |
Check whether this DataCommunicator is MPI_COMM_NULL for the current rank. More... | |
const DataCommunicator & | GetSubDataCommunicator (const std::vector< int > &rRanks, const std::string &rNewCommunicatorName) const override |
Get a sub-data communicator. More... | |
Helper functions for error checking in MPI | |
bool | BroadcastErrorIfTrue (bool Condition, const int SourceRank) const override |
This function throws an error on ranks != Sourcerank if Condition evaluates to true. More... | |
bool | BroadcastErrorIfFalse (bool Condition, const int SourceRank) const override |
This function throws an error on ranks != Sourcerank if Condition evaluates to false. More... | |
bool | ErrorIfTrueOnAnyRank (bool Condition) const override |
This function throws an error on ranks where Condition evaluates to false, if it evaluated to true on a different rank. More... | |
bool | ErrorIfFalseOnAnyRank (bool Condition) const override |
This function throws an error on ranks where Condition evaluates to true, if it evaluated to false on a different rank. More... | |
Input and output | |
std::string | Info () const override |
Turn back information as a string. More... | |
void | PrintInfo (std::ostream &rOStream) const override |
Print information about this object. More... | |
void | PrintData (std::ostream &rOStream) const override |
Print object's data. More... | |
Public Member Functions inherited from Kratos::DataCommunicator | |
KRATOS_CLASS_POINTER_DEFINITION (DataCommunicator) | |
Pointer definition of DataCommunicator. More... | |
DataCommunicator () | |
Default constructor. More... | |
virtual | ~DataCommunicator () |
Destructor. More... | |
template<typename TObject > | |
void | Broadcast (TObject &rBroadcastObject, const int SourceRank) const |
Synchronize a buffer to the value held by the broadcasting rank. More... | |
template<typename TObject > | |
TObject | SendRecv (const TObject &rSendObject, const int SendDestination, const int SendTag, const int RecvSource, const int RecvTag) const |
Exchange data with other ranks. More... | |
template<class TObject > | |
TObject | SendRecv (const TObject &rSendObject, const int SendDestination, const int RecvSource) const |
Exchange data with other ranks. More... | |
template<class TObject > | |
void | SendRecv (const TObject &rSendObject, const int SendDestination, const int SendTag, TObject &rRecvObject, const int RecvSource, const int RecvTag) const |
Exchange data with other ranks. More... | |
template<class TObject > | |
void | SendRecv (const TObject &rSendObject, const int SendDestination, TObject &rRecvObject, const int RecvSource) const |
Exchange data with other ranks. More... | |
template<typename TObject > | |
void | Send (const TObject &rSendValues, const int SendDestination, const int SendTag=0) const |
Exchange data with other ranks. More... | |
template<typename TObject > | |
void | Recv (TObject &rRecvObject, const int RecvSource, const int RecvTag=0) const |
Exchange data with other ranks. More... | |
Static Public Member Functions | |
Access | |
static MPI_Comm | GetMPICommunicator (const DataCommunicator &rDataCommunicator) |
Get the underlying MPI_Comm instance. More... | |
Static Public Member Functions inherited from Kratos::DataCommunicator | |
static DataCommunicator & | GetDefault () |
Convenience function to retrieve the current default DataCommunicator. More... | |
static DataCommunicator::UniquePointer | Create () |
Create a new DataCommunicator as a copy of this one. More... | |
Protected Member Functions | |
void | BroadcastImpl (std::string &rBroadcastValues, const int SourceRank) const override |
Synchronize a buffer to the value held by the broadcasting rank (string version). More... | |
std::string | SendRecvImpl (const std::string &rSendValues, const int SendDestination, const int SendTag, const int RecvSource, const int RecvTag) const override |
Exchange data with other ranks (string version). More... | |
void | SendRecvImpl (const std::string &rSendValues, const int SendDestination, const int SendTag, std::string &rRecvValues, const int RecvSource, const int RecvTag) const override |
Exchange data with other ranks (string version). More... | |
void | SendImpl (const std::string &rSendValues, const int SendDestination, const int SendTag=0) const override |
Send data to other ranks (string version). More... | |
void | RecvImpl (std::string &rRecvValues, const int RecvSource, const int RecvTag=0) const override |
Receive data from other ranks (string version). More... | |
Protected Member Functions inherited from Kratos::DataCommunicator | |
template<class TObject > | |
void | BroadcastImpl (TObject &rBroadcastObject, const int SourceRank) const |
Synchronize a buffer to the value held by the broadcasting rank (generic version). More... | |
template<class TObject > | |
TObject | SendRecvImpl (const TObject &rSendObject, const int SendDestination, const int SendTag, const int RecvSource, const int RecvTag) const |
Exchange data with other ranks (generic version). More... | |
template<class TObject > | |
void | SendImpl (const TObject &rSendObject, const int SendDestination, const int SendTag) const |
Exchange data with other ranks (generic version). More... | |
template<class TObject > | |
void | RecvImpl (TObject &rRecvObject, const int RecvSource, const int RecvTag=0) const |
Exchange data with other ranks (generic version). More... | |
Operations | |
void | Barrier () const override |
Pause program execution until all threads reach this call. More... | |
bool | AndReduce (const bool Value, const int Root) const override |
Kratos::Flags | AndReduce (const Kratos::Flags Values, const Kratos::Flags Mask, const int Root) const override |
bool | OrReduce (const bool Value, const int Root) const override |
Kratos::Flags | OrReduce (const Kratos::Flags Values, const Kratos::Flags Mask, const int Root) const override |
bool | AndReduceAll (const bool Value) const override |
Kratos::Flags | AndReduceAll (const Kratos::Flags Values, const Kratos::Flags Mask) const override |
bool | OrReduceAll (const bool Value) const override |
Kratos::Flags | OrReduceAll (const Kratos::Flags Values, const Kratos::Flags Mask) const override |
static MPIDataCommunicator::UniquePointer | Create (MPI_Comm MPIComm) |
Create a new MPIDataCommunicator using the provided MPI_Comm object. More... | |
Wrapper for common MPI calls within Kratos.
This class is designed to isolate the Kratos core and applications from direct calls to MPI routines.
For function operating on std::vectors, no effort is made to resize inconsistent vectors. The sizes of the sending and receiving buffers will only be checked if the code is compiled in Debug mode. In that case, a meaningful error explaining the inconsistency will be produced. This is done for efficiency (size checks can force multi-stage communications).
|
explicit |
Constructor accepting an MPI_Comm object.
|
override |
Destructor.
|
overridevirtual |
Reimplemented from Kratos::DataCommunicator.
|
overridevirtual |
Reimplemented from Kratos::DataCommunicator.
Reimplemented from Kratos::DataCommunicator.
|
overridevirtual |
Reimplemented from Kratos::DataCommunicator.
|
overridevirtual |
Pause program execution until all threads reach this call.
Wrapper for MPI_Barrier.
Reimplemented from Kratos::DataCommunicator.
|
overridevirtual |
This function throws an error on ranks != Sourcerank if Condition evaluates to false.
This method is intended as a helper function to force ranks to stop after an error is detected on a given rank. A typical use case would be to completely stop the simulation if an error is detected on the root process. The intended usage is something like:
KRATOS_ERROR_IF_NOT( data_communicator_instance.BroadcastErrorIfFalse(Condition, Root) ) << "Detailed error message in Root rank";
If an error is detected, ranks other than Root will fail with a generic error message. Failing on the Root rank is left to the caller, so that a detailed error message can be produced.
Condition | The condition to check. |
SourceRank | The rank where the condition is meaningful. |
Reimplemented from Kratos::DataCommunicator.
|
overridevirtual |
This function throws an error on ranks != Sourcerank if Condition evaluates to true.
This method is intended as a helper function to force ranks to stop after an error is detected on a given rank. A typical use case would be to completely stop the simulation if an error is detected on the root process. The intended usage is something like:
KRATOS_ERROR_IF( data_communicator_instance.BroadcastErrorIfTrue(Condition, Root) ) << "Detailed error message in Root rank";
If an error is detected, ranks other than Root will fail with a generic error message. Failing on the Root rank is left to the caller, so that a detailed error message can be produced.
Condition | The condition to check. |
SourceRank | The rank where the condition is meaningful. |
Reimplemented from Kratos::DataCommunicator.
|
overrideprotectedvirtual |
Synchronize a buffer to the value held by the broadcasting rank (string version).
This is a wrapper for MPI_Bcast.
[in/out] | The broadcast value (input on SourceRank, output on all other ranks). | |
[in] | SourceRank | The rank transmitting the value. |
Reimplemented from Kratos::DataCommunicator.
|
static |
Create a new MPIDataCommunicator using the provided MPI_Comm object.
The new MPIDataCommunicator instance is returned as a unique pointer, since it is responsible for managing the lifetime of the underlying MPI_Comm, and in particular calling MPI_Comm_free once it goes out of scope (this is only required/done if Comm is not one of the predefined MPI_COMM types).
This function throws an error on ranks where Condition evaluates to true, if it evaluated to false on a different rank.
This method is intended as a helper function to force ranks to stop after an error is detected on one or more ranks. The intended usage is something like:
KRATOS_ERROR_IF_NOT( data_communicator_instance.ErrorIfFalseOnAnyRank(Condition) ) << "Detailed error message in ranks where Condition == false.";
If an error is detected, ranks other than those where it was detected will fail with a generic error message. Failing on the ranks where the condition is false is left to the caller, so that a detailed error message can be produced.
Condition | The condition to check. |
Reimplemented from Kratos::DataCommunicator.
This function throws an error on ranks where Condition evaluates to false, if it evaluated to true on a different rank.
This method is intended as a helper function to force ranks to stop after an error is detected on one or more ranks. The intended usage is something like:
KRATOS_ERROR_IF( data_communicator_instance.ErrorIfTrueOnAnyRank(Condition) ) << "Detailed error message in ranks where Condition == true.";
If an error is detected, ranks other than those where it was detected will fail with a generic error message. Failing on the ranks where the condition is true is left to the caller, so that a detailed error message can be produced.
Condition | The condition to check. |
Reimplemented from Kratos::DataCommunicator.
|
static |
Get the underlying MPI_Comm instance.
|
overridevirtual |
Get a sub-data communicator.
This function returns a sub-data communicator based on the provided ranks and a new communicator name.
rRanks | The ranks to include in the sub-communicator. |
rNewCommunicatorName | The name of the new sub-communicator. |
Reimplemented from Kratos::DataCommunicator.
|
overridevirtual |
Turn back information as a string.
Reimplemented from Kratos::DataCommunicator.
|
overridevirtual |
Check whether this DataCommunicator involves the current rank.
In MPI, if the rank is not involved in communication, the communicator is MPI_COMM_NULL and is not a valid argument for most MPI calls.
Reimplemented from Kratos::DataCommunicator.
|
overridevirtual |
Check whether this DataCommunicator is aware of parallelism.
Reimplemented from Kratos::DataCommunicator.
|
overridevirtual |
Check whether this DataCommunicator is MPI_COMM_NULL for the current rank.
In MPI, if the rank is not involved in communication, the communicator is MPI_COMM_NULL and is not a valid argument for most MPI calls.
Reimplemented from Kratos::DataCommunicator.
Kratos::MPIDataCommunicator::KRATOS_CLASS_POINTER_DEFINITION | ( | MPIDataCommunicator | ) |
Pointer definition of MPIDataCommunicator.
|
overridevirtual |
Reimplemented from Kratos::DataCommunicator.
|
overridevirtual |
Reimplemented from Kratos::DataCommunicator.
Reimplemented from Kratos::DataCommunicator.
|
overridevirtual |
Reimplemented from Kratos::DataCommunicator.
|
overridevirtual |
Print object's data.
Reimplemented from Kratos::DataCommunicator.
|
overridevirtual |
Print information about this object.
Reimplemented from Kratos::DataCommunicator.
|
overridevirtual |
Get the parallel rank for this DataCommunicator.
This function serves as a wrapper for MPI_Comm_rank.
Reimplemented from Kratos::DataCommunicator.
|
overrideprotectedvirtual |
Receive data from other ranks (string version).
This is a wrapper for MPI_Recv.
[out] | rRecvValues | Received string from rank RecvSource. |
[in] | RecvSource | Rank the string is expected from. |
[in] | RecvTag | Message tag for received values. |
Reimplemented from Kratos::DataCommunicator.
|
overrideprotectedvirtual |
Send data to other ranks (string version).
This is a wrapper for MPI_Send.
[in] | rSendValues | String to send to rank SendDestination. |
[in] | SendDestination | Rank the string will be sent to. |
[in] | SendTag | Message tag for sent values. |
Reimplemented from Kratos::DataCommunicator.
|
overrideprotectedvirtual |
Exchange data with other ranks (string version).
This is a wrapper for MPI_Sendrecv.
[in] | rSendValues | String to send to rank SendDestination. |
[in] | SendDestination | Rank the string will be sent to. |
[in] | SendTag | Message tag for sent values. |
[in] | RecvSource | Rank the string is expected from. |
[in] | RecvTag | Message tag for received values. |
Reimplemented from Kratos::DataCommunicator.
|
overrideprotectedvirtual |
Exchange data with other ranks (string version).
This is a wrapper for MPI_Sendrecv.
[in] | rSendValues | String to send to rank SendDestination. |
[in] | SendDestination | Rank the string will be sent to. |
[in] | SendTag | Message tag for sent values. |
[out] | rRecvValues | Received string from rank RecvSource. |
[in] | RecvSource | Rank the string is expected from. |
[in] | RecvTag | Message tag for received values. |
Reimplemented from Kratos::DataCommunicator.
|
overridevirtual |
Get the parallel size of this DataCommunicator.
This function serves as a wrapper for MPI_Comm_size.
Reimplemented from Kratos::DataCommunicator.