#include "element.hpp" #include "distributed_view.hpp" #include "local_view.hpp" #include "local_connector.hpp" #include "context_client.hpp" #include "context_server.hpp" #include "mpi.hpp" namespace xios { CDistributedElement::CDistributedElement(int globalSize, const map>& globalIndex) { globalSize_= globalSize ; for(auto index : globalIndex) { globalIndex_[index.first].reference(index.second.copy()) ; localSize_[index.first] = index.second.numElements() ; } } CDistributedElement::CDistributedElement(CEventServer& event) { recvFromClient(event) ; } void CDistributedElement::addView(CElementView::type type, std::map>& indexView) { views_[type] = make_shared(shared_from_this(), type, indexView) ; } void CDistributedElement::addView(CElementView::type type, std::map>& maskView) { views_[type] = make_shared(shared_from_this(), type, maskView) ; } void CDistributedElement::addFullView(void) { if (views_[CElementView::FULL]!=nullptr) return ; std::map> indexView ; for(auto rank : globalIndex_) { auto& index = indexView[rank.first] ; int size=rank.second.numElements() ; index.resize(size) ; for(int i=0;igetRemoteSize() ; vector nbSenders(remoteSize,0) ; for(auto rank : globalIndex_) nbSenders[rank.first]=1 ; MPI_Allreduce(MPI_IN_PLACE, nbSenders.data(), remoteSize, MPI_INT, MPI_SUM, client->getIntraComm()) ; list messages; for(auto ranksData : globalIndex_) { int rank = ranksData.first ; auto& data = ranksData.second ; messages.push_back(CMessage(messageHeader)); messages.back()<sendEvent(event) ; } void CDistributedElement::recvFromClient(CEventServer& event) { globalIndex_.clear(); for (auto& subEvent : event.subEvents) { CBufferIn* buffer = subEvent.buffer; int rank=subEvent.rank ; *buffer>>globalSize_ ; *buffer >> globalIndex_[rank]; } localSize_.clear() ; for(auto& globalIndex : globalIndex_) localSize_[globalIndex.first] = globalIndex.second.numElements() ; } CLocalElement::CLocalElement(int localRank, size_t globalSize, const CArray& globalIndex) : CDistributedElement(globalSize, {{localRank, globalIndex}}), globalIndex_(CDistributedElement::globalIndex_[localRank]), localSize_(CDistributedElement::localSize_[localRank]), localRank_(localRank) { } CLocalElement::CLocalElement(int localRank, CEventServer& event) : globalIndex_(CDistributedElement::globalIndex_[localRank]), localSize_(CDistributedElement::localSize_[localRank]), localRank_(localRank) { recvFromClient(localRank, event) ; } void CLocalElement::recvFromClient(int localRank, CEventServer& event) { set globalIndex ; for (auto& subEvent : event.subEvents) { CBufferIn* buffer = subEvent.buffer; int rank=subEvent.rank ; CArray indGlo ; *buffer >> globalSize_>> indGlo; globalIndex.insert(indGlo.dataFirst(), indGlo.dataFirst()+indGlo.numElements()) ; } localSize_ = globalIndex.size() ; globalIndex_.resize(localSize_) ; int i=0 ; for(auto& ind : globalIndex) { globalIndex_(i)=ind ; i++; } } void CLocalElement::addView(CElementView::type type, CArray& indexView) { views_[type] = make_shared(static_pointer_cast(shared_from_this()), type, indexView) ; } void CLocalElement::addView(CElementView::type type, CArray& maskView) { views_[type] = make_shared(static_pointer_cast(shared_from_this()), type, maskView) ; } void CLocalElement::addFullView(void) { if (views_[CElementView::FULL]!=nullptr) return ; CArray indexView(localSize_) ; for(int i=0;i CLocalElement::getView(CElementView::type type) { if (views_[(size_t)type]==nullptr) { ERROR("CLocalElement::getView(CElementView::type type)",<<"View is not initialized");} else return static_pointer_cast(views_[(size_t)type]) ; } shared_ptr CLocalElement::getConnector(CElementView::type srcType, CElementView::type dstType) { auto newPair = pair(srcType,dstType); auto it = connectors_.find(newPair) ; if (it==connectors_.end()) { auto insertPair=pair, shared_ptr>(newPair,make_shared(getView(srcType),getView(dstType))) ; it=connectors_.insert(insertPair).first ; it->second->computeConnector() ; } return it->second ; } }