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.
|
Serial (do-nothing) version of a wrapper class for MPI communication. More...
#include <data_communicator.h>
Public Member Functions | |
Type Definitions | |
KRATOS_CLASS_POINTER_DEFINITION (DataCommunicator) | |
Pointer definition of DataCommunicator. More... | |
Life Cycle | |
DataCommunicator () | |
Default constructor. More... | |
virtual | ~DataCommunicator () |
Destructor. More... | |
Inquiry | |
virtual int | Rank () const |
Get the parallel rank for this DataCommunicator. More... | |
virtual int | Size () const |
Get the parallel size of this DataCommunicator. More... | |
virtual bool | IsDistributed () const |
Check whether this DataCommunicator is aware of parallelism. More... | |
virtual bool | IsDefinedOnThisRank () const |
Check whether this DataCommunicator involves the current rank. More... | |
virtual bool | IsNullOnThisRank () const |
Check whether this DataCommunicator is MPI_COMM_NULL for the current rank. More... | |
virtual const DataCommunicator & | GetSubDataCommunicator (const std::vector< int > &rRanks, const std::string &rNewCommunicatorName) const |
Get a sub-data communicator. More... | |
Helper functions for error checking in MPI | |
virtual bool | BroadcastErrorIfTrue (bool Condition, const int SourceRank) const |
This function throws an error on ranks != Sourcerank if Condition evaluates to true. More... | |
virtual bool | BroadcastErrorIfFalse (bool Condition, const int SourceRank) const |
This function throws an error on ranks != Sourcerank if Condition evaluates to false. More... | |
virtual bool | ErrorIfTrueOnAnyRank (bool Condition) const |
This function throws an error on ranks where Condition evaluates to false, if it evaluated to true on a different rank. More... | |
virtual bool | ErrorIfFalseOnAnyRank (bool Condition) const |
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 | |
virtual std::string | Info () const |
Turn back information as a string. More... | |
virtual void | PrintInfo (std::ostream &rOStream) const |
Print information about this object. More... | |
virtual void | PrintData (std::ostream &rOStream) const |
Print object's data. More... | |
Static Public Member Functions | |
Access | |
static DataCommunicator & | GetDefault () |
Convenience function to retrieve the current default DataCommunicator. More... | |
Protected Member Functions | |
Protected operations | |
virtual void | BroadcastImpl (std::string &rBuffer, const int SourceRank) const |
Synchronize a buffer to the value held by the broadcasting rank (string version). More... | |
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... | |
virtual void | SendRecvImpl (const std::string &rSendValues, const int SendDestination, const int SendTag, std::string &rRecvValues, const int RecvSource, const int RecvTag) const |
Exchange data with other ranks (string version). More... | |
virtual std::string | SendRecvImpl (const std::string &rSendValues, const int SendDestination, const int SendTag, const int RecvSource, const int RecvTag) const |
Exchange data with other ranks (string 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... | |
virtual void | SendImpl (const std::string &rSendValues, const int SendDestination, const int SendTag) const |
Send data to other ranks (string 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... | |
virtual void | RecvImpl (std::string &rRecvValues, const int RecvSource, const int RecvTag=0) const |
Receive data from other ranks (string 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 | |
virtual void | Barrier () const |
Pause program execution until all threads reach this call. More... | |
virtual bool | AndReduce (const bool Value, const int Root) const |
virtual Kratos::Flags | AndReduce (const Kratos::Flags Values, const Kratos::Flags Mask, const int Root) const |
virtual bool | OrReduce (const bool Value, const int Root) const |
virtual Kratos::Flags | OrReduce (const Kratos::Flags Values, const Kratos::Flags Mask, const int Root) const |
virtual bool | AndReduceAll (const bool Value) const |
virtual Kratos::Flags | AndReduceAll (const Kratos::Flags Values, const Kratos::Flags Mask) const |
virtual bool | OrReduceAll (const bool Value) const |
virtual Kratos::Flags | OrReduceAll (const Kratos::Flags Values, const Kratos::Flags Mask) const |
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 DataCommunicator::UniquePointer | Create () |
Create a new DataCommunicator as a copy of this one. More... | |
Serial (do-nothing) version of a wrapper class for MPI communication.
|
inline |
Default constructor.
|
inlinevirtual |
Destructor.
|
inlinevirtual |
Reimplemented in Kratos::MPIDataCommunicator.
|
inlinevirtual |
Reimplemented in Kratos::MPIDataCommunicator.
Reimplemented in Kratos::MPIDataCommunicator.
|
inlinevirtual |
Reimplemented in Kratos::MPIDataCommunicator.
|
inlinevirtual |
Pause program execution until all threads reach this call.
Wrapper for MPI_Barrier.
Reimplemented in Kratos::MPIDataCommunicator.
|
inline |
Synchronize a buffer to the value held by the broadcasting rank.
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. This function will transfer basic types (or std::vectors of basic types) directly. For complex classes, serialization will be used to package the object(s) before communication. |
|
inlinevirtual |
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 in Kratos::MPIDataCommunicator.
|
inlinevirtual |
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 in Kratos::MPIDataCommunicator.
|
inlineprotectedvirtual |
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 in Kratos::MPIDataCommunicator.
|
inlineprotected |
Synchronize a buffer to the value held by the broadcasting rank (generic version).
This is a wrapper for MPI_Bcast, using serialization to package complex objects.
[in/out] | The broadcast value (input on SourceRank, output on all other ranks). | |
[in] | SourceRank | The rank transmitting the value. |
|
inlinestatic |
Create a new DataCommunicator as a copy of this one.
This method is used in ParallelEnvironment to register DataCommunicators
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 in Kratos::MPIDataCommunicator.
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 in Kratos::MPIDataCommunicator.
|
static |
Convenience function to retrieve the current default DataCommunicator.
|
inlinevirtual |
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 in Kratos::MPIDataCommunicator.
|
inlinevirtual |
Turn back information as a string.
Reimplemented in Kratos::MPIDataCommunicator.
|
inlinevirtual |
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 in Kratos::MPIDataCommunicator.
|
inlinevirtual |
Check whether this DataCommunicator is aware of parallelism.
Reimplemented in Kratos::MPIDataCommunicator.
|
inlinevirtual |
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 in Kratos::MPIDataCommunicator.
Kratos::DataCommunicator::KRATOS_CLASS_POINTER_DEFINITION | ( | DataCommunicator | ) |
Pointer definition of DataCommunicator.
|
inlinevirtual |
Reimplemented in Kratos::MPIDataCommunicator.
|
inlinevirtual |
Reimplemented in Kratos::MPIDataCommunicator.
Reimplemented in Kratos::MPIDataCommunicator.
|
inlinevirtual |
Reimplemented in Kratos::MPIDataCommunicator.
|
inlinevirtual |
Print object's data.
Reimplemented in Kratos::MPIDataCommunicator.
|
inlinevirtual |
Print information about this object.
Reimplemented in Kratos::MPIDataCommunicator.
|
inlinevirtual |
Get the parallel rank for this DataCommunicator.
This function serves as a wrapper for MPI_Comm_rank.
Reimplemented in Kratos::MPIDataCommunicator.
|
inline |
Exchange data with other ranks.
This is a wrapper for MPI_Recv.
[out] | rRecvObject | Objects to receive from rank RecvSource. |
[in] | RecvSource | Rank the data will be received from. |
[in] | RecvTag | Message tag for received values. This function will transfer basic types (or std::vectors of basic types) directly. For complex classes, serialization will be used to package the object(s) before communication. |
|
inlineprotectedvirtual |
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 in Kratos::MPIDataCommunicator.
|
inlineprotected |
Exchange data with other ranks (generic version).
This is a wrapper for MPI_Recv that uses serialization to transfer arbitrary objects. The objects are expected to be serializable and come in an stl-like container supporting size() and resize()
[out] | rRecvObject | Objects to receive from rank RecvSource. |
[in] | RecvSource | Rank the data will be received from. |
[in] | RecvTag | Message tag for received values. |
|
inline |
Exchange data with other ranks.
This is a wrapper for MPI_Send.
[in] | rSendValues | Objects to send to rank SendDestination. |
[in] | SendDestination | Rank the data will be sent to. |
[in] | SendTag | Message tag for sent values. This function will transfer basic types (or std::vectors of basic types) directly. For complex classes, serialization will be used to package the object(s) before communication. |
|
inlineprotectedvirtual |
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 in Kratos::MPIDataCommunicator.
|
inlineprotected |
Exchange data with other ranks (generic version).
This is a wrapper for MPI_Send that uses serialization to transfer arbitrary objects. The objects are expected to be serializable and come in an stl-like container supporting size() and resize()
[in] | rSendValues | Objects to send to rank SendDestination. |
[in] | SendDestination | Rank the data will be sent to. |
[in] | SendTag | Message tag for sent values. |
|
inline |
Exchange data with other ranks.
This is a wrapper for MPI_Sendrecv.
[in] | rSendValues | Values to send to rank SendDestination. |
[in] | RecvSource | Rank values are expected from. |
[in] | SendDestination | Rank the values will be sent to. |
|
inline |
Exchange data with other ranks.
This is a wrapper for MPI_Sendrecv.
[in] | rSendValues | Values to send to rank SendDestination. |
[in] | SendDestination | Rank the values will be sent to. |
[in] | SendTag | Message tag for sent values. |
[in] | RecvSource | Rank values are expected from. |
[in] | RecvTag | Message tag for received values. |
|
inline |
Exchange data with other ranks.
This is a wrapper for MPI_Sendrecv.
[in] | rSendValues | Values to send to rank SendDestination. |
[in] | SendDestination | Rank the values will be sent to. |
[in] | SendTag | Message tag for sent values. |
[out] | rRecvValues | Received values from rank RecvSource. |
[in] | RecvSource | Rank values are expected from. |
[in] | RecvTag | Message tag for received values. This function will transfer basic types (or std::vectors of basic types) directly. For complex classes, serialization will be used to package the object(s) before communication. |
|
inline |
Exchange data with other ranks.
This is a wrapper for MPI_Sendrecv.
[in] | rSendValues | Values to send to rank SendDestination. |
[in] | SendDestination | Rank the values will be sent to. |
[out] | rRecvValues | Received values from rank RecvSource. |
[in] | RecvSource | Rank values are expected from. This function will transfer basic types (or std::vectors of basic types) directly. For complex classes, serialization will be used to package the object(s) before communication. |
|
inlineprotectedvirtual |
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 in Kratos::MPIDataCommunicator.
|
inlineprotectedvirtual |
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 in Kratos::MPIDataCommunicator.
|
inlineprotected |
Exchange data with other ranks (generic version).
This is a wrapper for MPI_Sendrecv that uses serialization to transfer arbitrary objects. The objects are expected to be serializable and come in an stl-like container supporting size() and resize()
[in] | rSendValues | Objects to send to rank SendDestination. |
[in] | SendDestination | Rank the data will be sent to. |
[in] | SendTag | Message tag for sent values. |
[in] | RecvSource | Rank the data is expected from. |
[in] | RecvTag | Message tag for received values. |
|
inlinevirtual |
Get the parallel size of this DataCommunicator.
This function serves as a wrapper for MPI_Comm_size.
Reimplemented in Kratos::MPIDataCommunicator.