Changeset 1930
- Timestamp:
- 09/10/20 13:51:02 (4 years ago)
- Location:
- XIOS/dev/dev_ym/XIOS_COUPLING/src
- Files:
-
- 13 added
- 4 deleted
- 32 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/dev/dev_ym/XIOS_COUPLING/src/config/axis_attribute.conf
r1493 r1930 22 22 23 23 /* LOCAL */ 24 DECLARE_ARRAY(double , 1 , value )25 DECLARE_ATTRIBUTE(StdString, axis_ref )24 DECLARE_ARRAY(double , 1 , value, false) 25 DECLARE_ATTRIBUTE(StdString, axis_ref, false) 26 26 27 DECLARE_ARRAY(int ,1 , index )27 DECLARE_ARRAY(int ,1 , index, false) 28 28 29 29 /* LOCAL */ 30 DECLARE_ATTRIBUTE(int, data_n )31 DECLARE_ATTRIBUTE(int, data_begin )32 DECLARE_ARRAY(int , 1 , data_index )30 DECLARE_ATTRIBUTE(int, data_n, false) 31 DECLARE_ATTRIBUTE(int, data_begin, false) 32 DECLARE_ARRAY(int , 1 , data_index, false) 33 33 34 34 /*LOCAL */ 35 DECLARE_ATTRIBUTE(int, begin )36 DECLARE_ATTRIBUTE(int, n )35 DECLARE_ATTRIBUTE(int, begin, false) 36 DECLARE_ATTRIBUTE(int, n, false) 37 37 38 38 /* LOCAL */ 39 DECLARE_ARRAY(bool, 1 , mask )40 DECLARE_ARRAY(double, 2 , bounds )39 DECLARE_ARRAY(bool, 1 , mask, false) 40 DECLARE_ARRAY(double, 2 , bounds, false) 41 41 DECLARE_ATTRIBUTE(int, prec) 42 DECLARE_ARRAY(StdString ,1 , label )42 DECLARE_ARRAY(StdString ,1 , label, false) -
XIOS/dev/dev_ym/XIOS_COUPLING/src/config/domain_attribute.conf
r1615 r1930 57 57 DECLARE_ARRAY(double, 3, bounds_lat_2d, false) 58 58 59 DECLARE_ARRAY(double, 2, area )59 DECLARE_ARRAY(double, 2, area, false) 60 60 DECLARE_ATTRIBUTE(double, radius) 61 61 62 62 DECLARE_ENUM4(type,rectilinear,curvilinear,unstructured, gaussian) 63 DECLARE_ATTRIBUTE(StdString, domain_ref )63 DECLARE_ATTRIBUTE(StdString, domain_ref, false) 64 64 DECLARE_ATTRIBUTE(int, prec) -
XIOS/dev/dev_ym/XIOS_COUPLING/src/data_input.cpp
r1882 r1930 19 19 //---------------------------------------------------------------- 20 20 21 void CDataInput::readFieldData(CField* field, CArray<double,1>& data)21 void CDataInput::readFieldData(CField* field, int record, CArray<double,1>& data) 22 22 { 23 this->readFieldData_(field, data);23 this->readFieldData_(field, record, data); 24 24 } 25 25 -
XIOS/dev/dev_ym/XIOS_COUPLING/src/data_input.hpp
r1882 r1930 18 18 /// Read methods /// 19 19 StdSize getFieldNbRecords(CField* field); 20 void readFieldData(CField* field, CArray<double,1>& data);20 void readFieldData(CField* field, int record, CArray<double,1>& data); 21 21 void readFieldAttributesMetaData(CField* field); 22 22 void readFieldAttributesValues(CField* field); … … 27 27 protected: 28 28 virtual StdSize getFieldNbRecords_(CField* field) = 0; 29 virtual void readFieldData_(CField* field, CArray<double,1>& data) = 0;29 virtual void readFieldData_(CField* field, int record, CArray<double,1>& data) = 0; 30 30 virtual void readFieldAttributes_(CField* field, bool readAttributeValues) = 0; 31 31 virtual void closeFile_(void) = 0; -
XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/distributed_view.cpp
r1918 r1930 9 9 : globalIndex_(parent->globalIndex_), globalSize_(parent->globalSize_), localSize_(parent->localSize_) 10 10 { 11 for(auto index : indexView)11 for(auto& index : indexView) 12 12 { 13 13 index_[index.first].reference(index.second.copy()) ; … … 16 16 } 17 17 18 19 } 18 CDistributedView::CDistributedView(CDistributedElement* parent, CElementView::type, const std::map<int,CArray<bool,1>>& maskView) 19 : globalIndex_(parent->globalIndex_), globalSize_(parent->globalSize_), localSize_(parent->localSize_) 20 { 21 for(auto& it : maskView) 22 { 23 int rank = it.first ; 24 auto& mask = it.second ; 25 int size = mask.numElements() ; 26 auto& index = index_[rank] ; 27 index.resize(size) ; 28 int pos=0 ; 29 for(int i=0 ; i < size ; i++) 30 if (mask(i)) { index(pos) = i ; pos++ ; } 31 index.resizeAndPreserve(pos) ; 32 size_[rank] = pos ; 33 } 34 } 35 } -
XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/distributed_view.hpp
r1918 r1930 15 15 16 16 CDistributedView(CDistributedElement* parent, CElementView::type type, const std::map<int,CArray<int,1>>& indexView) ; 17 CDistributedView(CDistributedElement* parent, CElementView::type type, const std::map<int,CArray<bool,1>>& maskView) ; 17 18 18 19 std::map<int,CArray<int,1>>& getIndex(void) { return index_ ;} … … 21 22 std::map<int, int>& getLocalSize(void) { return localSize_ ;} 22 23 size_t getGlobalSize(void) { return globalSize_ ;} 24 25 void getGlobalIndexView(map<int,CArray<size_t,1>>& globalIndexView) 26 { 27 for(auto& it : globalIndex_) 28 { 29 int rank=it.first ; 30 auto& globalIndex = it.second; 31 auto& globalIndView = globalIndexView[rank] ; 32 auto& index = index_[rank] ; 33 auto& size = size_[rank] ; 34 auto& localSize = localSize_[rank] ; 35 globalIndView.resize(size) ; 36 int pos=0 ; 37 for(int i=0 ; i<size ; i++) 38 { 39 if (index(i)>=0 && index(i)<localSize) 40 { 41 globalIndView(i) = globalIndex(index(i)) ; 42 pos++ ; 43 } 44 } 45 globalIndView.resizeAndPreserve(pos) ; 46 } 47 } 23 48 24 49 void getGlobalIndex(int rank, vector<size_t>& globalIndex, size_t sliceIndex, size_t* sliceSize, CDistributedView** view, int pos) -
XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/element.cpp
r1918 r1930 29 29 { 30 30 views_[type] = new CDistributedView(this, type, indexView) ; 31 } 32 33 void CDistributedElement::addView(CElementView::type type, std::map<int, CArray<bool,1>>& maskView) 34 { 35 views_[type] = new CDistributedView(this, type, maskView) ; 31 36 } 32 37 … … 118 123 } 119 124 125 void CLocalElement::addView(CElementView::type type, CArray<bool,1>& maskView) 126 { 127 views_[type] = new CLocalView(this, type, maskView) ; 128 } 129 120 130 void CLocalElement::addFullView(void) 121 131 { -
XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/element.hpp
r1918 r1930 40 40 41 41 void addView(CElementView::type type, std::map<int, CArray<int,1>>& indexView) ; 42 void addView(CElementView::type type, std::map<int, CArray<bool,1>>& maskView) ; 42 43 void sendToServer(CEventClient& event, const CMessage& messageHeader) ; 43 44 … … 55 56 CLocalElement(int localRank, CEventServer& event) ; 56 57 void recvFromClient(int localRank, CEventServer& event) ; 57 58 const CArray<size_t,1>& getGlobalIndex(void) { return globalIndex_ ;} 58 59 void addView(CElementView::type type, CArray<int,1>& indexView) ; 60 void addView(CElementView::type type, CArray<bool,1>& maskView) ; 59 61 void addFullView(void) ; 60 62 CLocalView* getView(CElementView::type type) -
XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/gatherer_connector.cpp
r1918 r1930 15 15 unordered_map<size_t,int> mapGlobalLocalIndex ; 16 16 int globalIndexSize=dstGlobalIndex.size() ; 17 for(auto& ind : dstIndex) mapGlobalLocalIndex[dstGlobalIndex(ind)] = ind ; 17 //for(auto& ind : dstIndex) mapGlobalLocalIndex[dstGlobalIndex(ind)] = ind ; 18 for(int i=0; i<dstSize_ ; i++) if (dstIndex(i)>=0 && dstIndex(i)<globalIndexSize) mapGlobalLocalIndex[dstGlobalIndex(dstIndex(i))] = i ; 19 18 20 for(auto& rankIndex : srcIndex) 19 21 { … … 27 29 for(int ind=0; ind<indexSize ; ind++) 28 30 { 29 if (ind >=0 && ind<globalIndexSize)31 if (index(ind)>=0 && index(ind)<globalIndexSize) 30 32 { 31 auto it=mapGlobalLocalIndex.find(globalIndex(ind )) ;33 auto it=mapGlobalLocalIndex.find(globalIndex(index(ind))) ; 32 34 if (it != mapGlobalLocalIndex.end()) 33 35 { -
XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/gatherer_connector.hpp
r1918 r1930 29 29 30 30 template<typename T> 31 void transfer( map<int, CArray<T,1>>& dataIn, CArray<T,1>& dataOut)31 void transfer(int sizeT, map<int, CArray<T,1>>& dataIn, CArray<T,1>& dataOut) 32 32 { 33 dataOut.resize(dstSize_) ; 33 // for future, make a specific transfer function for sizeT=1 to avoid multiplication (increasing performance) 34 dataOut.resize(dstSize_*sizeT) ; 34 35 T* output = dataOut.dataFirst() ; 35 36 for(auto& data : dataIn) … … 39 40 auto& connector=connector_[rank] ; 40 41 auto& mask=mask_[rank] ; 41 int size= data.second.numElements() ;42 int size=mask.size() ; 42 43 43 44 for(int i=0, j=0 ;i<size;i++) … … 45 46 if (mask[i]) 46 47 { 47 output[connector[j]] = input[i] ; 48 int cj = connector[j]*sizeT ; 49 int ci = i*sizeT ; 50 for (int k=0;k<sizeT;k++) output[cj+k] = input[ci+k] ; 48 51 j++ ; 49 52 } … … 52 55 } 53 56 57 template<typename T> 58 void transfer(map<int, CArray<T,1>>& dataIn, CArray<T,1>& dataOut) 59 { 60 transfer(1,dataIn,dataOut) ; 61 } 54 62 55 63 template<typename T> … … 93 101 void transfer(map<int, CArray<T,1>>& dataIn, CArray<T,1>& dataOut, T missingValue) 94 102 { 95 dataOut.resize(dstSize_) ; 96 dataOut=missingValue ; 97 transfer(map<int, CArray<T,1>>& dataIn, CArray<T,1>& dataOut) ; 103 transfer(1, dataIn, dataout, missingValue) 98 104 } 99 105 100 106 template<typename T> 101 void transfer(CEventServer& event, CArray<T,1>& dataOut) 107 void transfer(int sizeT, map<int, CArray<T,1>>& dataIn, CArray<T,1>& dataOut, T missingValue) 108 { 109 dataOut.resize(dstSize_*sizeT) ; 110 dataOut=missingValue ; 111 transfer(sizeT, dataIn, dataOut) ; 112 } 113 114 template<typename T> 115 void transfer(CEventServer& event, int sizeT, CArray<T,1>& dataOut) 102 116 { 103 117 map<int, CArray<T,1>> dataIn ; … … 107 121 (*subEvent.buffer) >> data ; 108 122 } 109 transfer(dataIn, dataOut) ; 123 transfer(sizeT, dataIn, dataOut) ; 124 } 125 126 template<typename T> 127 void transfer(CEventServer& event, CArray<T,1>& dataOut) 128 { 129 transfer(event, 1, dataOut) ; 130 } 131 132 template<typename T> 133 void transfer(CEventServer& event, int sizeT, CArray<T,1>& dataOut, T missingValue) 134 { 135 map<int, CArray<T,1>> dataIn ; 136 for (auto& subEvent : event.subEvents) 137 { 138 auto& data = dataIn[subEvent.rank]; 139 (*subEvent.buffer) >> data ; 140 } 141 transfer(sizeT, dataIn, dataOut, missingValue) ; 110 142 } 111 143 … … 119 151 (*subEvent.buffer) >> data ; 120 152 } 121 transfer( dataIn, dataOut, missingValue) ;153 transfer(1, dataIn, dataOut, missingValue) ; 122 154 } 123 155 -
XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/grid_local_view.cpp
r1918 r1930 6 6 CGridLocalView::CGridLocalView(CGridLocalElements* parent, CElementView::type type) : localMask_(parent->getLocalMask()) 7 7 { 8 for(auto element : parent->getElements()) views_.push_back(element->getView(type)) ; 8 size_ = 1 ; 9 for(auto element : parent->getElements()) 10 { 11 views_.push_back(element->getView(type)) ; 12 size_ *= element->getView(type)->getSize() ; 13 } 14 9 15 } 10 16 -
XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/grid_local_view.hpp
r1918 r1930 14 14 std::vector<CLocalView*> views_ ; 15 15 std::vector<bool>& localMask_ ; 16 int size_ ; 16 17 17 18 public: 18 19 CGridLocalView(CGridLocalElements* parent, CElementView::type type) ; 19 20 std::vector<CLocalView*>& getViews(void) {return views_ ;} 21 int getSize() { return size_ ;} 20 22 } ; 21 23 } -
XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/grid_remote_connector.cpp
r1918 r1930 19 19 { 20 20 // generic method, every element can be distributed 21 int nDst = dstView_.size() ; 22 vector<size_t> dstSliceSize(nDst) ; 23 dstSliceSize[0] = 1 ; 24 for(int i=1; i<nDst; i++) dstSliceSize[i] = dstView_[i-1]->getGlobalSize()*dstSliceSize[i-1] ; 25 26 CClientClientDHTTemplate<int>::Index2VectorInfoTypeMap dataInfo ; 27 28 CClientClientDHTTemplate<size_t>::Index2VectorInfoTypeMap info ; // info map 29 for(int pos=0; pos<nDst; pos++) 30 { 31 size_t sliceSize=dstSliceSize[pos] ; 32 map<int,CArray<size_t,1>> globalIndexView ; 33 dstView_[pos]->getGlobalIndexView(globalIndexView) ; 34 35 CClientClientDHTTemplate<size_t>::Index2VectorInfoTypeMap lastInfo(info) ; 36 37 if (pos>0) 38 { 39 CArray<size_t,1> ranks(globalIndexView.size()) ; 40 auto it=globalIndexView.begin() ; 41 for(int i=0 ; i<ranks.numElements();i++,it++) ranks(i)=it->first ; 42 CClientClientDHTTemplate<size_t> dataRanks(info, localComm_) ; 43 dataRanks.computeIndexInfoMapping(ranks) ; 44 lastInfo = dataRanks.getInfoIndexMap() ; 45 } 46 47 info.clear() ; 48 for(auto& it : globalIndexView) 49 { 50 int rank = it.first ; 51 auto& globalIndex = it.second ; 52 auto& inf = info[rank] ; 53 if (pos==0) for(int i=0;i<globalIndex.numElements();i++) inf.push_back(globalIndex(i)) ; 54 else 55 { 56 auto& lastGlobalIndex = lastInfo[rank] ; 57 for(size_t lastGlobalInd : lastGlobalIndex) 58 { 59 for(int i=0;i<globalIndex.numElements();i++) inf.push_back(globalIndex(i)*sliceSize+lastGlobalInd) ; 60 } 61 } 62 } 63 64 if (pos==nDst-1) 65 { 66 for(auto& it : info) 67 { 68 int rank=it.first ; 69 auto& globalIndex = it.second ; 70 for(auto globalInd : globalIndex) dataInfo[globalInd].push_back(rank) ; 71 } 72 } 73 } 74 75 CClientClientDHTTemplate<int> dataRanks(dataInfo, localComm_) ; 76 /* 21 77 CClientClientDHTTemplate<int>::Index2VectorInfoTypeMap info ; // info map 22 78 … … 37 93 38 94 CClientClientDHTTemplate<int> dataRanks(info, localComm_) ; 39 95 */ 40 96 // generate list of global index for src view 41 97 int nSrc = srcView_.size() ; 42 98 vector<size_t> srcSliceSize(nSrc) ; 43 srcSliceSize[nSrc-1] = 1 ; 44 for(int i=nSrc-2; i>=0; i--) srcSliceSize[i] = srcView_[i+1]->getGlobalSize()*srcSliceSize[i+1] ; 45 99 // srcSliceSize[nSrc-1] = 1 ; 100 // for(int i=nSrc-2; i>=0; i--) srcSliceSize[i] = srcView_[i+1]->getGlobalSize()*srcSliceSize[i+1] ; 101 102 srcSliceSize[0] = 1 ; 103 for(int i=1; i<nSrc; i++) srcSliceSize[i] = srcView_[i-1]->getGlobalSize()*srcSliceSize[i-1] ; 104 46 105 vector<size_t> srcGlobalIndex ; 47 106 size_t sliceIndex=0 ; … … 54 113 vector<map<int, set<size_t>>> elements(nSrc) ; // internal representation of elements composing the grid 55 114 56 srcSliceSize[nSrc-1] = srcView_[nSrc-1]->getGlobalSize() ;57 for(int i=nSrc-2 ; i>=0 ; i--) srcSliceSize[i] = srcView_[i]->getGlobalSize()*srcSliceSize[i+1] ;115 // srcSliceSize[nSrc-1] = srcView_[nSrc-1]->getGlobalSize() ; 116 // for(int i=nSrc-2 ; i>=0 ; i--) srcSliceSize[i] = srcView_[i]->getGlobalSize()*srcSliceSize[i+1] ; 58 117 59 118 for(auto& indRanks : returnInfo) … … 61 120 size_t gridIndexGlo=indRanks.first ; 62 121 auto& ranks = indRanks.second ; 63 for(int i= 0;i<nSrc;i++)122 for(int i=nSrc-1; i>=0; i--) 64 123 { 65 124 auto& element = elements[i] ; 66 size_t localIndGlo = gridIndexGlo % srcSliceSize[i] ; 125 size_t localIndGlo = gridIndexGlo / srcSliceSize[i] ; 126 gridIndexGlo = gridIndexGlo % srcSliceSize[i] ; 67 127 for(int rank : ranks) element[rank].insert(localIndGlo) ; 68 128 } -
XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/local_view.cpp
r1918 r1930 15 15 } 16 16 17 CLocalView::CLocalView(CLocalElement* parent, CElementView::type type, const CArray<bool,1>& maskView) 18 : CDistributedView( parent, type, {{ parent->localRank_, maskView }} ), 19 localRank_(parent->localRank_), 20 globalIndex_(parent->globalIndex_), size_(CDistributedView::size_[parent->localRank_]), 21 index_(CDistributedView::index_[parent->localRank_]), localSize_(CDistributedView::localSize_[parent->localRank_]) 22 { 23 24 } 17 25 18 26 void CLocalView::sendRemoteElement(CRemoteConnector& connector, CContextClient* client, CEventClient& event, const CMessage& messageHeader) -
XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/local_view.hpp
r1918 r1930 17 17 public: 18 18 CLocalView(CLocalElement* parent, CElementView::type type, const CArray<int,1>& indexView) ; 19 CLocalView(CLocalElement* parent, CElementView::type type, const CArray<bool,1>& maskView) ; 20 19 21 const CArray<int,1>& getIndex(void) { return index_ ;} 20 22 const CArray<size_t,1>& getGlobalIndex(void) { return globalIndex_ ;} 23 24 void getGlobalIndexView(CArray<size_t,1>& globalIndexView) 25 { 26 globalIndexView.resize(size_) ; 27 int pos=0 ; 28 for(int i=0 ; i<size_ ; i++) 29 { 30 if (index_(i)>=0 && index_(i)<localSize_) 31 { 32 globalIndexView(i) = globalIndex_(index_(i)) ; 33 pos++ ; 34 } 35 } 36 globalIndexView.resizeAndPreserve(pos) ; 37 } 21 38 22 39 void getGlobalIndex(vector<size_t>& globalIndex, size_t sliceIndex, size_t* sliceSize, CLocalView** localView, int pos) -
XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/scatterer_connector.hpp
r1918 r1930 34 34 void computeConnector(void) ; 35 35 36 template<typename T >37 void transfer(const CArray<T, 1>& dataIn, map<int, CArray<T,1>>& dataOut)36 template<typename T, int n> 37 void transfer(const CArray<T,n>& dataIn, map<int, CArray<T,1>>& dataOut) 38 38 { 39 transfer(1, dataIn, dataOut) ; 40 } 41 42 template<typename T, int n> 43 void transfer(const CArray<T,n>& dataIn, map<int, CArray<T,1>>& dataOut, T missingValue) 44 { 45 transfer(1, dataIn, dataOut, missingValue) ; 46 } 47 48 template<typename T, int n> 49 void transfer(int sizeT, const CArray<T,n>& dataIn, map<int, CArray<T,1>>& dataOut) 50 { 51 // for future, make a specific transfer function for sizeT=1 to avoid multiplication (increasing performance) 39 52 for(auto& rankConnector : connector_) 40 53 { … … 44 57 int dstSize = mask.size() ; 45 58 auto& data = dataOut[rank] ; 46 data.resize(dstSize ) ;59 data.resize(dstSize * sizeT) ; 47 60 T* dstData = data.dataFirst() ; 48 61 const T* srcData = dataIn.dataFirst() ; … … 50 63 if (mask[i]) 51 64 { 52 dstData[i] = srcData[connector[j]] ; 65 for(int k=0;k<sizeT;k++) dstData[i*sizeT+k] = srcData[connector[j]*sizeT+k] ; 66 j++ ; 67 } 68 } 69 } 70 71 template<typename T, int n> 72 void transfer(int sizeT, const CArray<T,n>& dataIn, map<int, CArray<T,1>>& dataOut, T missingValue) 73 { 74 // for future, make a specific transfer function for sizeT=1 to avoid multiplication (increasing performance) 75 for(auto& rankConnector : connector_) 76 { 77 int rank = rankConnector.first ; 78 auto& connector = rankConnector.second ; 79 auto& mask = mask_[rank] ; 80 int dstSize = mask.size() ; 81 auto& data = dataOut[rank] ; 82 data.resize(dstSize * sizeT) ; 83 T* dstData = data.dataFirst() ; 84 const T* srcData = dataIn.dataFirst() ; 85 for(int i=0, j=0; i<dstSize; i++) 86 if (mask[i]) 87 { 88 for(int k=0;k<sizeT;k++) dstData[i*sizeT+k] = srcData[connector[j]*sizeT+k] ; 89 j++ ; 90 } 91 else 92 { 93 for(int k=0;k<sizeT;k++) dstData[i*sizeT+k] = missingValue ; 53 94 j++ ; 54 95 } … … 56 97 } 57 98 58 template<typename T> 59 void transfer(const CArray<T,1>& dataIn, CContextClient* client, CEventClient& event, const CMessage& messageHeader) 99 template<typename T,int n> 100 void transfer(const CArray<T,n>& dataIn, CContextClient* client, CEventClient& event, const CMessage& messageHeader) 101 { 102 transfer(1, dataIn, client, event, messageHeader) ; 103 } 104 105 template<typename T,int n> 106 void transfer(const CArray<T,n>& dataIn, T missingValue, CContextClient* client, CEventClient& event, const CMessage& messageHeader) 107 { 108 transfer(1, dataIn, missingValue, client, event, messageHeader) ; 109 } 110 111 template<typename T, int n> 112 void transfer(int sizeT, const CArray<T,n>& dataIn, CContextClient* client, CEventClient& event, const CMessage& messageHeader) 60 113 { 61 114 map<int, CArray<T,1>> dataOut ; 62 transfer(dataIn, dataOut) ; 115 transfer(sizeT, dataIn, dataOut) ; 116 sendToServer(dataOut, client, event, messageHeader) ; 117 } 118 119 template<typename T, int n> 120 void transfer(int sizeT, const CArray<T,n>& dataIn, T missingValue, CContextClient* client, CEventClient& event, const CMessage& messageHeader) 121 { 122 map<int, CArray<T,1>> dataOut ; 123 transfer(sizeT, dataIn, dataOut, missingValue) ; 63 124 sendToServer(dataOut, client, event, messageHeader) ; 64 125 } -
XIOS/dev/dev_ym/XIOS_COUPLING/src/filter/data_packet.hpp
r1542 r1930 32 32 * \return a deep copy of the packet 33 33 */ 34 CDataPacket* copy() const { 34 CDataPacket* copy() const 35 { 35 36 CDataPacket* p = new CDataPacket; 36 37 p->data.resize(data.shape()); -
XIOS/dev/dev_ym/XIOS_COUPLING/src/filter/source_filter.cpp
r1918 r1930 40 40 packet->data = defaultValue; 41 41 grid->uncompressField(data, packet->data); 42 43 // Convert missing values to NaN 44 if (hasMissingValue) // probably to removed later 45 { 46 const double nanValue = std::numeric_limits<double>::quiet_NaN(); 47 const size_t nbData = packet->data.numElements(); 48 for (size_t idx = 0; idx < nbData; ++idx) 49 { 50 if (defaultValue == packet->data(idx)) 51 packet->data(idx) = nanValue; 52 } 53 } 42 54 } 43 55 else 44 56 { 45 if (mask) grid->maskField(data, packet->data); 46 else grid->inputField(data, packet->data); 47 } 48 // Convert missing values to NaN 49 if (hasMissingValue) 50 { 51 const double nanValue = std::numeric_limits<double>::quiet_NaN(); 52 const size_t nbData = packet->data.numElements(); 53 for (size_t idx = 0; idx < nbData; ++idx) 57 if (mask) grid->maskField(data, packet->data); // => ie coming from model 58 //else grid->inputField(data, packet->data); 59 else 54 60 { 55 if (defaultValue == packet->data(idx)) 56 packet->data(idx) = nanValue; 61 packet->data.resize(data.numElements()) ; // temporary solution, create own source filter for data coming from client 62 CArray<double,1> tmp( (double*)data.dataFirst(),shape(data.numElements()),duplicateData) ; 63 packet->data.reference(tmp) ; // nothing to do if coming from client to server => workflow view 57 64 } 58 65 } -
XIOS/dev/dev_ym/XIOS_COUPLING/src/io/nc4_data_input.cpp
r1882 r1930 43 43 CATCH 44 44 45 void CNc4DataInput::readFieldData_(CField* field, CArray<double,1>& dataOut)45 void CNc4DataInput::readFieldData_(CField* field, int record, CArray<double,1>& dataOut) 46 46 TRY 47 47 { … … 50 50 CGrid* grid = field->getGrid(); 51 51 52 if (!grid->doGridHaveDataToWrite()) 53 if (SuperClass::type==MULTI_FILE || !isCollective) return; 52 if (!grid->doGridHaveDataToWrite()) if (SuperClass::type==MULTI_FILE || !isCollective) return; 54 53 55 54 StdString fieldId = field->getFieldOutputName(); 56 55 57 CArray<double,1> fieldData(grid->getWrittenDataSize());58 if (!field->default_value.isEmpty()) fieldData = field->default_value;59 60 56 switch (SuperClass::type) 61 57 { 62 58 case MULTI_FILE: 63 SuperClassWriter::getData( fieldData, fieldId, isCollective, (field->getNStep() - 1)%field->nstepMax);59 SuperClassWriter::getData(dataOut, fieldId, isCollective, record ); 64 60 break; 65 61 case ONE_FILE: … … 108 104 } 109 105 110 SuperClassWriter::getData( fieldData, fieldId, isCollective, (field->getNStep() - 1)%field->nstepMax, &start, &count);106 SuperClassWriter::getData(dataOut, fieldId, isCollective, record, &start, &count); 111 107 break; 112 108 } 113 }114 115 field->inputField(fieldData, dataOut);116 117 if (!field->scale_factor.isEmpty() || !field->add_offset.isEmpty())118 {119 double scaleFactor = 1.0, addOffset = 0.0;120 if (!field->scale_factor.isEmpty()) scaleFactor = field->scale_factor;121 if (!field->add_offset.isEmpty()) addOffset = field->add_offset;122 field->invertScaleFactorAddOffset(dataOut,scaleFactor, addOffset);123 109 } 124 110 } -
XIOS/dev/dev_ym/XIOS_COUPLING/src/io/nc4_data_input.hpp
r1882 r1930 37 37 // Read methods 38 38 virtual StdSize getFieldNbRecords_(CField* field); 39 virtual void readFieldData_(CField* field, CArray<double,1>& data);39 virtual void readFieldData_(CField* field, int record, CArray<double,1>& data); 40 40 virtual void readFieldAttributes_(CField* field, bool readAttributeValues); 41 41 virtual void closeFile_(void); -
XIOS/dev/dev_ym/XIOS_COUPLING/src/io/nc4_data_output.cpp
r1882 r1930 58 58 StdString lonName,latName ; 59 59 60 domain->computeWrittenIndex();60 //domain->computeWrittenIndex(); 61 61 domain->computeWrittenCompressedIndex(comm_file); 62 62 … … 319 319 { 320 320 case CDomain::type_attr::curvilinear : 321 SuperClassWriter::writeData( writtenLat, latid, isCollective, 0);322 SuperClassWriter::writeData( writtenLon, lonid, isCollective, 0);321 SuperClassWriter::writeData(domain->latvalue, latid, isCollective, 0); 322 SuperClassWriter::writeData(domain->lonvalue, lonid, isCollective, 0); 323 323 break; 324 324 case CDomain::type_attr::rectilinear : 325 CArray<double,1> lat = writtenLat(Range(fromStart,toEnd,domain->ni)) ;325 CArray<double,1> lat = domain->latvalue(Range(fromStart,toEnd,domain->ni)) ; 326 326 SuperClassWriter::writeData(CArray<double,1>(lat.copy()), latid, isCollective, 0); 327 CArray<double,1> lon = writtenLon(Range(0,domain->ni-1)) ;327 CArray<double,1> lon = domain->lonvalue(Range(0,domain->ni-1)) ; 328 328 SuperClassWriter::writeData(CArray<double,1>(lon.copy()), lonid, isCollective, 0); 329 329 break; … … 332 332 if (domain->hasBounds) 333 333 { 334 SuperClassWriter::writeData( writtenBndsLon, bounds_lonid, isCollective, 0);335 SuperClassWriter::writeData( writtenBndsLat, bounds_latid, isCollective, 0);334 SuperClassWriter::writeData(domain->bounds_lonvalue, bounds_lonid, isCollective, 0); 335 SuperClassWriter::writeData(domain->bounds_latvalue, bounds_latid, isCollective, 0); 336 336 } 337 337 } … … 339 339 if (domain->hasArea) 340 340 { 341 SuperClassWriter::writeData( writtenArea, areaId, isCollective, 0);341 SuperClassWriter::writeData(domain->areavalue, areaId, isCollective, 0); 342 342 } 343 343 … … 432 432 if (domain->hasLonLat) 433 433 { 434 SuperClassWriter::writeData(writtenLat, latid, isCollective, 0,&start,&count); 435 SuperClassWriter::writeData(writtenLon, lonid, isCollective, 0,&start,&count); 434 // SuperClassWriter::writeData(writtenLat, latid, isCollective, 0,&start,&count); 435 // SuperClassWriter::writeData(writtenLon, lonid, isCollective, 0,&start,&count); 436 SuperClassWriter::writeData(domain->latvalue, latid, isCollective, 0,&start,&count); 437 SuperClassWriter::writeData(domain->lonvalue, lonid, isCollective, 0,&start,&count); 438 436 439 } 437 440 break; … … 443 446 std::vector<StdSize> start(1) ; 444 447 std::vector<StdSize> count(1) ; 445 if (domain->isEmpty()) 446 { 447 start[0]=0 ; 448 count[0]=0 ; 449 SuperClassWriter::writeData(writtenLat, latid, isCollective, 0,&start,&count); 450 SuperClassWriter::writeData(writtenLon, lonid, isCollective, 0,&start,&count); 451 } 452 else 453 { 454 start[0]=domain->jbegin; 455 count[0]=domain->nj; 456 CArray<double,1> lat = writtenLat(Range(fromStart,toEnd,domain->ni)); 457 SuperClassWriter::writeData(CArray<double,1>(lat.copy()), latid, isCollective, 0,&start,&count); 458 459 start[0]=domain->ibegin; 460 count[0]=domain->ni; 461 CArray<double,1> lon = writtenLon(Range(0,domain->ni-1)); 462 SuperClassWriter::writeData(CArray<double,1>(lon.copy()), lonid, isCollective, 0,&start,&count); 463 } 448 449 start[0]=domain->jbegin; 450 count[0]=domain->nj; 451 CArray<double,1> lat = domain->latvalue(Range(fromStart,toEnd,domain->ni)); 452 SuperClassWriter::writeData(CArray<double,1>(lat.copy()), latid, isCollective, 0,&start,&count); 453 454 start[0]=domain->ibegin; 455 count[0]=domain->ni; 456 CArray<double,1> lon = domain->lonvalue(Range(0,domain->ni-1)); 457 SuperClassWriter::writeData(CArray<double,1>(lon.copy()), lonid, isCollective, 0,&start,&count); 464 458 } 465 459 break; … … 486 480 } 487 481 488 SuperClassWriter::writeData(writtenBndsLon, bounds_lonid, isCollective, 0, &start, &count); 489 SuperClassWriter::writeData(writtenBndsLat, bounds_latid, isCollective, 0, &start, &count); 482 // SuperClassWriter::writeData(writtenBndsLon, bounds_lonid, isCollective, 0, &start, &count); 483 // SuperClassWriter::writeData(writtenBndsLat, bounds_latid, isCollective, 0, &start, &count); 484 SuperClassWriter::writeData(domain->bounds_lonvalue, bounds_lonid, isCollective, 0, &start, &count); // will probably not working for rectilinear 485 SuperClassWriter::writeData(domain->bounds_latvalue, bounds_latid, isCollective, 0, &start, &count); 490 486 } 491 487 … … 495 491 std::vector<StdSize> count(2); 496 492 497 if (domain->isEmpty()) 498 { 499 start[0] = 0; start[1] = 0; 500 count[0] = 0; count[1] = 0; 501 } 502 else 503 { 504 start[1] = domain->ibegin; 505 start[0] = domain->jbegin; 506 count[1] = domain->ni; 507 count[0] = domain->nj; 508 } 493 start[1] = domain->ibegin; 494 start[0] = domain->jbegin; 495 count[1] = domain->ni; 496 count[0] = domain->nj; 509 497 510 SuperClassWriter::writeData( writtenArea, areaId, isCollective, 0, &start, &count);498 SuperClassWriter::writeData(domain->areavalue, areaId, isCollective, 0, &start, &count); 511 499 } 512 500 … … 1044 1032 if (domain->hasLonLat) 1045 1033 { 1046 SuperClassWriter::writeData(writtenLat, latid, isCollective, 0); 1047 SuperClassWriter::writeData(writtenLon, lonid, isCollective, 0); 1034 // SuperClassWriter::writeData(writtenLat, latid, isCollective, 0); 1035 // SuperClassWriter::writeData(writtenLon, lonid, isCollective, 0); 1036 SuperClassWriter::writeData(domain->latvalue, latid, isCollective, 0); 1037 SuperClassWriter::writeData(domain->lonvalue, lonid, isCollective, 0); 1048 1038 if (domain->hasBounds) 1049 1039 { 1050 SuperClassWriter::writeData(writtenBndsLon, bounds_lonid, isCollective, 0); 1051 SuperClassWriter::writeData(writtenBndsLat, bounds_latid, isCollective, 0); 1040 // SuperClassWriter::writeData(writtenBndsLon, bounds_lonid, isCollective, 0); 1041 // SuperClassWriter::writeData(writtenBndsLat, bounds_latid, isCollective, 0); 1042 SuperClassWriter::writeData(domain->bounds_lonvalue, bounds_lonid, isCollective, 0); 1043 SuperClassWriter::writeData(domain->bounds_latvalue, bounds_latid, isCollective, 0); 1052 1044 } 1053 1045 } 1054 1046 1055 1047 if (domain->hasArea) 1056 SuperClassWriter::writeData(writtenArea, areaId, isCollective, 0); 1048 // SuperClassWriter::writeData(writtenArea, areaId, isCollective, 0); 1049 SuperClassWriter::writeData(domain->areavalue, areaId, isCollective, 0); 1057 1050 1058 1051 SuperClassWriter::definition_start(); … … 1126 1119 if (domain->hasLonLat) 1127 1120 { 1128 SuperClassWriter::writeData( writtenLat, latid, isCollective, 0,&start,&count);1129 SuperClassWriter::writeData( writtenLon, lonid, isCollective, 0,&start,&count);1121 SuperClassWriter::writeData(domain->latvalue, latid, isCollective, 0,&start,&count); 1122 SuperClassWriter::writeData(domain->lonvalue, lonid, isCollective, 0,&start,&count); 1130 1123 if (domain->hasBounds) 1131 1124 { 1132 SuperClassWriter::writeData( writtenBndsLon, bounds_lonid, isCollective, 0,&startBounds,&countBounds);1133 SuperClassWriter::writeData( writtenBndsLat, bounds_latid, isCollective, 0,&startBounds,&countBounds);1125 SuperClassWriter::writeData(domain->bounds_lonvalue, bounds_lonid, isCollective, 0,&startBounds,&countBounds); 1126 SuperClassWriter::writeData(domain->bounds_latvalue, bounds_latid, isCollective, 0,&startBounds,&countBounds); 1134 1127 } 1135 1128 } 1136 1129 1137 1130 if (domain->hasArea) 1138 SuperClassWriter::writeData( writtenArea, areaId, isCollective, 0, &start, &count);1131 SuperClassWriter::writeData(domain->areavalue, areaId, isCollective, 0, &start, &count); 1139 1132 1140 1133 SuperClassWriter::definition_start(); … … 1166 1159 axis->checkAttributes(); 1167 1160 1168 axis->computeWrittenIndex();1161 // axis->computeWrittenIndex(); 1169 1162 axis->computeWrittenCompressedIndex(comm_file); 1170 1163 … … 1303 1296 { 1304 1297 if (!axis->value.isEmpty()) 1305 SuperClassWriter::writeData(axis _value, axisid, isCollective, 0);1298 SuperClassWriter::writeData(axis->value, axisid, isCollective, 0); 1306 1299 1307 1300 if (!axis->bounds.isEmpty()) … … 1321 1314 } 1322 1315 } 1323 SuperClassWriter::writeData(axis _bounds, axisBoundsId, isCollective, 0);1316 SuperClassWriter::writeData(axis->bounds, axisBoundsId, isCollective, 0); 1324 1317 } 1325 1318 } … … 1342 1335 { 1343 1336 if (!axis->value.isEmpty()) 1344 SuperClassWriter::writeData(axis _value, axisid, isCollective, 0, &start, &count);1337 SuperClassWriter::writeData(axis->value, axisid, isCollective, 0, &start, &count); 1345 1338 1346 1339 if (!axis->bounds.isEmpty()) … … 1360 1353 } 1361 1354 } 1362 SuperClassWriter::writeData(axis _bounds, axisBoundsId, isCollective, 0, &startBounds, &countBounds);1355 SuperClassWriter::writeData(axis->bounds, axisBoundsId, isCollective, 0, &startBounds, &countBounds); 1363 1356 } 1364 1357 } … … 2475 2468 field->outputCompressedField(dataIn, fieldData); 2476 2469 else 2477 field->outputField(dataIn, fieldData); 2470 { 2471 //field->outputField(dataIn, fieldData); 2472 if (!field->default_value.isEmpty()) field->getGrid()->getWorkflowToFullConnector()->transfer(dataIn, fieldData, (double)field->default_value ) ; 2473 else field->getGrid()->getWorkflowToFullConnector()->transfer(dataIn, fieldData ) ; 2474 } 2478 2475 2479 2476 if (!field->prec.isEmpty() && field->prec == 2) fieldData = round(fieldData); -
XIOS/dev/dev_ym/XIOS_COUPLING/src/node/axis.cpp
r1918 r1930 344 344 345 345 346 void CAxis::initializeLocalElement(void)347 {348 // after checkAttribute index of size n349 int rank = CContext::getCurrent()->getIntraCommRank() ;350 351 CArray<size_t,1> ind(n) ;352 for (int i=0;i<n;i++) ind(i)=index(i) ;353 354 localElement_ = new CLocalElement(rank, n_glo, ind) ;355 }356 357 void CAxis::addFullView(void)358 {359 CArray<int,1> index(n) ;360 for(int i=0; i<n ; i++) index(i)=i ;361 localElement_ -> addView(CElementView::FULL, index) ;362 }363 364 void CAxis::addWorkflowView(void)365 {366 // mask + data are included into data_index367 int nk=data_index.numElements() ;368 int nMask=0 ;369 for(int k=0;k<nk;k++) if (data_index(k)>=0 && data_index(k)<n) nMask++ ;370 371 CArray<int,1> index(nMask) ;372 nMask=0 ;373 for(int k=0;k<nk;k++)374 if (data_index(k)>=0 && data_index(k)<n)375 {376 index(nMask) = data_index(k) ;377 nMask++ ;378 }379 localElement_ -> addView(CElementView::WORKFLOW, index) ;380 }381 382 void CAxis::addModelView(void)383 {384 // information for model view is stored in data_index385 localElement_->addView(CElementView::MODEL, data_index) ;386 }387 388 void CAxis::computeModelToWorkflowConnector(void)389 {390 CLocalView* srcView=getLocalView(CElementView::MODEL) ;391 CLocalView* dstView=getLocalView(CElementView::WORKFLOW) ;392 modelToWorkflowConnector_ = new CLocalConnector(srcView, dstView);393 modelToWorkflowConnector_->computeConnector() ;394 }395 396 346 /*! 397 347 Check the validity of data, fill in values if any, and apply mask. … … 543 493 break; 544 494 case EVENT_ID_DISTRIBUTED_ATTRIBUTES: 495 recvDistributedAttributes_old(event); 496 return true; 497 break; 498 case EVENT_ID_AXIS_DISTRIBUTION: 499 recvAxisDistribution(event); 500 return true; 501 break; 502 case EVENT_ID_SEND_DISTRIBUTED_ATTRIBUTE: 545 503 recvDistributedAttributes(event); 546 504 return true; … … 671 629 || (index.numElements() != n_glo)) 672 630 { 673 sendDistributedAttributes (client, axisId);631 sendDistributedAttributes_old(client, axisId); 674 632 } 675 633 else … … 1171 1129 In future, if new attributes are added, they should also be processed in this function 1172 1130 */ 1173 void CAxis::sendDistributedAttributes (CContextClient* client, const string& axisId)1131 void CAxis::sendDistributedAttributes_old(CContextClient* client, const string& axisId) 1174 1132 TRY 1175 1133 { … … 1278 1236 \param [in] event event containing data of these attributes 1279 1237 */ 1280 void CAxis::recvDistributedAttributes (CEventServer& event)1238 void CAxis::recvDistributedAttributes_old(CEventServer& event) 1281 1239 TRY 1282 1240 { … … 1293 1251 buffers.push_back(buffer); 1294 1252 } 1295 get(axisId)->recvDistributedAttributes (ranks, buffers);1253 get(axisId)->recvDistributedAttributes_old(ranks, buffers); 1296 1254 } 1297 1255 CATCH … … 1302 1260 \param [in] buffers buffer containing data sent from the sender 1303 1261 */ 1304 void CAxis::recvDistributedAttributes (vector<int>& ranks, vector<CBufferIn*> buffers)1262 void CAxis::recvDistributedAttributes_old(vector<int>& ranks, vector<CBufferIn*> buffers) 1305 1263 TRY 1306 1264 { … … 1585 1543 CATCH_DUMP_ATTR 1586 1544 1545 1546 ////////////////////////////////////////////////////////////////////////////////////// 1547 // this part is related to distribution, element definition, views and connectors // 1548 ////////////////////////////////////////////////////////////////////////////////////// 1549 1550 void CAxis::initializeLocalElement(void) 1551 { 1552 // after checkAttribute index of size n 1553 int rank = CContext::getCurrent()->getIntraCommRank() ; 1554 1555 CArray<size_t,1> ind(n) ; 1556 for (int i=0;i<n;i++) ind(i)=index(i) ; 1557 1558 localElement_ = new CLocalElement(rank, n_glo, ind) ; 1559 } 1560 1561 void CAxis::addFullView(void) 1562 { 1563 CArray<int,1> index(n) ; 1564 for(int i=0; i<n ; i++) index(i)=i ; 1565 localElement_ -> addView(CElementView::FULL, index) ; 1566 } 1567 1568 void CAxis::addWorkflowView(void) 1569 { 1570 // mask + data are included into data_index 1571 int nk=data_index.numElements() ; 1572 int nMask=0 ; 1573 for(int k=0;k<nk;k++) if (data_index(k)>=0 && data_index(k)<n) nMask++ ; 1574 1575 CArray<int,1> index(nMask) ; 1576 nMask=0 ; 1577 for(int k=0;k<nk;k++) 1578 if (data_index(k)>=0 && data_index(k)<n) 1579 { 1580 index(nMask) = data_index(k) ; 1581 nMask++ ; 1582 } 1583 localElement_ -> addView(CElementView::WORKFLOW, index) ; 1584 } 1585 1586 void CAxis::addModelView(void) 1587 { 1588 // information for model view is stored in data_index 1589 localElement_->addView(CElementView::MODEL, data_index) ; 1590 } 1591 1592 void CAxis::computeModelToWorkflowConnector(void) 1593 { 1594 CLocalView* srcView=getLocalView(CElementView::MODEL) ; 1595 CLocalView* dstView=getLocalView(CElementView::WORKFLOW) ; 1596 modelToWorkflowConnector_ = new CLocalConnector(srcView, dstView); 1597 modelToWorkflowConnector_->computeConnector() ; 1598 } 1599 1600 1601 void CAxis::computeRemoteElement(CContextClient* client, EDistributionType type) 1602 { 1603 CContext* context = CContext::getCurrent(); 1604 map<int, CArray<size_t,1>> globalIndex ; 1605 1606 if (type==EDistributionType::BANDS) // Bands distribution to send to file server 1607 { 1608 int nbServer = client->serverSize; 1609 int nbClient = client->clientSize ; 1610 int rankClient = client->clientRank ; 1611 int size = nbServer / nbClient ; 1612 int start ; 1613 if (nbServer%nbClient > rankClient) 1614 { 1615 start = (size+1) * rankClient ; 1616 size++ ; 1617 } 1618 else start = size*rankClient + nbServer%nbClient ; 1619 1620 for(int i=0; i<size; i++) 1621 { 1622 int rank=start+i ; 1623 size_t indSize = n_glo/nbServer ; 1624 size_t indStart ; 1625 if (n_glo % nbServer > rank) 1626 { 1627 indStart = (indSize+1) * rank ; 1628 indSize++ ; 1629 } 1630 else indStart = indSize*rank + n_glo%nbServer ; 1631 1632 auto& globalInd = globalIndex[rank] ; 1633 globalInd.resize(indSize) ; 1634 for(size_t n = 0 ; n<indSize; n++) globalInd(n)=indStart+n ; 1635 } 1636 } 1637 else if (type==EDistributionType::NONE) // domain is not distributed ie all servers get the same local domain 1638 { 1639 int nbServer = client->serverSize; 1640 size_t nglo=n_glo ; 1641 CArray<size_t,1> indGlo(nglo) ; 1642 for(size_t i=0;i<nglo;i++) indGlo(i) = i ; 1643 for (auto& rankServer : client->getRanksServerLeader()) globalIndex[rankServer].reference(indGlo.copy()); ; 1644 } 1645 remoteElement_[client] = new CDistributedElement(n_glo, globalIndex) ; 1646 remoteElement_[client]->addFullView() ; 1647 } 1648 1649 void CAxis::distributeToServer(CContextClient* client, std::map<int, CArray<size_t,1>>& globalIndex, const string& axisId) 1650 { 1651 string serverAxisId = axisId.empty() ? this->getId() : axisId ; 1652 CContext* context = CContext::getCurrent(); 1653 1654 this->sendAllAttributesToServer(client, serverAxisId) ; 1655 1656 CDistributedElement scatteredElement(n_glo,globalIndex) ; 1657 scatteredElement.addFullView() ; 1658 CScattererConnector scattererConnector(localElement_->getView(CElementView::FULL), scatteredElement.getView(CElementView::FULL), context->getIntraComm()) ; 1659 scattererConnector.computeConnector() ; 1660 1661 // phase 0 1662 // send remote element to construct the full view on server, ie without hole 1663 CEventClient event0(getType(), EVENT_ID_AXIS_DISTRIBUTION); 1664 CMessage message0 ; 1665 message0<<serverAxisId<<0 ; 1666 remoteElement_[client]->sendToServer(client,event0,message0) ; 1667 1668 // phase 1 1669 // send the full view of element to construct the connector which connect distributed data coming from client to the full local view 1670 CEventClient event1(getType(), EVENT_ID_AXIS_DISTRIBUTION); 1671 CMessage message1 ; 1672 message1<<serverAxisId<<1<<localElement_->getView(CElementView::FULL)->getGlobalSize() ; 1673 scattererConnector.transfer(localElement_->getView(CElementView::FULL)->getGlobalIndex(),client,event1,message1) ; 1674 1675 sendDistributedAttributes(client, scattererConnector, axisId) ; 1676 1677 // phase 2 send the mask : data index + mask2D 1678 CArray<bool,1> maskIn(localElement_->getView(CElementView::WORKFLOW)->getSize()); 1679 CArray<bool,1> maskOut ; 1680 CLocalConnector workflowToFull(localElement_->getView(CElementView::WORKFLOW), localElement_->getView(CElementView::FULL)) ; 1681 workflowToFull.computeConnector() ; 1682 maskIn=true ; 1683 workflowToFull.transfer(maskIn,maskOut,false) ; 1684 1685 // phase 3 : prepare grid scatterer connector to send data from client to server 1686 map<int,CArray<size_t,1>> workflowGlobalIndex ; 1687 map<int,CArray<bool,1>> maskOut2 ; 1688 scattererConnector.transfer(maskOut, maskOut2) ; 1689 scatteredElement.addView(CElementView::WORKFLOW, maskOut2) ; 1690 scatteredElement.getView(CElementView::WORKFLOW)->getGlobalIndexView(workflowGlobalIndex) ; 1691 // create new workflow view for scattered element 1692 CDistributedElement clientToServerElement(scatteredElement.getGlobalSize(), workflowGlobalIndex) ; 1693 clientToServerElement.addFullView() ; 1694 CEventClient event2(getType(), EVENT_ID_AXIS_DISTRIBUTION); 1695 CMessage message2 ; 1696 message2<<serverAxisId<<2 ; 1697 clientToServerElement.sendToServer(client, event2, message2) ; 1698 clientToServerConnector_[client] = new CScattererConnector(localElement_->getView(CElementView::WORKFLOW), 1699 clientToServerElement.getView(CElementView::FULL), context->getIntraComm()) ; 1700 clientToServerConnector_[client]->computeConnector() ; 1701 1702 1703 CEventClient event3(getType(), EVENT_ID_AXIS_DISTRIBUTION); 1704 CMessage message3 ; 1705 message3<<serverAxisId<<3 ; 1706 clientToServerConnector_[client]->transfer(maskIn,client,event3,message3) ; 1707 1708 1709 1710 } 1711 1712 void CAxis::recvAxisDistribution(CEventServer& event) 1713 TRY 1714 { 1715 string axisId; 1716 int phasis ; 1717 for (auto& subEvent : event.subEvents) (*subEvent.buffer) >> axisId >> phasis ; 1718 get(axisId)->receivedAxisDistribution(event, phasis); 1719 } 1720 CATCH 1721 1722 1723 void CAxis::receivedAxisDistribution(CEventServer& event, int phasis) 1724 TRY 1725 { 1726 CContext* context = CContext::getCurrent(); 1727 if (phasis==0) // receive the remote element to construct the full view 1728 { 1729 localElement_ = new CLocalElement(context->getIntraCommRank(),event) ; 1730 localElement_->addFullView() ; 1731 // construct the local dimension and indexes 1732 auto& globalIndex=localElement_->getGlobalIndex() ; 1733 int nk=globalIndex.numElements() ; 1734 int minK=n_glo,maxK=-1 ; 1735 int nGlo=n_glo ; 1736 int indGlo ; 1737 for(int k=0;k<nk;k++) 1738 { 1739 indGlo=globalIndex(k) ; 1740 if (indGlo<minK) minK=indGlo ; 1741 if (indGlo>maxK) maxK=indGlo ; 1742 } 1743 if (maxK>=minK) { begin=minK ; n=maxK-minK+1 ; } 1744 else {begin=0; n=0 ;} 1745 1746 } 1747 else if (phasis==1) // receive the sent view from client to construct the full distributed full view on server 1748 { 1749 CContext* context = CContext::getCurrent(); 1750 CDistributedElement* elementFrom = new CDistributedElement(event) ; 1751 elementFrom->addFullView() ; 1752 gathererConnector_ = new CGathererConnector(elementFrom->getView(CElementView::FULL), localElement_->getView(CElementView::FULL)) ; 1753 gathererConnector_->computeConnector() ; 1754 } 1755 else if (phasis==2) 1756 { 1757 delete gathererConnector_ ; 1758 elementFrom_ = new CDistributedElement(event) ; 1759 elementFrom_->addFullView() ; 1760 gathererConnector_ = new CGathererConnector(elementFrom_->getView(CElementView::FULL), localElement_->getView(CElementView::FULL)) ; 1761 gathererConnector_ -> computeConnector() ; 1762 } 1763 else if (phasis==3) 1764 { 1765 CArray<bool,1> localMask ; 1766 gathererConnector_->transfer(event,localMask,false) ; 1767 localElement_->addView(CElementView::WORKFLOW, localMask) ; 1768 mask.reference(localMask.copy()) ; 1769 1770 serverFromClientConnector_ = new CGathererConnector(elementFrom_->getView(CElementView::FULL), localElement_->getView(CElementView::WORKFLOW)) ; 1771 serverFromClientConnector_->computeConnector() ; 1772 } 1773 } 1774 CATCH 1775 1776 void CAxis::sendDistributedAttributes(CContextClient* client, CScattererConnector& scattererConnector, const string& axisId) 1777 { 1778 string serverAxisId = axisId.empty() ? this->getId() : axisId ; 1779 CContext* context = CContext::getCurrent(); 1780 1781 if (hasValue) 1782 { 1783 { // send level value 1784 CEventClient event(getType(), EVENT_ID_SEND_DISTRIBUTED_ATTRIBUTE); 1785 CMessage message ; 1786 message<<serverAxisId<<string("value") ; 1787 scattererConnector.transfer(value, client, event,message) ; 1788 } 1789 } 1790 1791 if (hasBounds) 1792 { 1793 { // send bounds level value 1794 CEventClient event(getType(), EVENT_ID_SEND_DISTRIBUTED_ATTRIBUTE); 1795 CMessage message ; 1796 message<<serverAxisId<<string("bounds") ; 1797 scattererConnector.transfer(2, bounds, client, event,message) ; 1798 } 1799 } 1800 1801 if (hasLabel) 1802 { 1803 { // send label 1804 CEventClient event(getType(), EVENT_ID_SEND_DISTRIBUTED_ATTRIBUTE); 1805 CMessage message ; 1806 message<<serverAxisId<<string("label") ; 1807 // something to do ? => convert string label into char ? 1808 //clientToServerConnector_[client]->transfer(2, bounds, client, event,message) ; 1809 } 1810 } 1811 } 1812 1813 void CAxis::recvDistributedAttributes(CEventServer& event) 1814 TRY 1815 { 1816 string axisId; 1817 string type ; 1818 for (auto& subEvent : event.subEvents) (*subEvent.buffer) >> axisId >> type ; 1819 get(axisId)->recvDistributedAttributes(event, type); 1820 } 1821 CATCH 1822 1823 void CAxis::recvDistributedAttributes(CEventServer& event, const string& type) 1824 TRY 1825 { 1826 if (type=="value") 1827 { 1828 gathererConnector_->transfer(event, value, 0.); 1829 } 1830 else if (type=="bounds") 1831 { 1832 CArray<double,1> value ; 1833 gathererConnector_->transfer(event, 2, value, 0.); 1834 bounds.resize(2,n) ; 1835 bounds=CArray<double,2>(bounds.dataFirst(),shape(2,n),neverDeleteData) ; 1836 } 1837 else if (type=="label") 1838 { 1839 1840 } 1841 } 1842 CATCH 1843 1587 1844 DEFINE_REF_FUNC(Axis,axis) 1588 1845 -
XIOS/dev/dev_ym/XIOS_COUPLING/src/node/axis.hpp
r1918 r1930 18 18 #include "element.hpp" 19 19 #include "local_connector.hpp" 20 #include "scatterer_connector.hpp" 21 #include "gatherer_connector.hpp" 22 #include "distribution_type.hpp" 23 20 24 21 25 namespace xios { … … 50 54 EVENT_ID_NON_DISTRIBUTED_VALUE, 51 55 EVENT_ID_NON_DISTRIBUTED_ATTRIBUTES, 52 EVENT_ID_DISTRIBUTED_ATTRIBUTES 56 EVENT_ID_DISTRIBUTED_ATTRIBUTES, 57 EVENT_ID_AXIS_DISTRIBUTION, 58 EVENT_ID_SEND_DISTRIBUTED_ATTRIBUTE 53 59 } ; 54 60 … … 164 170 165 171 void sendNonDistributedAttributes(CContextClient* client, const string& axisId=""); 166 void sendDistributedAttributes (CContextClient* client, const string& axisId="");172 void sendDistributedAttributes_old(CContextClient* client, const string& axisId=""); 167 173 168 174 static void recvNonDistributedAttributes(CEventServer& event); 169 static void recvDistributedAttributes (CEventServer& event);175 static void recvDistributedAttributes_old(CEventServer& event); 170 176 static void recvDistributionAttribute(CEventServer& event); 171 177 void recvNonDistributedAttributes(int rank, CBufferIn& buffer); 172 void recvDistributedAttributes (vector<int>& rank, vector<CBufferIn*> buffers);178 void recvDistributedAttributes_old(vector<int>& rank, vector<CBufferIn*> buffers); 173 179 void recvDistributionAttribute(CBufferIn& buffer); 174 180 … … 225 231 226 232 233 ////////////////////////////////////////////////////////////////////////////////////// 234 // this part is related to distribution, element definition, views and connectors // 235 ////////////////////////////////////////////////////////////////////////////////////// 227 236 228 237 private: … … 242 251 public: 243 252 CLocalConnector* getModelToWorkflowConnector(void) { if (modelToWorkflowConnector_==nullptr) computeModelToWorkflowConnector() ; return modelToWorkflowConnector_ ;} 253 254 public: 255 void computeRemoteElement(CContextClient* client, EDistributionType) ; 256 void distributeToServer(CContextClient* client, std::map<int, CArray<size_t,1>>& globalIndex, const string& axisId="") ; 257 258 static void recvAxisDistribution(CEventServer& event) ; 259 void receivedAxisDistribution(CEventServer& event, int phasis) ; 260 261 void sendDistributedAttributes(CContextClient* client, CScattererConnector& scattererConnector, const string& axisId) ; 262 static void recvDistributedAttributes(CEventServer& event) ; 263 void recvDistributedAttributes(CEventServer& event, const string& type) ; 264 private: 265 map<CContextClient*, CDistributedElement*> remoteElement_ ; 266 public: 267 CDistributedElement* getRemoteElement(CContextClient* client) {return remoteElement_[client] ;} 268 private: 269 map<CContextClient*, CScattererConnector*> clientToServerConnector_ ; 270 public: 271 CScattererConnector* getClientToServerConnector(CContextClient* client) { return clientToServerConnector_[client] ;} 272 private: 273 CGathererConnector* gathererConnector_ ; 274 CGathererConnector* serverFromClientConnector_ ; 275 CDistributedElement* elementFrom_ ; 276 public: 277 CGathererConnector* getServerFromClientConnector(void) { return serverFromClientConnector_ ;} 278 244 279 245 280 -
XIOS/dev/dev_ym/XIOS_COUPLING/src/node/domain.cpp
r1918 r1930 1745 1745 this->completeLonLatClient(); 1746 1746 this->initializeLocalElement() ; 1747 this->addFullView() ; 1748 this->addWorkflowView() ; 1749 this->addModelView() ; 1747 this->addFullView() ; // probably do not automatically add View, but only if requested 1748 this->addWorkflowView() ; // probably do not automatically add View, but only if requested 1749 this->addModelView() ; // probably do not automatically add View, but only if requested 1750 1750 // testing ? 1751 /* 1751 1752 CLocalView* local = localElement_->getView(CElementView::WORKFLOW) ; 1752 1753 CLocalView* model = localElement_->getView(CElementView::MODEL) ; … … 1769 1770 gridTest1.transfer(data_i_index,out1,-111) ; 1770 1771 gridTest2.transfer(out1, out2,-111) ; 1771 1772 */ 1772 1773 this->checkAttributes_done_ = true; 1773 1774 } … … 1820 1821 for(int k=0;k<dataSize;k++) 1821 1822 { 1822 i=data_i_index(k)+data_ibegin ; // bad 1823 j=data_j_index(k)+data_jbegin ; // bad 1824 if (i>=0 && i<ni && j>=0 && j<nj) index(k)=i+j*ni ; 1825 else index(k)=-1 ; 1823 if (data_dim==2) 1824 { 1825 i=data_i_index(k)+data_ibegin ; // bad 1826 j=data_j_index(k)+data_jbegin ; // bad 1827 if (i>=0 && i<ni && j>=0 && j<nj) index(k)=i+j*ni ; 1828 else index(k)=-1 ; 1829 } 1830 else if (data_dim==1) 1831 { 1832 i=data_i_index(k)+data_ibegin ; // bad 1833 if (i>=0 && i<ni*nj) index(k)=i ; 1834 else index(k)=-1 ; 1835 } 1826 1836 } 1827 1837 localElement_->addView(CElementView::MODEL, index) ; … … 2194 2204 this->sendAllAttributesToServer(client) ; 2195 2205 this->sendDistributionAttributes(client); 2196 this->sendIndex(client); 2197 this->sendLonLat(client); 2198 this->sendArea(client); 2199 this->sendDataIndex(client); 2200 2201 // test new connector functionnality 2202 this->sendDomainDistribution(client) ; 2206 //this->sendIndex(client); 2207 //this->sendLonLat(client); 2208 //this->sendArea(client); 2209 //this->sendDataIndex(client); 2210 2203 2211 } 2204 2212 … … 2232 2240 } 2233 2241 2242 2243 void CDomain::computeRemoteElement(CContextClient* client, EDistributionType type) 2244 TRY 2245 { 2246 CContext* context = CContext::getCurrent(); 2247 map<int, CArray<size_t,1>> globalIndex ; 2248 2249 if (type==EDistributionType::BANDS) // Bands distribution to send to file server 2250 { 2251 int nbServer = client->serverSize; 2252 std::vector<int> nGlobDomain(2); 2253 nGlobDomain[0] = this->ni_glo; 2254 nGlobDomain[1] = this->nj_glo; 2255 2256 // to be changed in future, need to rewrite more simply domain distribution 2257 CServerDistributionDescription serverDescription(nGlobDomain, nbServer); 2258 int distributedPosition ; 2259 if (isUnstructed_) distributedPosition = 0 ; 2260 else distributedPosition = 1 ; 2261 2262 std::vector<std::vector<int> > serverIndexBegin = serverDescription.getServerIndexBegin(); 2263 std::vector<std::vector<int> > serverDimensionSizes = serverDescription.getServerDimensionSizes(); 2264 vector<unordered_map<size_t,vector<int>>> indexServerOnElement ; 2265 CArray<int,1> axisDomainOrder(1) ; axisDomainOrder(0)=2 ; 2266 auto zeroIndex=serverDescription.computeServerGlobalByElement(indexServerOnElement, context->getIntraCommRank(), context->getIntraCommSize(), 2267 axisDomainOrder,distributedPosition) ; 2268 // distribution is very bad => to redo 2269 // convert indexServerOnElement => map<int,CArray<size_t,1>> - need to be changed later 2270 map<int, vector<size_t>> vectGlobalIndex ; 2271 for(auto& indexRanks : indexServerOnElement[0]) 2272 { 2273 size_t index=indexRanks.first ; 2274 auto& ranks=indexRanks.second ; 2275 for(int rank : ranks) vectGlobalIndex[rank].push_back(index) ; 2276 } 2277 for(auto& vect : vectGlobalIndex ) globalIndex.emplace(vect.first, CArray<size_t,1>(vect.second.data(), shape(vect.second.size()),duplicateData)) ; 2278 } 2279 else if (type==EDistributionType::NONE) // domain is not distributed ie all servers get the same local domain 2280 { 2281 int nbServer = client->serverSize; 2282 int nglo=ni_glo*nj_glo ; 2283 CArray<size_t,1> indGlo ; 2284 for(size_t i=0;i<nglo;i++) indGlo(i) = i ; 2285 for (auto& rankServer : client->getRanksServerLeader()) globalIndex[rankServer] = indGlo ; 2286 } 2287 remoteElement_[client] = new CDistributedElement(ni_glo*nj_glo, globalIndex) ; 2288 remoteElement_[client]->addFullView() ; 2289 } 2290 CATCH 2291 2292 2293 2294 void CDomain::distributeToServer(CContextClient* client, map<int, CArray<size_t,1>>& globalIndex, const string& domainId) 2295 TRY 2296 { 2297 string serverDomainId = domainId.empty() ? this->getId() : domainId ; 2298 CContext* context = CContext::getCurrent(); 2299 2300 this->sendAllAttributesToServer(client, serverDomainId) ; 2301 2302 CDistributedElement scatteredElement(ni_glo*nj_glo, globalIndex) ; 2303 scatteredElement.addFullView() ; 2304 CScattererConnector scattererConnector(localElement_->getView(CElementView::FULL), scatteredElement.getView(CElementView::FULL), context->getIntraComm()) ; 2305 scattererConnector.computeConnector() ; 2306 2307 // phase 0 2308 // send remote element to construct the full view on server, ie without hole 2309 CEventClient event0(getType(), EVENT_ID_DOMAIN_DISTRIBUTION); 2310 CMessage message0 ; 2311 message0<<serverDomainId<<0 ; 2312 remoteElement_[client]->sendToServer(client,event0,message0) ; 2313 2314 // phase 1 2315 // send the full view of element to construct the connector which connect distributed data coming from client to the full local view 2316 CEventClient event1(getType(), EVENT_ID_DOMAIN_DISTRIBUTION); 2317 CMessage message1 ; 2318 message1<<serverDomainId<<1<<localElement_->getView(CElementView::FULL)->getGlobalSize() ; 2319 scattererConnector.transfer(localElement_->getView(CElementView::FULL)->getGlobalIndex(),client,event1,message1) ; 2320 2321 sendDistributedAttributes(client, scattererConnector, domainId) ; 2322 2323 2324 // phase 2 send the mask : data index + mask2D 2325 CArray<bool,1> maskIn(localElement_->getView(CElementView::WORKFLOW)->getSize()); 2326 CArray<bool,1> maskOut ; 2327 CLocalConnector workflowToFull(localElement_->getView(CElementView::WORKFLOW), localElement_->getView(CElementView::FULL)) ; 2328 workflowToFull.computeConnector() ; 2329 maskIn=true ; 2330 workflowToFull.transfer(maskIn,maskOut,false) ; 2331 2332 2333 // phase 3 : prepare grid scatterer connector to send data from client to server 2334 map<int,CArray<size_t,1>> workflowGlobalIndex ; 2335 map<int,CArray<bool,1>> maskOut2 ; 2336 scattererConnector.transfer(maskOut, maskOut2, false) ; 2337 scatteredElement.addView(CElementView::WORKFLOW, maskOut2) ; 2338 scatteredElement.getView(CElementView::WORKFLOW)->getGlobalIndexView(workflowGlobalIndex) ; 2339 // create new workflow view for scattered element 2340 CDistributedElement clientToServerElement(scatteredElement.getGlobalSize(), workflowGlobalIndex) ; 2341 clientToServerElement.addFullView() ; 2342 CEventClient event2(getType(), EVENT_ID_DOMAIN_DISTRIBUTION); 2343 CMessage message2 ; 2344 message2<<serverDomainId<<2 ; 2345 clientToServerElement.sendToServer(client, event2, message2) ; 2346 clientToServerConnector_[client] = new CScattererConnector(localElement_->getView(CElementView::WORKFLOW), 2347 clientToServerElement.getView(CElementView::FULL), context->getIntraComm()) ; 2348 clientToServerConnector_[client]->computeConnector() ; 2349 2350 2351 CEventClient event3(getType(), EVENT_ID_DOMAIN_DISTRIBUTION); 2352 CMessage message3 ; 2353 message3<<serverDomainId<<3 ; 2354 clientToServerConnector_[client]->transfer(maskIn,client,event3,message3) ; 2355 2356 } 2357 CATCH 2358 2359 void CDomain::recvDomainDistribution(CEventServer& event) 2360 TRY 2361 { 2362 string domainId; 2363 int phasis ; 2364 for (auto& subEvent : event.subEvents) (*subEvent.buffer) >> domainId >> phasis ; 2365 get(domainId)->receivedDomainDistribution(event, phasis); 2366 } 2367 CATCH 2368 2369 void CDomain::receivedDomainDistribution(CEventServer& event, int phasis) 2370 TRY 2371 { 2372 CContext* context = CContext::getCurrent(); 2373 if (phasis==0) // receive the remote element to construct the full view 2374 { 2375 localElement_ = new CLocalElement(context->getIntraCommRank(),event) ; 2376 localElement_->addFullView() ; 2377 // construct the local dimension and indexes 2378 auto& globalIndex=localElement_->getGlobalIndex() ; 2379 int nij=globalIndex.numElements() ; 2380 int minI=ni_glo,maxI=-1,minJ=nj_glo,maxJ=-1 ; 2381 int i,j ; 2382 int niGlo=ni_glo, njGlo=njGlo ; 2383 for(int ij=0;ij<nij;ij++) 2384 { 2385 j=globalIndex(ij)/niGlo ; 2386 i=globalIndex(ij)%niGlo ; 2387 if (i<minI) minI=i ; 2388 if (i>maxI) maxI=i ; 2389 if (j<minJ) minJ=j ; 2390 if (j>maxJ) maxJ=j ; 2391 } 2392 if (maxI>=minI) { ibegin=minI ; ni=maxI-minI+1 ; } 2393 else {ibegin=0; ni=0 ;} 2394 if (maxJ>=minJ) { jbegin=minJ ; nj=maxJ-minJ+1 ; } 2395 else {jbegin=0; nj=0 ;} 2396 2397 } 2398 else if (phasis==1) // receive the sent view from client to construct the full distributed full view on server 2399 { 2400 CContext* context = CContext::getCurrent(); 2401 CDistributedElement* elementFrom = new CDistributedElement(event) ; 2402 elementFrom->addFullView() ; 2403 gathererConnector_ = new CGathererConnector(elementFrom->getView(CElementView::FULL), localElement_->getView(CElementView::FULL)) ; 2404 gathererConnector_->computeConnector() ; 2405 } 2406 else if (phasis==2) 2407 { 2408 delete gathererConnector_ ; 2409 elementFrom_ = new CDistributedElement(event) ; 2410 elementFrom_->addFullView() ; 2411 gathererConnector_ = new CGathererConnector(elementFrom_->getView(CElementView::FULL), localElement_->getView(CElementView::FULL)) ; 2412 gathererConnector_ -> computeConnector() ; 2413 } 2414 else if (phasis==3) 2415 { 2416 CArray<bool,1> localMask ; 2417 gathererConnector_->transfer(event,localMask,false) ; 2418 localElement_->addView(CElementView::WORKFLOW, localMask) ; 2419 mask_1d.reference(localMask.copy()) ; 2420 2421 serverFromClientConnector_ = new CGathererConnector(elementFrom_->getView(CElementView::FULL), localElement_->getView(CElementView::WORKFLOW)) ; 2422 serverFromClientConnector_->computeConnector() ; 2423 } 2424 } 2425 CATCH 2426 2427 2428 void CDomain::sendDistributedAttributes(CContextClient* client, CScattererConnector& scattererConnector, const string& domainId) 2429 { 2430 string serverDomainId = domainId.empty() ? this->getId() : domainId ; 2431 CContext* context = CContext::getCurrent(); 2432 2433 if (hasLonLat) 2434 { 2435 { // send longitude 2436 CEventClient event(getType(), EVENT_ID_SEND_DISTRIBUTED_ATTRIBUTE); 2437 CMessage message ; 2438 message<<serverDomainId<<string("lon") ; 2439 scattererConnector.transfer(lonvalue, client, event,message) ; 2440 } 2441 2442 { // send latitude 2443 CEventClient event(getType(), EVENT_ID_SEND_DISTRIBUTED_ATTRIBUTE); 2444 CMessage message ; 2445 message<<serverDomainId<<string("lat") ; 2446 scattererConnector.transfer(latvalue, client, event, message) ; 2447 } 2448 } 2449 2450 if (hasBounds) 2451 { 2452 { // send longitude boudaries 2453 CEventClient event(getType(), EVENT_ID_SEND_DISTRIBUTED_ATTRIBUTE); 2454 CMessage message ; 2455 message<<serverDomainId<<string("boundslon") ; 2456 scattererConnector.transfer(nvertex, bounds_lonvalue, client, event, message ) ; 2457 } 2458 2459 { // send latitude boudaries 2460 CEventClient event(getType(), EVENT_ID_SEND_DISTRIBUTED_ATTRIBUTE); 2461 CMessage message ; 2462 message<<serverDomainId<<string("boundslat") ; 2463 scattererConnector.transfer(nvertex, bounds_latvalue, client, event, message ) ; 2464 } 2465 } 2466 2467 if (hasArea) 2468 { // send area 2469 CEventClient event(getType(), EVENT_ID_SEND_DISTRIBUTED_ATTRIBUTE); 2470 CMessage message ; 2471 message<<serverDomainId<<string("area") ; 2472 scattererConnector.transfer(areavalue, client, event,message) ; 2473 } 2474 } 2475 2476 void CDomain::recvDistributedAttributes(CEventServer& event) 2477 TRY 2478 { 2479 string domainId; 2480 string type ; 2481 for (auto& subEvent : event.subEvents) (*subEvent.buffer) >> domainId >> type ; 2482 get(domainId)->recvDistributedAttributes(event, type); 2483 } 2484 CATCH 2485 2486 void CDomain::recvDistributedAttributes(CEventServer& event, const string& type) 2487 TRY 2488 { 2489 if (type=="lon") 2490 { 2491 CArray<double,1> value ; 2492 gathererConnector_->transfer(event, value, 0.); 2493 lonvalue_2d.resize(ni,nj) ; 2494 lonvalue_2d=CArray<double,2>(value.dataFirst(),shape(ni,nj),neverDeleteData) ; 2495 } 2496 else if (type=="lat") 2497 { 2498 CArray<double,1> value ; 2499 gathererConnector_->transfer(event, value, 0.); 2500 latvalue_2d.resize(ni,nj) ; 2501 latvalue_2d=CArray<double,2>(value.dataFirst(),shape(ni,nj),neverDeleteData) ; 2502 } 2503 else if (type=="boundslon") 2504 { 2505 CArray<double,1> value ; 2506 gathererConnector_->transfer(event, nvertex, value, 0.); 2507 bounds_lon_2d.resize(nvertex,ni,nj) ; 2508 bounds_lon_2d=CArray<double,3>(value.dataFirst(),shape(nvertex,ni,nj),neverDeleteData) ; 2509 } 2510 else if (type=="boundslat") 2511 { 2512 CArray<double,1> value ; 2513 gathererConnector_->transfer(event, nvertex, value, 0.); 2514 bounds_lat_2d.resize(nvertex,ni,nj) ; 2515 bounds_lat_2d=CArray<double,3>(value.dataFirst(),shape(nvertex,ni,nj),neverDeleteData) ; 2516 } 2517 else if (type=="area") 2518 { 2519 CArray<double,1> value ; 2520 gathererConnector_->transfer(event, value, 0.); 2521 area.resize(ni,nj) ; 2522 area=CArray<double,2>(value.dataFirst(),shape(ni,nj),neverDeleteData) ; 2523 } 2524 } 2525 CATCH 2234 2526 2235 2527 void CDomain::sendDomainDistribution(CContextClient* client, const string& domainId) … … 2308 2600 2309 2601 2310 void CDomain::recvDomainDistribution(CEventServer& event) 2311 TRY 2312 { 2313 string domainId; 2314 int phasis ; 2315 for (auto& subEvent : event.subEvents) (*subEvent.buffer) >> domainId >> phasis ; 2316 get(domainId)->receivedDomainDistribution(event, phasis); 2317 } 2318 CATCH 2319 2320 void CDomain::receivedDomainDistribution(CEventServer& event, int phasis) 2321 TRY 2322 { 2323 CContext* context = CContext::getCurrent(); 2324 if (phasis==0) 2325 { 2326 localElement_ = new CLocalElement(context->getIntraCommRank(),event) ; 2327 localElement_->addFullView() ; 2328 } 2329 else if (phasis==1) 2330 { 2331 CContext* context = CContext::getCurrent(); 2332 CDistributedElement* elementFrom = new CDistributedElement(event) ; 2333 elementFrom->addFullView() ; 2334 gathererConnector_ = new CGathererConnector(elementFrom->getView(CElementView::FULL), localElement_->getView(CElementView::FULL)) ; 2335 gathererConnector_->computeConnector() ; 2336 } 2337 else if (phasis==2) 2338 { 2339 CArray<size_t,1> globalIndex ; 2340 //gathererConnector_->transfer(event,globalIndex) ; 2341 CGridGathererConnector gridGathererConnector({gathererConnector_}) ; 2342 gridGathererConnector.transfer(event, globalIndex) ; 2343 } 2344 else if (phasis==3) 2345 { 2346 2347 } 2348 } 2349 CATCH 2350 2602 2351 2603 2352 2604 … … 2707 2959 return true; 2708 2960 break; 2961 case EVENT_ID_SEND_DISTRIBUTED_ATTRIBUTE: 2962 recvDistributedAttributes(event); 2963 return true; 2964 break; 2709 2965 default: 2710 2966 ERROR("bool CDomain::dispatchEvent(CEventServer& event)", -
XIOS/dev/dev_ym/XIOS_COUPLING/src/node/domain.hpp
r1918 r1930 20 20 #include "element.hpp" 21 21 #include "local_connector.hpp" 22 #include "scatterer_connector.hpp" 22 23 #include "gatherer_connector.hpp" 24 #include "distribution_type.hpp" 25 23 26 24 27 namespace xios { … … 54 57 EVENT_ID_AREA, 55 58 EVENT_ID_DATA_INDEX, EVENT_ID_SERVER_ATTRIBUT, 56 EVENT_ID_DOMAIN_DISTRIBUTION 59 EVENT_ID_DOMAIN_DISTRIBUTION, EVENT_ID_SEND_DISTRIBUTED_ATTRIBUTE 57 60 } ; 58 61 … … 220 223 private: 221 224 222 static void recvDomainDistribution(CEventServer& event) ;223 void receivedDomainDistribution(CEventServer& event, int phasis) ;224 225 226 225 void sendDomainDistribution(CContextClient* client, const string& domainId="") ; //for testing 227 226 void sendAttributes(); // ym obsolete -> to be removed … … 310 309 static bool _dummyTransformationMapList; 311 310 312 311 ////////////////////////////////////////////////////////////////////////////////////// 312 // this part is related to distribution, element definition, views and connectors // 313 ////////////////////////////////////////////////////////////////////////////////////// 313 314 private: 314 315 CLocalElement* localElement_ = nullptr ; … … 327 328 CLocalConnector* modelToWorkflowConnector_ ; 328 329 void computeModelToWorkflowConnector(void) ; 330 public: 331 CLocalConnector* getModelToWorkflowConnector(void) { if (modelToWorkflowConnector_==nullptr) computeModelToWorkflowConnector() ; return modelToWorkflowConnector_ ;} 332 333 public: 334 void computeRemoteElement(CContextClient* client, EDistributionType) ; 335 void distributeToServer(CContextClient* client, std::map<int, CArray<size_t,1>>& globalIndex, const string& domainId="") ; 336 337 static void recvDomainDistribution(CEventServer& event) ; 338 void receivedDomainDistribution(CEventServer& event, int phasis) ; 339 340 void sendDistributedAttributes(CContextClient* client, CScattererConnector& scaterrerConnector, const string& domainId) ; 341 static void recvDistributedAttributes(CEventServer& event) ; 342 void recvDistributedAttributes(CEventServer& event, const string& type) ; 343 private: 344 map<CContextClient*, CDistributedElement*> remoteElement_ ; 345 public: 346 CDistributedElement* getRemoteElement(CContextClient* client) {return remoteElement_[client] ;} 347 private: 348 map<CContextClient*, CScattererConnector*> clientToServerConnector_ ; 349 public: 350 CScattererConnector* getClientToServerConnector(CContextClient* client) { return clientToServerConnector_[client] ;} 351 private: 329 352 CGathererConnector* gathererConnector_ ; 330 331 public: 332 CLocalConnector* getModelToWorkflowConnector(void) { if (modelToWorkflowConnector_==nullptr) computeModelToWorkflowConnector() ; return modelToWorkflowConnector_ ;} 333 353 CGathererConnector* serverFromClientConnector_ ; 354 CDistributedElement* elementFrom_ ; 355 public: 356 CGathererConnector* getServerFromClientConnector(void) { return serverFromClientConnector_ ;} 357 358 359 334 360 DECLARE_REF_FUNC(Domain,domain) 335 361 -
XIOS/dev/dev_ym/XIOS_COUPLING/src/node/field.cpp
r1883 r1930 26 26 #include "file_server_reader_filter.hpp" 27 27 #include "server_to_client_filter.hpp" 28 #include "server_from_client_source_filter.hpp" 29 #include "file_reader_source_filter.hpp" 28 30 #include "tracer.hpp" 29 31 … … 148 150 CATCH 149 151 152 /* obsolete old interface 150 153 void CField::sendUpdateData(Time timeStamp, const CArray<double,1>& data, CContextClient* client) 151 154 TRY … … 204 207 } 205 208 CATCH_DUMP_ATTR 206 209 */ 210 211 void CField::sendUpdateData(Time timeStamp, const CArray<double,1>& data, CContextClient* client) 212 TRY 213 { 214 CTimer::get("Field : send data").resume(); 215 CEventClient event(getType(), EVENT_ID_UPDATE_DATA); 216 CMessage message ; 217 218 message<<getId() << timeStamp ; 219 this->getGrid()->getClientToServerConnector(client)->transfer(data, client, event, message) ; 220 CTimer::get("Field : send data").suspend(); 221 } 222 CATCH_DUMP_ATTR 223 224 /* old version obsolete 207 225 void CField::recvUpdateData(CEventServer& event) 208 226 TRY … … 224 242 } 225 243 CATCH 226 227 228 void CField::recvUpdateData(std::map<int,CBufferIn*>& rankBuffers) 229 TRY 230 { 231 if (hasCouplerIn()) recvUpdateDataFromCoupler(rankBuffers) ; 232 else recvUpdateDataFromClient(rankBuffers) ; 244 */ 245 246 void CField::recvUpdateData(CEventServer& event) 247 TRY 248 { 249 string fieldId; 250 for (auto& subEvent : event.subEvents) (*subEvent.buffer) >> fieldId ; 251 get(fieldId)->receiveUpdateData(event); 233 252 } 234 253 CATCH 235 254 255 void CField::receiveUpdateData(CEventServer& event) 256 TRY 257 { 258 if (hasCouplerIn()) clientFromClientSourceFilter_->streamData(event) ; 259 else serverFromClientSourceFilter_->streamData(event) ; 260 } 261 CATCH 262 /* 263 void CField::recvUpdateDataFromClient(CEventServer& event) 264 TRY 265 { 266 Time timeStamp ; 267 for (auto& subEvent : event.subEvents) (*subEvent.buffer) >> timeStamp ; 268 269 CArray<double,1> recvData ; 270 getGrid()->getServerFromClientConnector()->transfer(event,recvData) ; 271 this->setData(recvData); 272 } 273 CATCH 274 */ 275 276 /* 277 void CField::recvUpdateDataFromCoupler(CEventServer& event) 278 TRY 279 { 280 CContext* context = CContext::getCurrent(); 281 Time timeStamp ; 282 if (wasDataAlreadyReceivedFromServer) 283 { 284 lastDataReceivedFromServer = lastDataReceivedFromServer + freq_op; 285 } 286 else 287 { 288 // unlikely to input from file server where data are received at ts=0 289 // for coupling, it would be after the first freq_op, because for now we don't have 290 // restart mecanism to send the value at ts=0. It must be changed in future 291 lastDataReceivedFromServer = context->getCalendar()->getInitDate(); 292 wasDataAlreadyReceivedFromServer = true; 293 } 294 295 CArray<double,1> recvData ; 296 getGrid()->getServerFromClientConnector()->transfer(event,recvData) ; 297 clientSourceFilter->streamData(lastDataReceivedFromServer, recvData); 298 299 } 300 CATCH_DUMP_ATTR 301 */ 302 303 304 305 306 /* old interface to be removed.... */ 236 307 void CField::recvUpdateDataFromClient(std::map<int,CBufferIn*>& rankBuffers) 237 308 TRY … … 330 401 const CDate writeDate = last_Write_srv + freq_write_srv; 331 402 last_Write_srv = writeDate; 332 grid_->computeWrittenIndex();403 // grid_->computeWrittenIndex(); -> obselete function need to be removed 333 404 /* 334 405 recvDataSrv.resize(data.numElements()) ; … … 424 495 StdString fieldId; 425 496 *buffer >> fieldId; 426 get(fieldId)->recvReadDataRequest( event.getContextServer());497 get(fieldId)->recvReadDataRequest(); 427 498 } 428 499 CATCH 429 500 430 501 /*! 431 502 Receive data request sent from client and process it … … 434 505 In the future, this should (only) be done by the last level servers. 435 506 */ 507 void CField::recvReadDataRequest(void) 508 TRY 509 { 510 fileReaderSourceFilter_->streamData() ; 511 } 512 CATCH_DUMP_ATTR 513 514 /* old interface -> to remove 436 515 void CField::recvReadDataRequest(CContextServer* server) 437 516 TRY … … 446 525 } 447 526 CATCH_DUMP_ATTR 448 527 */ 449 528 450 529 void CField::sendUpdateDataServerToClient(bool isEOF, const CArray<double,1>& data, CContextClient* client) … … 509 588 \return State of field can be read from a file 510 589 */ 590 // obsolete to remove 591 /* 511 592 CField::EReadField CField::readField(CArray<double,1>& data) 512 593 TRY … … 561 642 } 562 643 CATCH_DUMP_ATTR 644 */ 563 645 564 646 /* … … 572 654 { 573 655 string fieldId; 574 vector<int> ranks; 575 vector<CBufferIn*> buffers; 576 577 list<CEventServer::SSubEvent>::iterator it; 578 for (it = event.subEvents.begin(); it != event.subEvents.end(); ++it) 579 { 580 ranks.push_back(it->rank); 581 CBufferIn* buffer = it->buffer; 582 *buffer >> fieldId; 583 buffers.push_back(buffer); 584 } 585 get(fieldId)->recvReadDataReady(ranks, buffers); 656 for (auto& subEvent : event.subEvents) (*subEvent.buffer) >> fieldId ; 657 get(fieldId)->recvReadDataReady(event); 586 658 } 587 659 CATCH 588 660 589 661 662 /* old interface to be removed ..*/ 590 663 void CField::recvUpdateDataFromCoupler(std::map<int,CBufferIn*>& rankBuffers) 591 664 TRY … … 622 695 } 623 696 CATCH_DUMP_ATTR 697 698 624 699 /*! 625 700 Receive read data from server … … 627 702 \param [in] buffers buffers containing read data 628 703 */ 704 // old interface to remove 629 705 void CField::recvReadDataReady(vector<int> ranks, vector<CBufferIn*> buffers) 630 706 TRY … … 667 743 CATCH_DUMP_ATTR 668 744 745 746 747 void CField::receiveReadDataReady(CEventServer& event) 748 TRY 749 { 750 clientFromServerSourceFilter_->streamData(event) ; 751 } 752 CATCH_DUMP_ATTR 753 754 755 669 756 void CField::checkForLateDataFromCoupler(void) 670 757 TRY … … 677 764 traceOff() ; 678 765 timer.suspend(); 679 680 bool isDataLate; 766 767 bool isDataLate; 681 768 do 682 769 { 683 if (wasDataAlreadyReceivedFromServer) isDataLate = lastDataReceivedFromServer + freq_offset + freq_op <= currentDate ; 684 else isDataLate = context->getCalendar()->getInitDate()+freq_offset <= currentDate ; 685 770 isDataLate=clientFromClientSourceFilter_->isDataLate() ; 686 771 if (isDataLate) 687 772 { 688 773 timer.resume(); 689 //ym context->checkBuffersAndListen();690 //ym context->eventLoop();691 774 context->globalEventLoop(); 692 693 775 timer.suspend(); 694 776 } … … 709 791 { 710 792 CContext* context = CContext::getCurrent(); 711 const CDate& currentDate = context->getCalendar()->getCurrentDate();712 713 793 // Check if data previously requested has been received as expected 714 if (wasDataRequestedFromServer && ! isEOF)794 if (wasDataRequestedFromServer && !clientFromServerSourceFilter_->isEOF()) 715 795 { 716 796 CTimer timer("CField::checkForLateDataFromServer"); … … 722 802 do 723 803 { 724 const CDate nextDataDue = wasDataAlreadyReceivedFromServer ? (lastDataReceivedFromServer + fileIn_->output_freq) : context->getCalendar()->getInitDate(); 725 isDataLate = (nextDataDue <= currentDate); 726 804 isDataLate=clientFromServerSourceFilter_->isDataLate(); 727 805 if (isDataLate) 728 806 { … … 744 822 if (isDataLate) 745 823 ERROR("void CField::checkForLateDataFromServer(void)", 746 << "Late data at timestep = " << c urrentDate);824 << "Late data at timestep = " << context->getCalendar()->getCurrentDate()); 747 825 } 748 826 } … … 755 833 { 756 834 checkForLateDataFromServer() ; 757 serverSourceFilter->trigger(CContext::getCurrent()->getCalendar()->getCurrentDate()) ;835 clientFromServerSourceFilter_->trigger(CContext::getCurrent()->getCalendar()->getCurrentDate()) ; 758 836 } 759 837 else if (hasCouplerIn()) 760 838 { 761 839 checkForLateDataFromCoupler() ; 762 client SourceFilter->trigger(CContext::getCurrent()->getCalendar()->getCurrentDate()) ;840 clientFromClientSourceFilter_->trigger(CContext::getCurrent()->getCalendar()->getCurrentDate()) ; 763 841 } 764 842 } … … 769 847 TRY 770 848 { 771 mustAutoTrigger = serverSourceFilter ? serverSourceFilter->mustAutoTrigger() : false;849 mustAutoTrigger = clientFromServerSourceFilter_ ? clientFromServerSourceFilter_->mustAutoTrigger() : false; 772 850 } 773 851 CATCH_DUMP_ATTR … … 777 855 { 778 856 if (mustAutoTrigger) 779 serverSourceFilter->trigger(CContext::getCurrent()->getCalendar()->getCurrentDate());857 clientFromServerSourceFilter_->trigger(CContext::getCurrent()->getCalendar()->getCurrentDate()); 780 858 } 781 859 CATCH_DUMP_ATTR … … 860 938 TRY 861 939 { 862 if (clientSourceFilter) 863 return atCurrentTimestep ? clientSourceFilter->isDataExpected(CContext::getCurrent()->getCalendar()->getCurrentDate()) : true; 864 else if (storeFilter) 865 return true; 940 if (modelToClientSourceFilter_) 941 return atCurrentTimestep ? modelToClientSourceFilter_->isDataExpected(CContext::getCurrent()->getCalendar()->getCurrentDate()) : true; 942 else if (clientToModelStoreFilter_) return true; 866 943 else if (instantDataFilter) 867 944 ERROR("bool CField::isActive(bool atCurrentTimestep)", … … 1412 1489 1413 1490 if (check_if_active.isEmpty()) check_if_active = false; 1414 clientSourceFilter = std::shared_ptr<CSourceFilter>(new CSourceFilter(gc, grid_, false, true, NoneDu, false, detectMissingValues, defaultValue));1415 clientSourceFilter-> connectOutput(inputFilter,0) ;1491 modelToClientSourceFilter_ = std::shared_ptr<CModelToClientSourceFilter>(new CModelToClientSourceFilter(gc, grid_, detectMissingValues, defaultValue)); 1492 modelToClientSourceFilter_ -> connectOutput(inputFilter,0) ; 1416 1493 } 1417 1494 … … 1421 1498 void CField::connectToClientInput(CGarbageCollector& gc) 1422 1499 { 1423 clientSourceFilter = std::shared_ptr<CSourceFilter>(new CSourceFilter(gc, grid_, false, false));1424 clientSourceFilter-> connectOutput(inputFilter,0) ;1500 serverFromClientSourceFilter_ = std::shared_ptr<CServerFromClientSourceFilter>(new CServerFromClientSourceFilter(gc, grid_)); 1501 serverFromClientSourceFilter_ -> connectOutput(inputFilter,0) ; 1425 1502 } 1426 1503 … … 1450 1527 if (freq_op.isEmpty()) freq_op.setValue(TimeStep); 1451 1528 if (freq_offset.isEmpty()) freq_offset.setValue(freq_op.getValue() - TimeStep); 1529 1530 /* old 1452 1531 1453 1532 freq_operation_srv = freq_op ; … … 1458 1537 clientSourceFilter = std::shared_ptr<CSourceFilter>(new CSourceFilter(gc, grid_, false, false, freq_offset, true)) ; 1459 1538 clientSourceFilter -> connectOutput(inputFilter,0) ; 1539 1540 */ 1541 // new 1542 1543 clientFromClientSourceFilter_ = std::shared_ptr<CClientFromClientSourceFilter>(new CClientFromClientSourceFilter(gc, this)) ; 1544 clientFromClientSourceFilter_ -> connectOutput(inputFilter,0) ; 1545 1460 1546 } 1461 1462 1547 1463 1548 /*! … … 1469 1554 instantDataFilter->connectOutput(fileServerWriterFilter, 0); 1470 1555 } 1471 1556 1472 1557 /*! 1473 1558 * Connect field to a file reader filter to read data from file (on server side). … … 1475 1560 void CField::connectToFileReader(CGarbageCollector& gc) 1476 1561 { 1477 fileServerReaderFilter_ = std::shared_ptr<CFileServerReaderFilter>(new CFileServerReaderFilter(gc, this)); 1478 fileServerReaderFilter_->connectOutput(inputFilter, 0); 1479 } 1562 fileReaderSourceFilter_ = std::shared_ptr<CFileReaderSourceFilter>(new CFileReaderSourceFilter(gc, this)); 1563 instantDataFilter->connectOutput(inputFilter, 0); 1564 } 1565 1480 1566 1481 1567 /*! … … 1484 1570 void CField::connectToModelOutput(CGarbageCollector& gc) 1485 1571 { 1486 const bool detectMissingValues = (!detect_missing_value.isEmpty() && !default_value.isEmpty() && detect_missing_value == true); 1487 const double defaultValue = detectMissingValues ? default_value : (!default_value.isEmpty() ? default_value : 0.0); 1488 1489 storeFilter = std::shared_ptr<CStoreFilter>(new CStoreFilter(gc, CContext::getCurrent(), grid_, detectMissingValues, defaultValue)); 1490 instantDataFilter->connectOutput(storeFilter, 0); 1572 clientToModelStoreFilter_ = std::shared_ptr<CClientToModelStoreFilter>(new CClientToModelStoreFilter(gc, this)); 1573 instantDataFilter->connectOutput(clientToModelStoreFilter_, 0); 1491 1574 } 1492 1575 … … 1565 1648 1566 1649 // If the field data is to be read by the client or/and written to a file 1567 if (enableOutput && ! storeFilter&& !fileWriterFilter)1650 if (enableOutput && !clientToModelStoreFilter_ && !fileWriterFilter) 1568 1651 { 1569 1652 if (getRelFile() && (getRelFile()->mode.isEmpty() || getRelFile()->mode == CFile::mode_attr::write)) … … 1580 1663 1581 1664 // If the field data is to be read by the client or/and written to a file 1582 if (enableOutput && ! storeFilter&& !fileWriterFilter)1665 if (enableOutput && !clientToModelStoreFilter_ && !fileWriterFilter) 1583 1666 { 1584 1667 if (getRelFile() && (getRelFile()->mode.isEmpty() || getRelFile()->mode == CFile::mode_attr::write)) … … 1633 1716 1634 1717 // If the field data is to be read by the client or/and written to a file 1635 if (enableOutput && ! storeFilter&& !fileWriterFilter)1718 if (enableOutput && !clientToModelStoreFilter_ && !fileWriterFilter) 1636 1719 { 1637 1720 if (!read_access.isEmpty() && read_access) 1638 1721 { 1639 storeFilter = std::shared_ptr<CStoreFilter>(new CStoreFilter(gc, CContext::getCurrent(), grid_, 1640 detectMissingValues, defaultValue)); 1641 instantDataFilter->connectOutput(storeFilter, 0); 1722 clientToModelStoreFilter_ = std::shared_ptr<CClientToModelStoreFilter>(new CClientToModelStoreFilter(gc, this)); 1723 instantDataFilter->connectOutput(clientToModelStoreFilter_, 0); 1642 1724 } 1643 1725 -
XIOS/dev/dev_ym/XIOS_COUPLING/src/node/field.hpp
r1883 r1930 19 19 #include "pass_through_filter.hpp" 20 20 #include "temporal_filter.hpp" 21 22 23 24 namespace xios { 21 #include "model_to_client_source_filter.hpp" 22 #include "client_from_client_source_filter.hpp" 23 #include "client_from_server_source_filter.hpp" 24 #include "client_to_model_store_filter.hpp" 25 26 27 28 29 namespace xios 30 { 25 31 26 32 /// ////////////////////// Déclarations ////////////////////// /// … … 40 46 class COutputPin; 41 47 class CSourceFilter; 42 class CStoreFilter;43 48 class CFileWriterFilter; 44 49 class CFileServerWriterFilter; 45 class CFile ServerReaderFilter;50 class CFileReaderSourceFilter; 46 51 class CServerToClientFilter; 52 class CModelToClientSourceFilter; 53 class CServerFromClientSourceFilter; 47 54 ///-------------------------------------------------------------- 48 55 … … 66 73 typedef CFieldAttributes SuperClassAttribute; 67 74 75 public : 68 76 enum EReadField 69 77 { … … 188 196 189 197 static void recvUpdateData(CEventServer& event); 190 void recvUpdateData(std::map<int,CBufferIn*>& rankBuffers); 191 void recvUpdateDataFromClient(std::map<int,CBufferIn*>& rankBuffers); 192 void recvUpdateDataFromCoupler(std::map<int,CBufferIn*>& rankBuffers); 198 void receiveUpdateData(CEventServer& event); 199 200 void recvUpdateData(std::map<int,CBufferIn*>& rankBuffers); // old interface to be removed 201 void recvUpdateDataFromClient(std::map<int,CBufferIn*>& rankBuffers); // old interface to be removed 202 void recvUpdateDataFromCoupler(std::map<int,CBufferIn*>& rankBuffers); // old interface to be removed 193 203 194 204 void writeField(const CArray<double,1>& data); … … 196 206 bool sendReadDataRequestIfNeeded(void); 197 207 static void recvReadDataRequest(CEventServer& event); 198 void recvReadDataRequest( CContextServer* server);208 void recvReadDataRequest(void); 199 209 EReadField readField(CArray<double,1>& data); 200 210 static void recvReadDataReady(CEventServer& event); 201 void recvReadDataReady(vector<int> ranks, vector<CBufferIn*> buffers); 202 void recvDataFromCoupler(vector<int> ranks, vector<CBufferIn*> buffers) ; 211 void receiveReadDataReady(CEventServer& event); 212 void recvReadDataReady(vector<int> ranks, vector<CBufferIn*> buffers); // old interface to remove 213 void recvDataFromCoupler(vector<int> ranks, vector<CBufferIn*> buffers) ; // old interface to remove 203 214 void checkForLateDataFromServer(void); 204 215 void checkForLateDataFromCoupler(void) ; … … 393 404 394 405 //! The source filter for data provided by the client 395 std::shared_ptr<CSourceFilter> clientSourceFilter; 396 406 std::shared_ptr<CSourceFilter> clientSourceFilter; // obsolete to remove 407 408 //! The source filter for data provided by the model to enter the client workflow 409 std::shared_ptr<CModelToClientSourceFilter> modelToClientSourceFilter_; 410 411 //! The source filter for data provided by the model to enter the client workflow 412 std::shared_ptr<CClientToModelStoreFilter> clientToModelStoreFilter_; 413 414 //! The source filter for data provided by the client that send data to server workflow 415 std::shared_ptr<CServerFromClientSourceFilter> serverFromClientSourceFilter_; 416 417 //! The source filter for data provided by an other to enter the current client workflow (coupling mode) 418 std::shared_ptr<CClientFromClientSourceFilter> clientFromClientSourceFilter_; 419 420 //! The source filter for data provided by server to enter the current client workflow (reading mode) 421 std::shared_ptr<CClientFromServerSourceFilter> clientFromServerSourceFilter_; 422 423 //! The source filter for data read from file on server side 424 std::shared_ptr<CFileReaderSourceFilter> fileReaderSourceFilter_; 425 397 426 //! The source filter for data provided by the server 398 std::shared_ptr<CSourceFilter> serverSourceFilter; 399 400 //! The terminal filter which stores the instant data 401 std::shared_ptr<CStoreFilter> storeFilter; 427 std::shared_ptr<CSourceFilter> serverSourceFilter; // obsolete to remove 402 428 403 429 //! The terminal filter which writes the data to file … … 407 433 std::shared_ptr<CFileServerWriterFilter> fileServerWriterFilter; 408 434 409 //! The source filter which read data from file 410 std::shared_ptr<CFileServerReaderFilter> fileServerReaderFilter_; 411 412 //! The terminal filter which send data from file server to client 435 //! The terminal filter which send data from server to client 413 436 std::shared_ptr<CServerToClientFilter> serverToClientFilter_; 414 437 -
XIOS/dev/dev_ym/XIOS_COUPLING/src/node/field_impl.hpp
r1622 r1930 19 19 TRY 20 20 { 21 if ( clientSourceFilter)21 if (modelToClientSourceFilter_) 22 22 { 23 23 if (check_if_active.isEmpty() || (!check_if_active.isEmpty() && (!check_if_active) || isActive(true))) 24 clientSourceFilter->streamData(CContext::getCurrent()->getCalendar()->getCurrentDate(), _data);24 modelToClientSourceFilter_->streamData(CContext::getCurrent()->getCalendar()->getCurrentDate(), _data); 25 25 } 26 26 else if (instantDataFilter) … … 34 34 TRY 35 35 { 36 if ( storeFilter)36 if (clientToModelStoreFilter_) 37 37 { 38 CDataPacket::StatusCode status = storeFilter->getData(CContext::getCurrent()->getCalendar()->getCurrentDate(), _data);38 CDataPacket::StatusCode status = clientToModelStoreFilter_->getData(CContext::getCurrent()->getCalendar()->getCurrentDate(), _data); 39 39 40 40 if (status == CDataPacket::END_OF_STREAM) -
XIOS/dev/dev_ym/XIOS_COUPLING/src/node/grid.cpp
r1918 r1930 19 19 #include "grid_generate.hpp" 20 20 #include "server.hpp" 21 #include "distribution_type.hpp" 22 #include "grid_remote_connector.hpp" 23 #include "grid_elements.hpp" 24 #include "grid_local_view.hpp" 25 21 26 22 27 namespace xios { … … 79 84 StdString CGrid::GetDefName(void) { return CGrid::GetName(); } 80 85 ENodeType CGrid::GetType(void) { return eGrid; } 86 87 88 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 89 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 90 ///////// MEMBER FUNCTION RELATED TO GRID CONSTRUCTION by ELEMNTS AND MANAGEMENT ///// 91 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 92 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 93 94 95 CGrid* CGrid::createGrid(CDomain* domain) 96 TRY 97 { 98 std::vector<CDomain*> vecDom(1, domain); 99 std::vector<CAxis*> vecAxis; 100 return createGrid(vecDom, vecAxis); 101 } 102 CATCH 103 104 CGrid* CGrid::createGrid(CDomain* domain, CAxis* axis) 105 TRY 106 { 107 std::vector<CDomain*> vecDom(1, domain); 108 std::vector<CAxis*> vecAxis(1, axis); 109 110 return createGrid(vecDom, vecAxis); 111 } 112 CATCH 113 114 CGrid* CGrid::createGrid(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis, 115 const CArray<int,1>& axisDomainOrder) 116 TRY 117 { 118 std::vector<CScalar*> vecScalar; 119 return createGrid(generateId(domains, axis, vecScalar, axisDomainOrder), domains, axis, vecScalar, axisDomainOrder); 120 } 121 CATCH 122 123 CGrid* CGrid::createGrid(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis, 124 const std::vector<CScalar*>& scalars, const CArray<int,1>& axisDomainOrder) 125 TRY 126 { 127 return createGrid(generateId(domains, axis, scalars, axisDomainOrder), domains, axis, scalars, axisDomainOrder); 128 } 129 CATCH 130 131 CGrid* CGrid::createGrid(StdString id, const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis, 132 const std::vector<CScalar*>& scalars, const CArray<int,1>& axisDomainOrder) 133 TRY 134 { 135 if (axisDomainOrder.numElements() > 0 && axisDomainOrder.numElements() != (domains.size() + axis.size() + scalars.size())) 136 ERROR("CGrid* CGrid::createGrid(...)", 137 << "The size of axisDomainOrder (" << axisDomainOrder.numElements() 138 << ") is not coherent with the number of elements (" << domains.size() + axis.size() <<")."); 139 140 CGrid* grid = CGridGroup::get("grid_definition")->createChild(id); 141 grid->setDomainList(domains); 142 grid->setAxisList(axis); 143 grid->setScalarList(scalars); 144 145 // By default, domains are always the first elements of a grid 146 if (0 == axisDomainOrder.numElements()) 147 { 148 int size = domains.size() + axis.size() + scalars.size(); 149 int nb = 0; 150 grid->axis_domain_order.resize(size); 151 for (int i = 0; i < size; ++i) 152 { 153 if (i < domains.size()) { 154 grid->axis_domain_order(i) = 2; 155 156 } 157 else if ((scalars.size() < (size-nb)) < size) { 158 grid->axis_domain_order(i) = 1; 159 } 160 else 161 grid->axis_domain_order(i) = 0; 162 ++nb; 163 } 164 } 165 else 166 { 167 grid->axis_domain_order.resize(axisDomainOrder.numElements()); 168 grid->axis_domain_order = axisDomainOrder; 169 } 170 171 // grid->solveElementsRefInheritance(true); 172 173 return grid; 174 } 175 CATCH 176 177 //---------------------------------------------------------------- 178 179 //! Change virtual field group to a new one 180 void CGrid::setVirtualDomainGroup(CDomainGroup* newVDomainGroup) 181 TRY 182 { 183 this->vDomainGroup_ = newVDomainGroup; 184 } 185 CATCH_DUMP_ATTR 186 187 //! Change virtual variable group to new one 188 void CGrid::setVirtualAxisGroup(CAxisGroup* newVAxisGroup) 189 TRY 190 { 191 this->vAxisGroup_ = newVAxisGroup; 192 } 193 CATCH_DUMP_ATTR 194 195 //! Change virtual variable group to new one 196 void CGrid::setVirtualScalarGroup(CScalarGroup* newVScalarGroup) 197 TRY 198 { 199 this->vScalarGroup_ = newVScalarGroup; 200 } 201 CATCH_DUMP_ATTR 202 203 //---------------------------------------------------------------- 204 205 CDomainGroup* CGrid::getVirtualDomainGroup() const 206 TRY 207 { 208 return this->vDomainGroup_; 209 } 210 CATCH 211 212 CAxisGroup* CGrid::getVirtualAxisGroup() const 213 TRY 214 { 215 return this->vAxisGroup_; 216 } 217 CATCH 218 219 CScalarGroup* CGrid::getVirtualScalarGroup() const 220 TRY 221 { 222 return this->vScalarGroup_; 223 } 224 CATCH 225 226 ///--------------------------------------------------------------- 227 228 CDomain* CGrid::addDomain(const std::string& id) 229 TRY 230 { 231 order_.push_back(2); 232 axis_domain_order.resize(order_.size()); 233 for (int idx = 0; idx < order_.size(); ++idx) axis_domain_order(idx)=order_[idx]; 234 return vDomainGroup_->createChild(id); 235 } 236 CATCH_DUMP_ATTR 237 238 CAxis* CGrid::addAxis(const std::string& id) 239 TRY 240 { 241 order_.push_back(1); 242 axis_domain_order.resize(order_.size()); 243 for (int idx = 0; idx < order_.size(); ++idx) axis_domain_order(idx)=order_[idx]; 244 return vAxisGroup_->createChild(id); 245 } 246 CATCH_DUMP_ATTR 247 248 CScalar* CGrid::addScalar(const std::string& id) 249 TRY 250 { 251 order_.push_back(0); 252 axis_domain_order.resize(order_.size()); 253 for (int idx = 0; idx < order_.size(); ++idx) axis_domain_order(idx)=order_[idx]; 254 return vScalarGroup_->createChild(id); 255 } 256 CATCH_DUMP_ATTR 257 258 259 260 261 /*! 262 \brief Get the list of domain pointers 263 \return list of domain pointers 264 */ 265 std::vector<CDomain*> CGrid::getDomains() 266 TRY 267 { 268 std::vector<CDomain*> domList; 269 if (!domList_.empty()) 270 { 271 for (int i = 0; i < domList_.size(); ++i) domList.push_back(CDomain::get(domList_[i])); 272 } 273 return domList; 274 } 275 CATCH_DUMP_ATTR 276 277 /*! 278 \brief Get the list of axis pointers 279 \return list of axis pointers 280 */ 281 std::vector<CAxis*> CGrid::getAxis() 282 TRY 283 { 284 std::vector<CAxis*> aList; 285 if (!axisList_.empty()) 286 for (int i =0; i < axisList_.size(); ++i) aList.push_back(CAxis::get(axisList_[i])); 287 288 return aList; 289 } 290 CATCH_DUMP_ATTR 291 292 /*! 293 \brief Get the list of axis pointers 294 \return list of axis pointers 295 */ 296 std::vector<CScalar*> CGrid::getScalars() 297 TRY 298 { 299 std::vector<CScalar*> sList; 300 if (!scalarList_.empty()) 301 for (int i =0; i < scalarList_.size(); ++i) sList.push_back(CScalar::get(scalarList_[i])); 302 303 return sList; 304 } 305 CATCH_DUMP_ATTR 306 307 /*! 308 \brief Get domain pointer with index 309 \return domain pointer 310 */ 311 CDomain* CGrid::getDomain(int domainIndex) 312 TRY 313 { 314 std::vector<CDomain*> domainListP = this->getDomains(); 315 if (domainListP.empty()) 316 { 317 ERROR("CGrid::getDomain(int domainIndex)", 318 << "No domain associated to this grid. " << std::endl 319 << "Grid id = " << this->getId()); 320 } 321 322 if (domainIndex >= domainListP.size() || (domainIndex < 0)) 323 ERROR("CGrid::getDomain(int domainIndex)", 324 << "Domain with the index doesn't exist " << std::endl 325 << "Grid id = " << this->getId() << std::endl 326 << "Grid has only " << domainListP.size() << " domain but domain index required is " << domainIndex << std::endl); 327 328 return domainListP[domainIndex]; 329 } 330 CATCH_DUMP_ATTR 331 332 /*! 333 \brief Get the axis pointer with index 334 \return axis pointer 335 */ 336 CAxis* CGrid::getAxis(int axisIndex) 337 TRY 338 { 339 std::vector<CAxis*> axisListP = this->getAxis(); 340 if (axisListP.empty()) 341 { 342 ERROR("CGrid::getDomain(int axisIndex)", 343 << "No axis associated to this grid. " << std::endl 344 << "Grid id = " << this->getId()); 345 } 346 347 if (axisIndex >= axisListP.size() || (axisIndex < 0)) 348 ERROR("CGrid::getDomain(int axisIndex)", 349 << "Domain with the index doesn't exist " << std::endl 350 << "Grid id = " << this->getId() << std::endl 351 << "Grid has only " << axisListP.size() << " axis but axis index required is " << axisIndex << std::endl); 352 353 return axisListP[axisIndex]; 354 } 355 CATCH_DUMP_ATTR 356 357 /*! 358 \brief Get the a scalar pointer 359 \return scalar pointer 360 */ 361 CScalar* CGrid::getScalar(int scalarIndex) 362 TRY 363 { 364 std::vector<CScalar*> scalarListP = this->getScalars(); 365 if (scalarListP.empty()) 366 { 367 ERROR("CGrid::getScalar(int scalarIndex)", 368 << "No scalar associated to this grid. " << std::endl 369 << "Grid id = " << this->getId()); 370 } 371 372 if (scalarIndex >= scalarListP.size() || (scalarIndex < 0)) 373 ERROR("CGrid::getScalar(int scalarIndex)", 374 << "Scalar with the index doesn't exist " << std::endl 375 << "Grid id = " << this->getId() << std::endl 376 << "Grid has only " << scalarListP.size() << " scalar but scalar index required is " << scalarIndex << std::endl); 377 378 return scalarListP[scalarIndex]; 379 } 380 CATCH_DUMP_ATTR 381 382 /*! 383 \brief Set domain(s) of a grid from a list 384 \param[in] domains list of domains 385 */ 386 void CGrid::setDomainList(const std::vector<CDomain*> domains) 387 TRY 388 { 389 if (isDomListSet) return; 390 std::vector<CDomain*> domList = this->getVirtualDomainGroup()->getAllChildren(); 391 if (!domains.empty() && domList.empty()) 392 { 393 for (int i = 0; i < domains.size(); ++i) 394 this->getVirtualDomainGroup()->addChild(domains[i]); 395 domList = this->getVirtualDomainGroup()->getAllChildren(); 396 } 397 398 if (!domList.empty()) 399 { 400 int sizeDom = domList.size(); 401 domList_.resize(sizeDom); 402 for (int i = 0; i < sizeDom; ++i) 403 { 404 domList_[i] = domList[i]->getId(); 405 } 406 isDomListSet = true; 407 } 408 } 409 CATCH_DUMP_ATTR 410 411 /*! 412 \brief Set axis(s) of a grid from a list 413 \param[in] axis list of axis 414 */ 415 void CGrid::setAxisList(const std::vector<CAxis*> axis) 416 TRY 417 { 418 if (isAxisListSet) return; 419 std::vector<CAxis*> aList = this->getVirtualAxisGroup()->getAllChildren(); 420 if (!axis.empty() && aList.empty()) 421 { 422 for (int i = 0; i < axis.size(); ++i) 423 this->getVirtualAxisGroup()->addChild(axis[i]); 424 aList = this->getVirtualAxisGroup()->getAllChildren(); 425 } 426 427 if (!aList.empty()) 428 { 429 int sizeAxis = aList.size(); 430 axisList_.resize(sizeAxis); 431 for (int i = 0; i < sizeAxis; ++i) 432 { 433 axisList_[i] = aList[i]->getId(); 434 } 435 isAxisListSet = true; 436 } 437 } 438 CATCH_DUMP_ATTR 439 440 /*! 441 \brief Set scalar(s) of a grid from a list 442 \param[in] scalars list of scalars 443 */ 444 void CGrid::setScalarList(const std::vector<CScalar*> scalars) 445 TRY 446 { 447 if (isScalarListSet) return; 448 std::vector<CScalar*> sList = this->getVirtualScalarGroup()->getAllChildren(); 449 if (!scalars.empty() && sList.empty()) 450 { 451 for (int i = 0; i < scalars.size(); ++i) 452 this->getVirtualScalarGroup()->addChild(scalars[i]); 453 sList = this->getVirtualScalarGroup()->getAllChildren(); 454 } 455 456 if (!sList.empty()) 457 { 458 int sizeScalar = sList.size(); 459 scalarList_.resize(sizeScalar); 460 for (int i = 0; i < sizeScalar; ++i) 461 { 462 scalarList_[i] = sList[i]->getId(); 463 } 464 isScalarListSet = true; 465 } 466 } 467 CATCH_DUMP_ATTR 468 469 /*! 470 \brief Get list of id of domains 471 \return id list of domains 472 */ 473 std::vector<StdString> CGrid::getDomainList() 474 TRY 475 { 476 setDomainList(); 477 return domList_; 478 } 479 CATCH 480 481 /*! 482 \brief Get list of id of axis 483 \return id list of axis 484 */ 485 std::vector<StdString> CGrid::getAxisList() 486 TRY 487 { 488 setAxisList(); 489 return axisList_; 490 } 491 CATCH 492 493 /*! 494 \brief Get list of id of scalar 495 \return id list of scalar 496 */ 497 std::vector<StdString> CGrid::getScalarList() 498 TRY 499 { 500 setScalarList(); 501 return scalarList_; 502 } 503 CATCH 504 505 506 void CGrid::computeElements(void) 507 { 508 const auto& domains = getDomains() ; 509 const auto& axis = getAxis() ; 510 const auto& scalars = getScalars() ; 511 int idxDomain = 0, idxAxis=0 , idxScalar=0 ; 512 513 for(auto type : order_) 514 { 515 if (type == 0) { elements_.push_back({scalars[idxScalar], TYPE_SCALAR, scalars[idxScalar], nullptr, nullptr } ) ; idxScalar++;} 516 else if (type == 1) { elements_.push_back({axis[idxAxis], TYPE_AXIS, nullptr, axis[idxAxis], nullptr}) ; idxAxis++;} 517 else if (type == 2) { elements_.push_back({domains[idxDomain], TYPE_DOMAIN, nullptr, nullptr, domains[idxDomain] }) ; idxDomain++;} 518 } 519 elementsComputed_ = true ; 520 } 521 522 523 /*! 524 Parse a grid, for now, it contains only domain, axis and scalar 525 */ 526 void CGrid::parse(xml::CXMLNode& node) 527 TRY 528 { 529 SuperClass::parse(node); 530 531 if (node.goToChildElement()) 532 { 533 StdString domainName("domain"); 534 StdString axisName("axis"); 535 StdString scalarName("scalar"); 536 do 537 { 538 if (node.getElementName() == domainName) { 539 order_.push_back(2); 540 this->getVirtualDomainGroup()->parseChild(node); 541 } 542 if (node.getElementName() == axisName) { 543 order_.push_back(1); 544 this->getVirtualAxisGroup()->parseChild(node); 545 } 546 if (node.getElementName() == scalarName) { 547 order_.push_back(0); 548 this->getVirtualScalarGroup()->parseChild(node); 549 } 550 } while (node.goToNextElement()); 551 node.goToParentElement(); 552 } 553 554 if (!order_.empty()) 555 { 556 int sizeOrd = order_.size(); 557 axis_domain_order.resize(sizeOrd); 558 for (int i = 0; i < sizeOrd; ++i) 559 { 560 axis_domain_order(i) = order_[i]; 561 } 562 } 563 564 setDomainList(); 565 setAxisList(); 566 setScalarList(); 567 } 568 CATCH_DUMP_ATTR 569 570 571 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 572 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 573 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 574 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 575 81 576 82 577 … … 1169 1664 //---------------------------------------------------------------- 1170 1665 1171 CGrid* CGrid::createGrid(CDomain* domain) 1172 TRY 1173 { 1174 std::vector<CDomain*> vecDom(1, domain); 1175 std::vector<CAxis*> vecAxis; 1176 1177 return createGrid(vecDom, vecAxis); 1178 } 1179 CATCH 1180 1181 CGrid* CGrid::createGrid(CDomain* domain, CAxis* axis) 1182 TRY 1183 { 1184 std::vector<CDomain*> vecDom(1, domain); 1185 std::vector<CAxis*> vecAxis(1, axis); 1186 1187 return createGrid(vecDom, vecAxis); 1188 } 1189 CATCH 1190 1191 CGrid* CGrid::createGrid(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis, 1192 const CArray<int,1>& axisDomainOrder) 1193 TRY 1194 { 1195 std::vector<CScalar*> vecScalar; 1196 return createGrid(generateId(domains, axis, vecScalar, axisDomainOrder), domains, axis, vecScalar, axisDomainOrder); 1197 } 1198 CATCH 1199 1200 CGrid* CGrid::createGrid(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis, 1201 const std::vector<CScalar*>& scalars, const CArray<int,1>& axisDomainOrder) 1202 TRY 1203 { 1204 return createGrid(generateId(domains, axis, scalars, axisDomainOrder), domains, axis, scalars, axisDomainOrder); 1205 } 1206 CATCH 1207 1208 CGrid* CGrid::createGrid(StdString id, const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis, 1209 const std::vector<CScalar*>& scalars, const CArray<int,1>& axisDomainOrder) 1210 TRY 1211 { 1212 if (axisDomainOrder.numElements() > 0 && axisDomainOrder.numElements() != (domains.size() + axis.size() + scalars.size())) 1213 ERROR("CGrid* CGrid::createGrid(...)", 1214 << "The size of axisDomainOrder (" << axisDomainOrder.numElements() 1215 << ") is not coherent with the number of elements (" << domains.size() + axis.size() <<")."); 1216 1217 CGrid* grid = CGridGroup::get("grid_definition")->createChild(id); 1218 grid->setDomainList(domains); 1219 grid->setAxisList(axis); 1220 grid->setScalarList(scalars); 1221 1222 // By default, domains are always the first elements of a grid 1223 if (0 == axisDomainOrder.numElements()) 1224 { 1225 int size = domains.size() + axis.size() + scalars.size(); 1226 int nb = 0; 1227 grid->axis_domain_order.resize(size); 1228 for (int i = 0; i < size; ++i) 1229 { 1230 if (i < domains.size()) { 1231 grid->axis_domain_order(i) = 2; 1232 1233 } 1234 else if ((scalars.size() < (size-nb)) < size) { 1235 grid->axis_domain_order(i) = 1; 1236 } 1237 else 1238 grid->axis_domain_order(i) = 0; 1239 ++nb; 1240 } 1241 } 1242 else 1243 { 1244 grid->axis_domain_order.resize(axisDomainOrder.numElements()); 1245 grid->axis_domain_order = axisDomainOrder; 1246 } 1247 1248 // grid->solveElementsRefInheritance(true); 1249 1250 return grid; 1251 } 1252 CATCH 1666 1253 1667 1254 1668 CGrid* CGrid::cloneGrid(const StdString& idNewGrid, CGrid* gridSrc) … … 1353 1767 CATCH 1354 1768 1355 //----------------------------------------------------------------1356 1357 CDomainGroup* CGrid::getVirtualDomainGroup() const1358 TRY1359 {1360 return this->vDomainGroup_;1361 }1362 CATCH1363 1364 CAxisGroup* CGrid::getVirtualAxisGroup() const1365 TRY1366 {1367 return this->vAxisGroup_;1368 }1369 CATCH1370 1371 CScalarGroup* CGrid::getVirtualScalarGroup() const1372 TRY1373 {1374 return this->vScalarGroup_;1375 }1376 CATCH1377 1769 1378 1770 //---------------------------------------------------------------- … … 2086 2478 TRY 2087 2479 { 2088 return (0 != get WrittenDataSize());2480 return (0 != getGridLocalElements()->getView(CElementView::FULL)->getSize()); 2089 2481 } 2090 2482 CATCH_DUMP_ATTR … … 2099 2491 TRY 2100 2492 { 2101 return get ServerDistribution()->getGridSize();2493 return getGridLocalElements()->getView(CElementView::FULL)->getSize() ; 2102 2494 } 2103 2495 CATCH … … 2205 2597 CATCH 2206 2598 2207 ///--------------------------------------------------------------- 2208 2209 CDomain* CGrid::addDomain(const std::string& id) 2210 TRY 2211 { 2212 order_.push_back(2); 2213 axis_domain_order.resize(order_.size()); 2214 for (int idx = 0; idx < order_.size(); ++idx) axis_domain_order(idx)=order_[idx]; 2215 return vDomainGroup_->createChild(id); 2216 } 2217 CATCH_DUMP_ATTR 2218 2219 CAxis* CGrid::addAxis(const std::string& id) 2220 TRY 2221 { 2222 order_.push_back(1); 2223 axis_domain_order.resize(order_.size()); 2224 for (int idx = 0; idx < order_.size(); ++idx) axis_domain_order(idx)=order_[idx]; 2225 return vAxisGroup_->createChild(id); 2226 } 2227 CATCH_DUMP_ATTR 2228 2229 CScalar* CGrid::addScalar(const std::string& id) 2230 TRY 2231 { 2232 order_.push_back(0); 2233 axis_domain_order.resize(order_.size()); 2234 for (int idx = 0; idx < order_.size(); ++idx) axis_domain_order(idx)=order_[idx]; 2235 return vScalarGroup_->createChild(id); 2236 } 2237 CATCH_DUMP_ATTR 2238 2239 //! Change virtual field group to a new one 2240 void CGrid::setVirtualDomainGroup(CDomainGroup* newVDomainGroup) 2241 TRY 2242 { 2243 this->vDomainGroup_ = newVDomainGroup; 2244 } 2245 CATCH_DUMP_ATTR 2246 2247 //! Change virtual variable group to new one 2248 void CGrid::setVirtualAxisGroup(CAxisGroup* newVAxisGroup) 2249 TRY 2250 { 2251 this->vAxisGroup_ = newVAxisGroup; 2252 } 2253 CATCH_DUMP_ATTR 2254 2255 //! Change virtual variable group to new one 2256 void CGrid::setVirtualScalarGroup(CScalarGroup* newVScalarGroup) 2257 TRY 2258 { 2259 this->vScalarGroup_ = newVScalarGroup; 2260 } 2261 CATCH_DUMP_ATTR 2262 2599 2263 2600 2264 2601 void CGrid::sendGridToFileServer(CContextClient* client) … … 2271 2608 gridPtr->sendCreateChild(this->getId(),client); 2272 2609 this->sendAllAttributesToServer(client); 2273 if (isScalarGrid()) sendIndexScalarGrid(client); 2274 else sendIndex(client); 2275 this->sendAllDomains(client); 2276 this->sendAllAxis(client); 2277 this->sendAllScalars(client); 2278 } 2610 //if (isScalarGrid()) sendIndexScalarGrid(client); 2611 //else sendIndex(client); 2612 //this->sendAllDomains(client); 2613 //this->sendAllAxis(client); 2614 //this->sendAllScalars(client); 2615 2616 distributeGridToFileServer(client) ; 2617 } 2618 2619 2620 void CGrid::distributeGridToFileServer(CContextClient* client) 2621 { 2622 CContext* context = CContext::getCurrent(); 2623 // simple Distribution for now 2624 // distribute over the fisrt element except if it is a scalar 2625 auto& elements = getElements() ; 2626 int posDistributed = 0 ; 2627 for(auto& element : elements) 2628 { 2629 if (element.type==TYPE_DOMAIN) break ; 2630 else if (element.type==TYPE_AXIS) break ; 2631 else if (element.type==TYPE_SCALAR) posDistributed++ ; 2632 } 2633 2634 vector<CLocalView*> localViews ; 2635 vector<CDistributedView*> remoteViews ; 2636 2637 for(int i=0 ; i<elements.size() ; i++) 2638 { 2639 if (elements[i].type==TYPE_DOMAIN) 2640 { 2641 CDomain* domain = (CDomain*) elements[i].ptr ; 2642 domain->computeRemoteElement(client, posDistributed==i ? EDistributionType::BANDS : EDistributionType::NONE) ; 2643 remoteViews.push_back(domain->getRemoteElement(client)->getView(CElementView::FULL)) ; 2644 localViews.push_back(domain->getLocalView(CElementView::FULL)) ; 2645 } 2646 else if (elements[i].type==TYPE_AXIS) 2647 { 2648 CAxis* axis = (CAxis*) elements[i].ptr ; 2649 axis->computeRemoteElement(client, posDistributed==i ? EDistributionType::BANDS : EDistributionType::NONE) ; 2650 remoteViews.push_back(axis->getRemoteElement(client)->getView(CElementView::FULL)) ; 2651 localViews.push_back(axis->getLocalView(CElementView::FULL)) ; 2652 } 2653 else if (elements[i].type==TYPE_SCALAR) 2654 { 2655 CScalar* scalar = (CScalar*) elements[i].ptr ; 2656 scalar->computeRemoteElement(client, posDistributed==i ? EDistributionType::BANDS : EDistributionType::NONE) ; 2657 remoteViews.push_back(scalar->getRemoteElement(client)->getView(CElementView::FULL)) ; 2658 localViews.push_back(scalar->getLocalView(CElementView::FULL)) ; 2659 } 2660 } 2661 CGridRemoteConnector gridRemoteConnector(localViews, remoteViews, context->getIntraComm()) ; 2662 gridRemoteConnector.computeConnector() ; 2663 2664 vector<CScattererConnector*> clientToServerConnectors ; 2665 for(int i=0 ; i<elements.size() ; i++) 2666 { 2667 if (elements[i].type==TYPE_DOMAIN) 2668 { 2669 CDomain* domain = (CDomain*) elements[i].ptr ; 2670 sendAddDomain(domain->getId(),client) ; 2671 domain->distributeToServer(client, gridRemoteConnector.getDistributedGlobalIndex(i)) ; 2672 clientToServerConnectors.push_back(domain->getClientToServerConnector(client)) ; 2673 } 2674 else if (elements[i].type==TYPE_AXIS) 2675 { 2676 CAxis* axis = (CAxis*) elements[i].ptr ; 2677 sendAddAxis(axis->getId(),client) ; 2678 axis->distributeToServer(client, gridRemoteConnector.getDistributedGlobalIndex(i)) ; 2679 clientToServerConnectors.push_back(axis->getClientToServerConnector(client)) ; 2680 } 2681 else if (elements[i].type==TYPE_SCALAR) 2682 { 2683 CScalar* scalar = (CScalar*) elements[i].ptr ; 2684 sendAddScalar(scalar->getId(),client) ; 2685 scalar->distributeToServer(client, gridRemoteConnector.getDistributedGlobalIndex(i)) ; 2686 clientToServerConnectors.push_back(scalar->getClientToServerConnector(client)) ; 2687 } 2688 } 2689 2690 // compute the grid clientToServerConnector to send flux from client to servers 2691 clientToServerConnector_[client] = new CGridScattererConnector(clientToServerConnectors) ; 2692 2693 } 2694 2279 2695 2280 2696 void CGrid::sendGridToCouplerOut(CContextClient* client, const string& fieldId) … … 2282 2698 if (sendGridToCouplerOut_done_.count(client)!=0) return ; 2283 2699 else sendGridToCouplerOut_done_.insert(client) ; 2284 string gridId="_grid_of_"+fieldId ; 2285 this->sendAllAttributesToServer(client, gridId); 2700 2701 CContext* context = CContext::getCurrent(); 2702 // simple Distribution for now 2703 // distribute over the fisrt element except if it is a scalar 2704 auto& elements = getElements() ; 2705 int posDistributed = 0 ; 2706 for(auto& element : elements) 2707 { 2708 if (element.type==TYPE_DOMAIN) break ; 2709 else if (element.type==TYPE_AXIS) break ; 2710 else if (element.type==TYPE_SCALAR) posDistributed++ ; 2711 } 2286 2712 2287 if (isScalarGrid()) sendIndexScalarGrid(client, gridId); 2288 else sendIndex(client, gridId); 2289 2290 const auto& domVect = getDomains() ; 2291 for (int pos=0; pos<domVect.size();pos++) domVect[pos]->sendDomainToCouplerOut(client, fieldId, pos); 2292 2293 const auto& axisVect=getAxis() ; 2294 for (int pos=0; pos<axisVect.size();pos++) axisVect[pos]->sendAxisToCouplerOut(client, getGlobalDimension(), getAxisPositionInGrid()[pos], fieldId, pos); 2295 2296 const auto& scalVect=getScalars() ; 2297 for (int pos=0; pos<scalVect.size();pos++) scalVect[pos]->sendScalarToCouplerOut(client, fieldId, pos); 2713 vector<CLocalView*> localViews ; 2714 vector<CDistributedView*> remoteViews ; 2715 2716 for(int i=0 ; i<elements.size() ; i++) 2717 { 2718 if (elements[i].type==TYPE_DOMAIN) 2719 { 2720 CDomain* domain = (CDomain*) elements[i].ptr ; 2721 domain->computeRemoteElement(client, posDistributed==i ? EDistributionType::BANDS : EDistributionType::NONE) ; 2722 remoteViews.push_back(domain->getRemoteElement(client)->getView(CElementView::FULL)) ; 2723 localViews.push_back(domain->getLocalView(CElementView::FULL)) ; 2724 } 2725 else if (elements[i].type==TYPE_AXIS) 2726 { 2727 CAxis* axis = (CAxis*) elements[i].ptr ; 2728 axis->computeRemoteElement(client, posDistributed==i ? EDistributionType::BANDS : EDistributionType::NONE) ; 2729 remoteViews.push_back(axis->getRemoteElement(client)->getView(CElementView::FULL)) ; 2730 localViews.push_back(axis->getLocalView(CElementView::FULL)) ; 2731 } 2732 else if (elements[i].type==TYPE_SCALAR) 2733 { 2734 CScalar* scalar = (CScalar*) elements[i].ptr ; 2735 scalar->computeRemoteElement(client, posDistributed==i ? EDistributionType::BANDS : EDistributionType::NONE) ; 2736 remoteViews.push_back(scalar->getRemoteElement(client)->getView(CElementView::FULL)) ; 2737 localViews.push_back(scalar->getLocalView(CElementView::FULL)) ; 2738 } 2739 } 2740 CGridRemoteConnector gridRemoteConnector(localViews, remoteViews, context->getIntraComm()) ; 2741 gridRemoteConnector.computeConnector() ; 2742 2743 vector<CScattererConnector*> clientToClientConnectors ; 2744 for(int i=0 ; i<elements.size() ; i++) 2745 { 2746 if (elements[i].type==TYPE_DOMAIN) 2747 { 2748 CDomain* domain = (CDomain*) elements[i].ptr ; 2749 sendAddDomain(domain->getId(),client) ; 2750 domain->distributeToServer(client, gridRemoteConnector.getDistributedGlobalIndex(i)) ; 2751 clientToClientConnectors.push_back(domain->getClientToServerConnector(client)) ; 2752 } 2753 else if (elements[i].type==TYPE_AXIS) 2754 { 2755 CAxis* axis = (CAxis*) elements[i].ptr ; 2756 sendAddAxis(axis->getId(),client) ; 2757 axis->distributeToServer(client, gridRemoteConnector.getDistributedGlobalIndex(i)) ; 2758 clientToClientConnectors.push_back(axis->getClientToServerConnector(client)) ; 2759 } 2760 else if (elements[i].type==TYPE_SCALAR) 2761 { 2762 CScalar* scalar = (CScalar*) elements[i].ptr ; 2763 sendAddScalar(scalar->getId(),client) ; 2764 scalar->distributeToServer(client, gridRemoteConnector.getDistributedGlobalIndex(i)) ; 2765 clientToClientConnectors.push_back(scalar->getClientToServerConnector(client)) ; 2766 } 2767 } 2768 2769 // compute the grid clientToServerConnector to send flux from client to servers 2770 clientToClientConnector_[client] = new CGridScattererConnector(clientToClientConnectors) ; 2298 2771 } 2299 2772 … … 2710 3183 CATCH_DUMP_ATTR 2711 3184 2712 /*! 2713 \brief Get the list of domain pointers 2714 \return list of domain pointers 2715 */ 2716 std::vector<CDomain*> CGrid::getDomains() 2717 TRY 2718 { 2719 std::vector<CDomain*> domList; 2720 if (!domList_.empty()) 2721 { 2722 for (int i = 0; i < domList_.size(); ++i) domList.push_back(CDomain::get(domList_[i])); 2723 } 2724 return domList; 2725 } 2726 CATCH_DUMP_ATTR 2727 2728 /*! 2729 \brief Get the list of axis pointers 2730 \return list of axis pointers 2731 */ 2732 std::vector<CAxis*> CGrid::getAxis() 2733 TRY 2734 { 2735 std::vector<CAxis*> aList; 2736 if (!axisList_.empty()) 2737 for (int i =0; i < axisList_.size(); ++i) aList.push_back(CAxis::get(axisList_[i])); 2738 2739 return aList; 2740 } 2741 CATCH_DUMP_ATTR 2742 2743 /*! 2744 \brief Get the list of axis pointers 2745 \return list of axis pointers 2746 */ 2747 std::vector<CScalar*> CGrid::getScalars() 2748 TRY 2749 { 2750 std::vector<CScalar*> sList; 2751 if (!scalarList_.empty()) 2752 for (int i =0; i < scalarList_.size(); ++i) sList.push_back(CScalar::get(scalarList_[i])); 2753 2754 return sList; 2755 } 2756 CATCH_DUMP_ATTR 2757 2758 /*! 2759 \brief Get domain pointer with index 2760 \return domain pointer 2761 */ 2762 CDomain* CGrid::getDomain(int domainIndex) 2763 TRY 2764 { 2765 std::vector<CDomain*> domainListP = this->getDomains(); 2766 if (domainListP.empty()) 2767 { 2768 ERROR("CGrid::getDomain(int domainIndex)", 2769 << "No domain associated to this grid. " << std::endl 2770 << "Grid id = " << this->getId()); 2771 } 2772 2773 if (domainIndex >= domainListP.size() || (domainIndex < 0)) 2774 ERROR("CGrid::getDomain(int domainIndex)", 2775 << "Domain with the index doesn't exist " << std::endl 2776 << "Grid id = " << this->getId() << std::endl 2777 << "Grid has only " << domainListP.size() << " domain but domain index required is " << domainIndex << std::endl); 2778 2779 return domainListP[domainIndex]; 2780 } 2781 CATCH_DUMP_ATTR 2782 2783 /*! 2784 \brief Get the axis pointer with index 2785 \return axis pointer 2786 */ 2787 CAxis* CGrid::getAxis(int axisIndex) 2788 TRY 2789 { 2790 std::vector<CAxis*> axisListP = this->getAxis(); 2791 if (axisListP.empty()) 2792 { 2793 ERROR("CGrid::getDomain(int axisIndex)", 2794 << "No axis associated to this grid. " << std::endl 2795 << "Grid id = " << this->getId()); 2796 } 2797 2798 if (axisIndex >= axisListP.size() || (axisIndex < 0)) 2799 ERROR("CGrid::getDomain(int axisIndex)", 2800 << "Domain with the index doesn't exist " << std::endl 2801 << "Grid id = " << this->getId() << std::endl 2802 << "Grid has only " << axisListP.size() << " axis but axis index required is " << axisIndex << std::endl); 2803 2804 return axisListP[axisIndex]; 2805 } 2806 CATCH_DUMP_ATTR 2807 2808 /*! 2809 \brief Get the a scalar pointer 2810 \return scalar pointer 2811 */ 2812 CScalar* CGrid::getScalar(int scalarIndex) 2813 TRY 2814 { 2815 std::vector<CScalar*> scalarListP = this->getScalars(); 2816 if (scalarListP.empty()) 2817 { 2818 ERROR("CGrid::getScalar(int scalarIndex)", 2819 << "No scalar associated to this grid. " << std::endl 2820 << "Grid id = " << this->getId()); 2821 } 2822 2823 if (scalarIndex >= scalarListP.size() || (scalarIndex < 0)) 2824 ERROR("CGrid::getScalar(int scalarIndex)", 2825 << "Scalar with the index doesn't exist " << std::endl 2826 << "Grid id = " << this->getId() << std::endl 2827 << "Grid has only " << scalarListP.size() << " scalar but scalar index required is " << scalarIndex << std::endl); 2828 2829 return scalarListP[scalarIndex]; 2830 } 2831 CATCH_DUMP_ATTR 2832 2833 /*! 2834 \brief Set domain(s) of a grid from a list 2835 \param[in] domains list of domains 2836 */ 2837 void CGrid::setDomainList(const std::vector<CDomain*> domains) 2838 TRY 2839 { 2840 if (isDomListSet) return; 2841 std::vector<CDomain*> domList = this->getVirtualDomainGroup()->getAllChildren(); 2842 if (!domains.empty() && domList.empty()) 2843 { 2844 for (int i = 0; i < domains.size(); ++i) 2845 this->getVirtualDomainGroup()->addChild(domains[i]); 2846 domList = this->getVirtualDomainGroup()->getAllChildren(); 2847 } 2848 2849 if (!domList.empty()) 2850 { 2851 int sizeDom = domList.size(); 2852 domList_.resize(sizeDom); 2853 for (int i = 0; i < sizeDom; ++i) 2854 { 2855 domList_[i] = domList[i]->getId(); 2856 } 2857 isDomListSet = true; 2858 } 2859 } 2860 CATCH_DUMP_ATTR 2861 2862 /*! 2863 \brief Set axis(s) of a grid from a list 2864 \param[in] axis list of axis 2865 */ 2866 void CGrid::setAxisList(const std::vector<CAxis*> axis) 2867 TRY 2868 { 2869 if (isAxisListSet) return; 2870 std::vector<CAxis*> aList = this->getVirtualAxisGroup()->getAllChildren(); 2871 if (!axis.empty() && aList.empty()) 2872 { 2873 for (int i = 0; i < axis.size(); ++i) 2874 this->getVirtualAxisGroup()->addChild(axis[i]); 2875 aList = this->getVirtualAxisGroup()->getAllChildren(); 2876 } 2877 2878 if (!aList.empty()) 2879 { 2880 int sizeAxis = aList.size(); 2881 axisList_.resize(sizeAxis); 2882 for (int i = 0; i < sizeAxis; ++i) 2883 { 2884 axisList_[i] = aList[i]->getId(); 2885 } 2886 isAxisListSet = true; 2887 } 2888 } 2889 CATCH_DUMP_ATTR 2890 2891 /*! 2892 \brief Set scalar(s) of a grid from a list 2893 \param[in] scalars list of scalars 2894 */ 2895 void CGrid::setScalarList(const std::vector<CScalar*> scalars) 2896 TRY 2897 { 2898 if (isScalarListSet) return; 2899 std::vector<CScalar*> sList = this->getVirtualScalarGroup()->getAllChildren(); 2900 if (!scalars.empty() && sList.empty()) 2901 { 2902 for (int i = 0; i < scalars.size(); ++i) 2903 this->getVirtualScalarGroup()->addChild(scalars[i]); 2904 sList = this->getVirtualScalarGroup()->getAllChildren(); 2905 } 2906 2907 if (!sList.empty()) 2908 { 2909 int sizeScalar = sList.size(); 2910 scalarList_.resize(sizeScalar); 2911 for (int i = 0; i < sizeScalar; ++i) 2912 { 2913 scalarList_[i] = sList[i]->getId(); 2914 } 2915 isScalarListSet = true; 2916 } 2917 } 2918 CATCH_DUMP_ATTR 2919 2920 /*! 2921 \brief Get list of id of domains 2922 \return id list of domains 2923 */ 2924 std::vector<StdString> CGrid::getDomainList() 2925 TRY 2926 { 2927 setDomainList(); 2928 return domList_; 2929 } 2930 CATCH 2931 2932 /*! 2933 \brief Get list of id of axis 2934 \return id list of axis 2935 */ 2936 std::vector<StdString> CGrid::getAxisList() 2937 TRY 2938 { 2939 setAxisList(); 2940 return axisList_; 2941 } 2942 CATCH 2943 2944 /*! 2945 \brief Get list of id of scalar 2946 \return id list of scalar 2947 */ 2948 std::vector<StdString> CGrid::getScalarList() 2949 TRY 2950 { 2951 setScalarList(); 2952 return scalarList_; 2953 } 2954 CATCH 3185 2955 3186 2956 3187 /*! … … 3014 3245 CATCH_DUMP_ATTR 3015 3246 3016 /*! 3017 Parse a grid, for now, it contains only domain, axis and scalar 3018 */ 3019 void CGrid::parse(xml::CXMLNode& node) 3020 TRY 3021 { 3022 SuperClass::parse(node); 3023 3024 if (node.goToChildElement()) 3025 { 3026 StdString domainName("domain"); 3027 StdString axisName("axis"); 3028 StdString scalarName("scalar"); 3029 do 3030 { 3031 if (node.getElementName() == domainName) { 3032 order_.push_back(2); 3033 this->getVirtualDomainGroup()->parseChild(node); 3034 } 3035 if (node.getElementName() == axisName) { 3036 order_.push_back(1); 3037 this->getVirtualAxisGroup()->parseChild(node); 3038 } 3039 if (node.getElementName() == scalarName) { 3040 order_.push_back(0); 3041 this->getVirtualScalarGroup()->parseChild(node); 3042 } 3043 } while (node.goToNextElement()); 3044 node.goToParentElement(); 3045 } 3046 3047 if (!order_.empty()) 3048 { 3049 int sizeOrd = order_.size(); 3050 axis_domain_order.resize(sizeOrd); 3051 for (int i = 0; i < sizeOrd; ++i) 3052 { 3053 axis_domain_order(i) = order_[i]; 3054 } 3055 } 3056 3057 setDomainList(); 3058 setAxisList(); 3059 setScalarList(); 3060 } 3061 CATCH_DUMP_ATTR 3062 3063 3247 3064 3248 void CGrid::computeGridLocalElements() 3065 3249 { … … 3097 3281 modelToWorkflowConnector_ = getGridLocalElements()->getConnector(CElementView::MODEL,CElementView::WORKFLOW) ; 3098 3282 } 3283 3284 void CGrid::computeWorkflowToFullConnector(void) 3285 { 3286 workflowToFullConnector_ = getGridLocalElements()->getConnector(CElementView::WORKFLOW,CElementView::FULL) ; 3287 } 3288 3289 void CGrid::computeWorkflowToModelConnector(void) 3290 { 3291 workflowToModelConnector_ = getGridLocalElements()->getConnector(CElementView::WORKFLOW,CElementView::MODEL) ; 3292 } 3293 3294 void CGrid::computeFullToWorkflowConnector(void) 3295 { 3296 fullToWorkflowConnector_ = getGridLocalElements()->getConnector(CElementView::FULL,CElementView::WORKFLOW) ; 3297 } 3298 3299 void CGrid::computeServerFromClientConnector(void) 3300 { 3301 vector<CGathererConnector*> connectors ; 3302 for(auto& element : getElements()) 3303 { 3304 if (element.type==TYPE_DOMAIN) connectors.push_back(element.domain->getServerFromClientConnector()) ; 3305 else if (element.type==TYPE_AXIS) connectors.push_back(element.axis->getServerFromClientConnector()) ; 3306 else if (element.type==TYPE_SCALAR) connectors.push_back(element.scalar->getServerFromClientConnector()) ; 3307 } 3308 serverFromClientConnector_ = new CGridGathererConnector(connectors) ; 3309 } 3310 3311 void CGrid::computeClientFromClientConnector(void) 3312 { 3313 vector<CGathererConnector*> connectors ; 3314 for(auto& element : getElements()) 3315 { 3316 if (element.type==TYPE_DOMAIN) connectors.push_back(element.domain->getServerFromClientConnector()) ; 3317 else if (element.type==TYPE_AXIS) connectors.push_back(element.axis->getServerFromClientConnector()) ; 3318 else if (element.type==TYPE_SCALAR) connectors.push_back(element.scalar->getServerFromClientConnector()) ; 3319 } 3320 clientFromClientConnector_ = new CGridGathererConnector(connectors) ; 3321 } 3099 3322 } // namespace xios -
XIOS/dev/dev_ym/XIOS_COUPLING/src/node/grid.hpp
r1918 r1930 18 18 #include "grid_local_connector.hpp" 19 19 #include "grid_elements.hpp" 20 #include "grid_scatterer_connector.hpp" 21 #include "grid_gatherer_connector.hpp" 22 20 23 21 24 namespace xios { … … 52 55 typedef CGridAttributes SuperClassAttribute; 53 56 57 private: 58 59 // define a structure to store elements (CDomain, CAxis, CScalar) using a void* and a type to cast the pointer 60 enum EElementType { TYPE_SCALAR, TYPE_AXIS, TYPE_DOMAIN } ; 61 struct SElement {void* ptr ; EElementType type ; CScalar* scalar ; CAxis* axis ; CDomain* domain ; } ; 62 vector<SElement> elements_ ; 63 bool elementsComputed_ = false ; 64 /** retrieve the vector of elements as a structure containing a void* and the type of pointer */ 65 vector<SElement>& getElements(void) { if (!elementsComputed_) computeElements() ; return elements_ ; } 66 void computeElements(void) ; 67 /** List order of axis and domain in a grid, if there is a domain, it will take value 2, axis 1, scalar 0 */ 68 std::vector<int> order_; 69 54 70 public: 55 71 … … 72 88 73 89 void checkEligibilityForCompressedOutput(); 74 90 75 91 76 92 … … 504 520 std::map<int, CClientServerMapping::GlobalIndexMap> globalIndexOnServer_; 505 521 506 507 /** List order of axis and domain in a grid, if there is a domain, it will take value 2, axis 1, scalar 0 */ 508 std::vector<int> order_; 522 523 524 ////////////////////////////////////////////////////////////////////////////////////// 525 // this part is related to distribution, element definition, views and connectors // 526 ////////////////////////////////////////////////////////////////////////////////////// 527 509 528 510 529 private: … … 519 538 void computeModelToWorkflowConnector(void) ; 520 539 CGridLocalConnector* getModelToWorkflowConnector(void) { if (modelToWorkflowConnector_==nullptr) computeModelToWorkflowConnector() ; return modelToWorkflowConnector_;} 540 541 private: 542 CGridLocalConnector* workflowToModelConnector_ ; 543 public: 544 void computeWorkflowToModelConnector(void) ; 545 CGridLocalConnector* getWorkflowToModelConnector(void) { if (workflowToModelConnector_==nullptr) computeWorkflowToModelConnector() ; return workflowToModelConnector_;} 546 547 public: //? 548 void distributeGridToFileServer(CContextClient* client); 549 550 private: 551 map<CContextClient*, CGridScattererConnector*> clientToServerConnector_ ; 552 public: 553 CGridScattererConnector* getClientToServerConnector(CContextClient* client) { return clientToServerConnector_[client] ;} // make some test to see if connector exits for the given client 554 555 private: 556 CGridGathererConnector* serverFromClientConnector_ = nullptr ; 557 public: 558 CGridGathererConnector* getServerFromClientConnector(void) { if (serverFromClientConnector_==nullptr) computeServerFromClientConnector() ; return serverFromClientConnector_;} 559 void computeServerFromClientConnector(void) ; 560 561 private: 562 CGridLocalConnector* workflowToFullConnector_ = nullptr; 563 public: 564 void computeWorkflowToFullConnector(void) ; 565 CGridLocalConnector* getWorkflowToFullConnector(void) { if (workflowToFullConnector_==nullptr) computeWorkflowToFullConnector() ; return workflowToFullConnector_;} 566 567 private: 568 CGridLocalConnector* fullToWorkflowConnector_ = nullptr; 569 public: 570 void computeFullToWorkflowConnector(void) ; 571 CGridLocalConnector* getFullToWorkflowConnector(void) { if (fullToWorkflowConnector_==nullptr) computeFullToWorkflowConnector() ; return fullToWorkflowConnector_;} 572 573 private: 574 CGridGathererConnector* clientFromClientConnector_ = nullptr ; 575 public: 576 CGridGathererConnector* getClientFromClientConnector(void) { if (clientFromClientConnector_==nullptr) computeClientFromClientConnector() ; return clientFromClientConnector_;} 577 void computeClientFromClientConnector(void) ; 578 579 private: 580 map<CContextClient*, CGridScattererConnector*> clientToClientConnector_ ; 581 public: 582 CGridScattererConnector* getClientToClientConnector(CContextClient* client) { return clientToClientConnector_[client] ;} // make some test to see if connector exits for the given client 583 584 585 private: 586 CGridGathererConnector* clientFromServerConnector_ = nullptr ; 587 public: 588 CGridGathererConnector* getClientFromServerConnector(void) { if (clientFromServerConnector_==nullptr) computeClientFromServerConnector() ; return clientFromServerConnector_;} 589 void computeClientFromServerConnector(void) ; 521 590 522 591 }; // class CGrid -
XIOS/dev/dev_ym/XIOS_COUPLING/src/node/scalar.cpp
r1875 r1930 7 7 #include "xios_spl.hpp" 8 8 #include "type.hpp" 9 #include "context.hpp" 9 10 10 11 namespace xios { … … 231 232 } 232 233 234 ////////////////////////////////////////////////////////////////////////////////////// 235 // this part is related to distribution, element definition, views and connectors // 236 ////////////////////////////////////////////////////////////////////////////////////// 237 238 void CScalar::initializeLocalElement(void) 239 { 240 // after checkAttribute index of size n 241 int rank = CContext::getCurrent()->getIntraCommRank() ; 242 243 CArray<size_t,1> ind(1) ; 244 ind(0)=0 ; 245 246 localElement_ = new CLocalElement(rank, 1, ind) ; 247 } 248 249 void CScalar::addFullView(void) 250 { 251 CArray<int,1> index(1) ; 252 for(int i=0; i<1 ; i++) index(0)=0 ; 253 localElement_ -> addView(CElementView::FULL, index) ; 254 } 255 256 void CScalar::addWorkflowView(void) 257 { 258 CArray<int,1> index(1) ; 259 for(int i=0; i<1 ; i++) index(0)=0 ; 260 localElement_ -> addView(CElementView::WORKFLOW, index) ; 261 } 262 263 void CScalar::addModelView(void) 264 { 265 CArray<int,1> index(1) ; 266 for(int i=0; i<1 ; i++) index(0)=0 ; 267 localElement_->addView(CElementView::MODEL, index) ; 268 } 269 270 void CScalar::computeModelToWorkflowConnector(void) 271 { 272 CLocalView* srcView=getLocalView(CElementView::MODEL) ; 273 CLocalView* dstView=getLocalView(CElementView::WORKFLOW) ; 274 modelToWorkflowConnector_ = new CLocalConnector(srcView, dstView); 275 modelToWorkflowConnector_->computeConnector() ; 276 } 277 278 279 void CScalar::computeRemoteElement(CContextClient* client, EDistributionType type) 280 { 281 CContext* context = CContext::getCurrent(); 282 map<int, CArray<size_t,1>> globalIndex ; 283 284 int nbServer = client->serverSize; 285 size_t nglo=1 ; 286 CArray<size_t,1> indGlo ; 287 for(size_t i=0;i<nglo;i++) indGlo(i) = i ; 288 for (auto& rankServer : client->getRanksServerLeader()) globalIndex[rankServer] = indGlo ; 289 290 remoteElement_[client] = new CDistributedElement(nglo, globalIndex) ; 291 remoteElement_[client]->addFullView() ; 292 } 293 294 void CScalar::distributeToServer(CContextClient* client, std::map<int, CArray<size_t,1>>& globalIndex) 295 { 296 CContext* context = CContext::getCurrent(); 297 CDistributedElement scatteredElement(1,globalIndex) ; 298 clientToServerConnector_[client] = new CScattererConnector(localElement_->getView(CElementView::FULL), scatteredElement.getView(CElementView::FULL), context->getIntraComm()) ; 299 clientToServerConnector_[client] ->computeConnector() ; 300 } 301 302 233 303 // Definition of some macros 234 304 DEFINE_REF_FUNC(Scalar,scalar) -
XIOS/dev/dev_ym/XIOS_COUPLING/src/node/scalar.hpp
r1875 r1930 13 13 #include "transformation.hpp" 14 14 #include "transformation_enum.hpp" 15 16 #include "element.hpp" 17 #include "local_connector.hpp" 18 #include "scatterer_connector.hpp" 19 #include "gatherer_connector.hpp" 20 #include "distribution_type.hpp" 21 15 22 16 23 namespace xios … … 133 140 void unsetCompleted(void) { isCompleted_=false ; } 134 141 142 143 144 ////////////////////////////////////////////////////////////////////////////////////// 145 // this part is related to distribution, element definition, views and connectors // 146 ////////////////////////////////////////////////////////////////////////////////////// 147 private: 148 CLocalElement* localElement_ = nullptr ; 149 void initializeLocalElement(void) ; 150 151 public: 152 CLocalElement* getLocalElement(void) { if (localElement_==nullptr) initializeLocalElement() ; return localElement_ ; } 153 CLocalView* getLocalView(CElementView::type type) { return getLocalElement()->getView(type) ;} 154 155 private: 156 void addFullView(void) ; 157 void addWorkflowView(void) ; 158 void addModelView(void) ; 159 160 private: 161 CLocalConnector* modelToWorkflowConnector_ ; 162 void computeModelToWorkflowConnector(void) ; 163 public: 164 CLocalConnector* getModelToWorkflowConnector(void) { if (modelToWorkflowConnector_==nullptr) computeModelToWorkflowConnector() ; return modelToWorkflowConnector_ ;} 165 166 public: 167 void computeRemoteElement(CContextClient* client, EDistributionType) ; 168 void distributeToServer(CContextClient* client, std::map<int, CArray<size_t,1>>& globalIndex) ; 169 private: 170 map<CContextClient*, CDistributedElement*> remoteElement_ ; 171 public: 172 CDistributedElement* getRemoteElement(CContextClient* client) {return remoteElement_[client] ;} 173 private: 174 map<CContextClient*, CScattererConnector*> clientToServerConnector_ ; 175 public: 176 CScattererConnector* getClientToServerConnector(CContextClient* client) { return clientToServerConnector_[client] ;} 177 178 private: 179 CGathererConnector* gathererConnector_ ; 180 CGathererConnector* serverFromClientConnector_ ; 181 public: 182 CGathererConnector* getServerFromClientConnector(void) { return serverFromClientConnector_ ;} 183 184 185 186 187 135 188 private: 136 189 DECLARE_REF_FUNC(Scalar,scalar)
Note: See TracChangeset
for help on using the changeset viewer.