14 #if !defined(KRATOS_POINTER_MAP_COMMUNICATOR_H_INCLUDED )
15 #define KRATOS_POINTER_MAP_COMMUNICATOR_H_INCLUDED
21 #include <unordered_map>
25 #include "concurrentqueue/concurrentqueue.h"
45 template <
class TPo
interDataType,
class TValueDataType>
46 class GlobalPointerMapCommunicator;
90 template<
class TPo
interDataType,
class TValueDataType,
class TApplyFunctor>
116 const TApplyFunctor& rApplyFunctor,
118 : mCurrentRank(rPointerCommunicator.GetMyPID()),
119 mrApplyFunctor(rApplyFunctor),
120 mrPointerCommunicator(rPointerCommunicator)
127 <<
"Constructing a proxy in a parallel "
128 "region is not allowed.\n";
130 this->mUpdateMethod = &ProxyType::AssignLocalAndRemoteData;
132 this->mUpdateMethod = &ProxyType::AssignLocalData;
166 const TValueDataType& rValue)
168 (this->*(this->mUpdateMethod))(rGlobalPointer, rValue);
192 const int mCurrentRank;
193 const TApplyFunctor& mrApplyFunctor;
197 moodycamel::ConcurrentQueue<std::pair<GlobalPointerType, TValueDataType>> mNonLocalGlobalPointerValueConcurrentQueue;
215 void AssignLocalData(
217 const TValueDataType& rValue)
219 mrApplyFunctor(*rGlobalPointer, rValue);
233 void AssignLocalAndRemoteData(
235 const TValueDataType& rValue)
237 const int data_rank = rGlobalPointer.
GetRank();
239 if (data_rank == mCurrentRank) {
240 mrApplyFunctor(*rGlobalPointer, rValue);
242 mNonLocalGlobalPointerValueConcurrentQueue.enqueue(
243 std::make_pair(std::move(rGlobalPointer), rValue));
260 template <
class TPo
interDataType,
class TValueDataType>
275 template<
class TApplyFunctor>
323 template <
class TApplyFunctor>
331 <<
"Calling SendAndApplyRemotely in a parallel region is not "
337 std::unordered_map<int, GlobalPointersUnorderedMap<TPointerDataType, DataVectorType>> non_local_map;
339 bool found_gp_value =
true;
340 while (found_gp_value) {
341 std::pair<GlobalPointerType, TValueDataType> item_pair;
343 rApplyProxy.mNonLocalGlobalPointerValueConcurrentQueue.try_dequeue(item_pair);
344 if (found_gp_value) {
345 auto& r_gp = item_pair.first;
346 non_local_map[r_gp.GetRank()][r_gp].push_back(
347 std::move(item_pair.second));
383 std::vector<GlobalPointerValueVectorPair> gp_value_pair_list;
384 gp_value_pair_list.resize(received_gp_map.size());
385 for (
const auto& r_pair : received_gp_map) {
386 gp_value_pair_list.push_back(std::move(r_pair));
391 auto& r_pointer_data_type_entity = *(rItem.first);
395 rApplyProxy.mrApplyFunctor(r_pointer_data_type_entity, rItem.second[
i]);
419 template <
class TApplyFunctor>
448 virtual std::string
Info()
const
450 std::stringstream buffer;
451 buffer <<
"GlobalPointerMapCommunicator" ;
458 rOStream <<
"GlobalPointerMapCommunicator";
477 template<
class... TArgs>
480 std::vector<int> send_list;
481 send_list.reserve(rNonLocalGlobalPointerMap.size());
482 for (
const auto& r_pair : rNonLocalGlobalPointerMap) {
483 send_list.push_back(r_pair.first);
485 std::sort(send_list.begin(), send_list.end());
501 template <
class TPo
interDataType,
class TDataType>
503 std::istream& rIStream,
510 template <
class TPo
interDataType,
class TDataType>
512 std::ostream& rOStream,
516 rOStream << std::endl;
Proxy class to update local and non-local data.
Definition: pointer_map_communicator.h:92
std::vector< TValueDataType > DataVectorType
Definition: pointer_map_communicator.h:103
GlobalPointerMapCommunicator< TPointerDataType, TValueDataType > TGPMapCommunicator
Definition: pointer_map_communicator.h:99
GlobalPointer< TPointerDataType > GlobalPointerType
Definition: pointer_map_communicator.h:101
ApplyProxy(const TApplyFunctor &rApplyFunctor, TGPMapCommunicator &rPointerCommunicator)
Construct a new Apply Proxy object.
Definition: pointer_map_communicator.h:115
ApplyProxy< TPointerDataType, TValueDataType, TApplyFunctor > ProxyType
Definition: pointer_map_communicator.h:97
void SendAndApplyRemotely()
This method does all the communication.
Definition: pointer_map_communicator.h:181
void Assign(GlobalPointerType &rGlobalPointer, const TValueDataType &rValue)
Assigns value of the GlobalPointer.
Definition: pointer_map_communicator.h:164
Serial (do-nothing) version of a wrapper class for MPI communication.
Definition: data_communicator.h:318
TObject SendRecv(const TObject &rSendObject, const int SendDestination, const int SendTag, const int RecvSource, const int RecvTag) const
Exchange data with other ranks.
Definition: data_communicator.h:492
virtual bool IsDistributed() const
Check whether this DataCommunicator is aware of parallelism.
Definition: data_communicator.h:606
This class is a wrapper for a pointer to a data that is located in a different rank.
Definition: global_pointer.h:44
Short class definition.
Definition: pointer_map_communicator.h:262
void SendAndApplyRemotely(ProxyType< TApplyFunctor > &rApplyProxy)
Sends and applies remote Gp values.
Definition: pointer_map_communicator.h:324
GlobalPointerMapCommunicator(const DataCommunicator &rDataCommunicator)
Construct a new Global Pointer Map Communicator object.
Definition: pointer_map_communicator.h:292
GlobalPointerMapCommunicator(GlobalPointerMapCommunicator const &rOther)=delete
Copy constructor.
std::vector< TValueDataType > DataVectorType
Definition: pointer_map_communicator.h:271
std::vector< int > ComputeCommunicationPlan(const std::unordered_map< int, TArgs... > &rNonLocalGlobalPointerMap)
Definition: pointer_map_communicator.h:478
std::pair< GlobalPointerType, DataVectorType > GlobalPointerValueVectorPair
Definition: pointer_map_communicator.h:273
bool IsDistributed() const
Returns jobs parallel status.
Definition: pointer_map_communicator.h:429
ProxyType< TApplyFunctor > GetApplyProxy(TApplyFunctor &&rApplyFunctor)
Get the Apply Proxy object.
Definition: pointer_map_communicator.h:420
const int mCurrentRank
Definition: pointer_map_communicator.h:471
std::size_t IndexType
Definition: pointer_map_communicator.h:267
GlobalPointerMapCommunicator & operator=(GlobalPointerMapCommunicator const &rOther)=delete
Assignment constructor.
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: pointer_map_communicator.h:456
KRATOS_CLASS_POINTER_DEFINITION(GlobalPointerMapCommunicator)
Pointer definition of GlobalPointerMapCommunicator.
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: pointer_map_communicator.h:462
virtual std::string Info() const
Turn back information as a string.
Definition: pointer_map_communicator.h:448
const DataCommunicator & mrDataCommunicator
Definition: pointer_map_communicator.h:470
int GetMyPID() const
Get the current rank.
Definition: pointer_map_communicator.h:438
virtual ~GlobalPointerMapCommunicator()=default
Destructor.
static std::vector< int > ComputeCommunicationScheduling(const std::vector< int > &rLocalDestinationIds, const DataCommunicator &rComm)
Definition: communication_coloring_utilities.cpp:56
static int IsInParallel()
Wrapper for omp_in_parallel().
Definition: openmp_utils.h:122
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
int GetRank() const
Returns the rank of the global pointer.
Definition: global_pointer.h:262
#define KRATOS_DEBUG_ERROR_IF(conditional)
Definition: exception.h:171
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
void block_for_each(TIterator itBegin, TIterator itEnd, TFunction &&rFunction)
Execute a functor on all items of a range in parallel.
Definition: parallel_utilities.h:299
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
color
Definition: all_t_win_vs_m_fixed_error.py:230
integer i
Definition: TensorModule.f:17