12 #if !defined(KRATOS_DISTRIBUTED_VECTOR_EXPORTER_H_INCLUDED )
13 #define KRATOS_DISTRIBUTED_VECTOR_EXPORTER_H_INCLUDED
52 template<
class TIndexType=std::
size_t>
69 template<
class TGlobalIndicesVectorType>
72 const TGlobalIndicesVectorType& rGlobalIndices,
77 mpNumbering = Kratos::make_unique< DistributedNumbering<IndexType> >(rNumbering);
78 std::unordered_map<int, std::vector<IndexType>> to_send_remote_local_id;
79 for(
unsigned int local_i=0; local_i<rGlobalIndices.size(); ++local_i)
81 IndexType global_i = rGlobalIndices[local_i];
84 mPositionWithinData[owner_rank].push_back(local_i);
85 to_send_remote_local_id[owner_rank].push_back(remote_local_i);
87 mToRecvLocalId[
GetComm().
Rank()] = std::move(to_send_remote_local_id[
GetComm().Rank()]);
92 std::vector<MpiIndexType> send_list;
93 for(
const auto& item : to_send_remote_local_id)
97 send_list.push_back(cpu_id);
102 for(
auto color : mVectorCommColors)
112 for(
auto color : mVectorCommColors)
117 mToRecvLocalId[
color];
118 mPositionWithinData[
color];
128 mrComm(rOther.mrComm),
130 mToRecvLocalId(rOther.mToRecvLocalId),
131 mPositionWithinData(rOther.mPositionWithinData),
132 mVectorCommColors(rOther.mVectorCommColors)
137 template<
class TDistributedVectorType,
class TLocalVectorType,
class TApplyFunctorType=std::plus<
typename TLocalVectorType::value_type>>
138 void Apply(TDistributedVectorType& rDestinationVector,
139 const TLocalVectorType& rLocalDataVector
142 std::vector<typename TLocalVectorType::value_type> send_buffer;
143 std::vector<typename TLocalVectorType::value_type> recv_buffer;
144 for(
auto color : mVectorCommColors)
148 const auto& local_ids = mToRecvLocalId.find(
color)->second;
149 const auto& position_within_data = mPositionWithinData.find(
color)->second;
150 recv_buffer.resize(local_ids.size());
151 send_buffer.resize(0);
153 send_buffer.push_back(rLocalDataVector[position_within_data[
i]]);
161 rDestinationVector[local_ids[
i]] = TApplyFunctorType()(rDestinationVector[local_ids[
i]],recv_buffer[
i]);
166 const auto& local_ids = mToRecvLocalId.find(
GetComm().
Rank())->second;
167 const auto& position_within_data = mPositionWithinData.find(
GetComm().
Rank())->second;
169 rDestinationVector[local_ids[
i]] = TApplyFunctorType()( rDestinationVector[local_ids[
i]], rLocalDataVector[position_within_data[
i]] );
203 std::stringstream buffer;
204 buffer <<
"DistributedVectorExporter" ;
209 void PrintInfo(std::ostream& rOStream)
const {rOStream <<
"DistributedVectorExporter";}
268 std::unordered_map<int, std::vector<IndexType>> mToRecvLocalId;
269 std::unordered_map<int, std::vector<IndexType>> mPositionWithinData;
270 std::vector<int> mVectorCommColors;
315 template<
class TIndexType>
323 template<
class TIndexType>
328 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
IndexType OwnerRank(const IndexType RowIndex) const
Definition: distributed_numbering.h:200
IndexType RemoteLocalId(const IndexType rGlobalId, const IndexType rOwnerRank) const
Definition: distributed_numbering.h:190
Provides a DistributedVectorExporter which implements FEM assemble capabilities.
Definition: distributed_vector_exporter.h:54
~DistributedVectorExporter()
Destructor.
Definition: distributed_vector_exporter.h:173
void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: distributed_vector_exporter.h:212
const DataCommunicator & GetComm() const
Definition: distributed_vector_exporter.h:187
KRATOS_CLASS_POINTER_DEFINITION(DistributedVectorExporter)
Pointer definition of DistributedVectorExporter.
void Apply(TDistributedVectorType &rDestinationVector, const TLocalVectorType &rLocalDataVector) const
this function "returns" (writes onto rDestinationVector) a local array containing the values identifi...
Definition: distributed_vector_exporter.h:138
TIndexType IndexType
Definition: distributed_vector_exporter.h:58
void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: distributed_vector_exporter.h:209
DistributedVectorExporter(DistributedVectorExporter const &rOther)
Copy constructor.
Definition: distributed_vector_exporter.h:126
DistributedVectorExporter(const DataCommunicator &rComm, const TGlobalIndicesVectorType &rGlobalIndices, const DistributedNumbering< IndexType > &rNumbering)
Default constructor.
Definition: distributed_vector_exporter.h:70
std::string Info() const
Turn back information as a string.
Definition: distributed_vector_exporter.h:201
int MpiIndexType
Definition: distributed_vector_exporter.h:59
static std::vector< int > ComputeCommunicationScheduling(const std::vector< int > &rLocalDestinationIds, const DataCommunicator &rComm)
Definition: communication_coloring_utilities.cpp:56
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
unique_ptr< C > make_unique(Args &&...args)
Definition: smart_pointers.h:45
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