18 #include <type_traits>
55 template<
class TPo
interDataType >
56 class GlobalPointerCommunicator;
67 template<
class TPo
interDataType,
class TFunctorType >
72 using TSendType = std::invoke_result_t<TFunctorType,GlobalPointer<TPointerDataType>&>;
84 TFunctorType UserFunctor,
87 mCurrentRank(current_rank), mNonLocalData(NonLocalData), mUserFunctor(UserFunctor), mpPointerComm(pPointerComm)
100 if(rGlobalPointer.
GetRank() == mCurrentRank)
101 return mUserFunctor(rGlobalPointer);
103 auto non_local_gp = mNonLocalData.find(rGlobalPointer);
104 KRATOS_DEBUG_ERROR_IF(non_local_gp == mNonLocalData.end()) <<
"Missing entry in NonLocalData" << std::endl;
105 return non_local_gp->second;
116 if(rGlobalPointer.
GetRank() == mCurrentRank)
117 return mUserFunctor(rGlobalPointer);
119 auto non_local_gp = mNonLocalData.find(rGlobalPointer);
120 KRATOS_DEBUG_ERROR_IF(non_local_gp == mNonLocalData.end()) <<
"Missing entry in NonLocalData" << std::endl;
121 return non_local_gp->second;
132 if(rGlobalPointer.
GetRank() == mCurrentRank)
135 return mNonLocalData.find(rGlobalPointer) != mNonLocalData.end();
145 if(rGlobalPointer.
GetRank() == mCurrentRank)
148 return mNonLocalData.find(rGlobalPointer) != mNonLocalData.end();
156 mpPointerComm->Update(mUserFunctor, mNonLocalData);
160 const int mCurrentRank;
162 TFunctorType mUserFunctor;
176 template<
class TPo
interDataType >
213 template<
class TIteratorType >
231 template<
class TFunctorType >
237 auto gps = rFunctor(rComm);
248 template<
class TFunctorType >
262 template<
class TFunctorType >
276 Update(UserFunctor, non_local_data);
288 template<
class TFunctorType >
290 TFunctorType& rUserFunctor,
294 for(
auto color : mColors)
302 std::vector< typename ResultsProxy<TPointerDataType, TFunctorType >::TSendType > locally_gathered_data;
303 for(
auto& gp : recv_global_pointers.GetContainer())
304 locally_gathered_data.push_back( rUserFunctor(gp) );
308 for(
unsigned int i=0;
i<remote_data.size(); ++
i)
309 rNonLocalData[gps_to_be_sent(
i)] = remote_data[
i];
344 virtual std::string
Info()
const
346 std::stringstream buffer;
347 buffer <<
"GlobalPointerCommunicator" ;
354 rOStream <<
"GlobalPointerCommunicator";
390 template<
class TIteratorType >
396 for(
auto it = begin; it !=
end; ++it)
399 if(gp.GetRank() != current_rank)
407 non_local.second.Unique();
418 std::vector<int> send_list;
421 send_list.push_back( it.first );
423 std::sort(send_list.begin(), send_list.end());
452 std::vector<int> mColors;
494 template<
class TPo
interDataType,
class TSendType >
502 template<
class TPo
interDataType,
class TSendType >
507 rOStream << std::endl;
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 int Rank() const
Get the parallel rank for this DataCommunicator.
Definition: data_communicator.h:587
virtual bool IsDistributed() const
Check whether this DataCommunicator is aware of parallelism.
Definition: data_communicator.h:606
A template class for handling communication related to global pointers.
Definition: pointer_communicator.h:178
const DataCommunicator & GetDataCommunicator() const
Returns the data communicator.
Definition: pointer_communicator.h:330
ResultsProxy< TPointerDataType, TFunctorType > Apply(TFunctorType &&UserFunctor)
Applies a user-provided function to the global pointers and return a proxy to the results.
Definition: pointer_communicator.h:266
std::unordered_map< int, GlobalPointersVector< TPointerDataType > > mNonLocalPointers
Definition: pointer_communicator.h:369
void AddPointers(TIteratorType begin, TIteratorType end)
Adds global pointers to the communicator.
Definition: pointer_communicator.h:391
GlobalPointerCommunicator(TFunctorType rFunctor)
Constructor with functor and default data communicator.
Definition: pointer_communicator.h:249
GlobalPointerCommunicator(const DataCommunicator &rComm, GlobalPointersVector< TPointerDataType > &rGpList)
Default constructor.
Definition: pointer_communicator.h:195
GlobalPointerCommunicator(const DataCommunicator &rComm, TFunctorType rFunctor)
Constructor with functor for generating global pointers.
Definition: pointer_communicator.h:232
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: pointer_communicator.h:358
void ComputeCommunicationPlan()
Computes the communication plan for the communicator.
Definition: pointer_communicator.h:416
virtual ~GlobalPointerCommunicator()
Destructor.
Definition: pointer_communicator.h:254
virtual std::string Info() const
Turn back information as a string.
Definition: pointer_communicator.h:344
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: pointer_communicator.h:352
KRATOS_CLASS_POINTER_DEFINITION(GlobalPointerCommunicator)
Pointer definition of GlobalPointerCommunicator.
void Update(TFunctorType &rUserFunctor, GlobalPointersUnorderedMap< TPointerDataType, typename ResultsProxy< TPointerDataType, TFunctorType >::TSendType > &rNonLocalData)
Updates the non-local data using a user-provided function.
Definition: pointer_communicator.h:289
GlobalPointerCommunicator(const DataCommunicator &rComm, TIteratorType itBegin, TIteratorType itEnd)
Constructor with iterator range for global pointers.
Definition: pointer_communicator.h:214
const DataCommunicator & mrDataCommunicator
Non local pointers stored as map with rank as key.
Definition: pointer_communicator.h:371
This class is a wrapper for a pointer to a data that is located in a different rank.
Definition: global_pointer.h:44
This class is a vector which stores global pointers.
Definition: global_pointers_vector.h:61
ptr_iterator ptr_begin()
Definition: global_pointers_vector.h:253
ptr_iterator ptr_end()
Definition: global_pointers_vector.h:261
static std::vector< int > ComputeCommunicationScheduling(const std::vector< int > &rLocalDestinationIds, const DataCommunicator &rComm)
Definition: communication_coloring_utilities.cpp:56
Holder for general data related to MPI (or suitable serial equivalents for non-MPI runs).
Definition: parallel_environment.h:57
A template class to proxy results, whether they are locally or remotely owned.
Definition: pointer_communicator.h:69
void Update()
Updates the NonLocalData using the user functor and communicator.
Definition: pointer_communicator.h:154
ResultsProxy(int current_rank, GlobalPointersUnorderedMap< TPointerDataType, TSendType > NonLocalData, TFunctorType UserFunctor, GlobalPointerCommunicator< TPointerDataType > *pPointerComm)
Constructor.
Definition: pointer_communicator.h:81
TSendType Get(const GlobalPointer< TPointerDataType > &rGlobalPointer) const
Overload for constant GlobalPointer.
Definition: pointer_communicator.h:114
TSendType Get(GlobalPointer< TPointerDataType > &rGlobalPointer) const
Returns the effect of "user_function(rGlobalPointer)" whether the rGlobalPointer is locally or remote...
Definition: pointer_communicator.h:98
std::invoke_result_t< TFunctorType, GlobalPointer< TPointerDataType > & > TSendType
Type alias for the result of applying the functor to a global pointer of TPointerDataType.
Definition: pointer_communicator.h:72
bool Has(GlobalPointer< TPointerDataType > &rGlobalPointer) const
Checks if the node has the GlobalPointer.
Definition: pointer_communicator.h:130
bool Has(const GlobalPointer< TPointerDataType > &rGlobalPointer) const
Overload for constant GlobalPointer.
Definition: pointer_communicator.h:143
virtual ~ResultsProxy()
Destructor.
Definition: pointer_communicator.h:91
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
end
Definition: DEM_benchmarks.py:180
DataCommunicator & GetDefaultDataCommunicator()
Definition: testing.cpp:24
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
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