12 #if !defined(KRATOS_DISTRIBUTED_VECTOR_IMPORTER_H_INCLUDED )
13 #define KRATOS_DISTRIBUTED_VECTOR_IMPORTER_H_INCLUDED
55 template<
class TDataType=
double,
class TIndexType=std::
size_t>
72 template<
class TGlobalIndicesVectorType>
75 const TGlobalIndicesVectorType& rGlobalIndices,
80 mpNumbering = Kratos::make_unique< DistributedNumbering<IndexType> >(rNumbering);
81 mImportedDataSize = rGlobalIndices.size();
82 std::unordered_map<int, std::vector<IndexType>> to_recv_by_color;
84 for(
unsigned int local_i=0; local_i<rGlobalIndices.size(); ++local_i)
86 IndexType global_i = rGlobalIndices[local_i];
90 mLocalIByColor[owner_rank].push_back(local_i);
91 to_recv_by_color[owner_rank].push_back(remote_local_i);
94 mIdOfLocallyOwnedTerms = mLocalIByColor[
GetComm().
Rank()];
95 mLocallyOwnedIds = to_recv_by_color[
GetComm().
Rank()];
98 std::vector<MpiIndexType> send_list;
99 for(
const auto& item : to_recv_by_color)
103 send_list.push_back(cpu_id);
108 for(
auto color : mVectorCommColors)
112 mLocalIByColor[
color];
113 to_recv_by_color[
color];
118 for(
auto color : mVectorCommColors)
131 mrComm(rOther.mrComm),
133 mLocalIByColor(rOther.mLocalIByColor),
134 mLocallyOwnedIds(rOther.mLocallyOwnedIds),
135 mIdOfLocallyOwnedTerms(rOther.mIdOfLocallyOwnedTerms),
136 mVectorCommColors(rOther.mVectorCommColors)
144 std::vector<TDataType> send_buffer;
145 std::vector<TDataType> recv_buffer;
146 for(
auto color : mVectorCommColors)
150 const auto& local_ids = mLocalIByColor.find(
color)->second;
151 const auto& to_send_ids = mToSendByColor.find(
color)->second;
153 send_buffer.resize(to_send_ids.size());
154 recv_buffer.resize(local_ids.size());
157 send_buffer[
i] = data_vector(to_send_ids[
i]);
164 ImportedData(local_ids[
i]) = recv_buffer[
i];
169 ImportedData(mIdOfLocallyOwnedTerms[
i]) = data_vector( mLocallyOwnedIds[
i] );
207 std::stringstream buffer;
208 buffer <<
"DistributedVectorImporter" ;
213 void PrintInfo(std::ostream& rOStream)
const {rOStream <<
"DistributedVectorImporter";}
275 std::unordered_map<int, std::vector<IndexType>> mToSendByColor;
276 std::unordered_map<MpiIndexType, std::vector<IndexType>> mLocalIByColor;
277 std::vector<IndexType> mLocallyOwnedIds;
278 std::vector<IndexType> mIdOfLocallyOwnedTerms;
279 std::vector<int> mVectorCommColors;
326 template<
class TDataType,
class TIndexType>
334 template<
class TDataType,
class TIndexType>
339 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 DistributedSystemVector which implements FEM assemble capabilities.
Definition: distributed_system_vector.h:61
Provides a DistributedVectorImporter which implements FEM assemble capabilities.
Definition: distributed_vector_importer.h:57
const DataCommunicator & GetComm() const
Definition: distributed_vector_importer.h:181
DenseVector< TDataType > ImportData(const DistributedSystemVector< TDataType, TIndexType > &data_vector) const
this function returns a local array containing the values identified by the rGlobalIndices list passe...
Definition: distributed_vector_importer.h:140
void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: distributed_vector_importer.h:216
~DistributedVectorImporter()
Destructor.
Definition: distributed_vector_importer.h:176
KRATOS_CLASS_POINTER_DEFINITION(DistributedVectorImporter)
Pointer definition of DistributedVectorImporter.
int MpiIndexType
Definition: distributed_vector_importer.h:62
DistributedVectorImporter(const DataCommunicator &rComm, const TGlobalIndicesVectorType &rGlobalIndices, const DistributedNumbering< IndexType > &rNumbering)
Default constructor.
Definition: distributed_vector_importer.h:73
DistributedVectorImporter(DistributedVectorImporter const &rOther)
Copy constructor.
Definition: distributed_vector_importer.h:129
void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: distributed_vector_importer.h:213
TIndexType IndexType
Definition: distributed_vector_importer.h:61
std::string Info() const
Turn back information as a string.
Definition: distributed_vector_importer.h:205
Definition: amatrix_interface.h:41
static std::vector< int > ComputeCommunicationScheduling(const std::vector< int > &rLocalDestinationIds, const DataCommunicator &rComm)
Definition: communication_coloring_utilities.cpp:56
std::size_t IndexType
The definition of the index type.
Definition: key_hash.h:35
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