[591] | 1 | #ifndef __XIOS_CAxis__ |
---|
| 2 | #define __XIOS_CAxis__ |
---|
[219] | 3 | |
---|
[591] | 4 | /// XIOS headers /// |
---|
| 5 | #include "xios_spl.hpp" |
---|
[219] | 6 | #include "group_factory.hpp" |
---|
[619] | 7 | #include "virtual_node.hpp" |
---|
[219] | 8 | |
---|
| 9 | #include "declare_group.hpp" |
---|
[540] | 10 | #include "declare_ref_func.hpp" |
---|
[619] | 11 | #include "declare_virtual_node.hpp" |
---|
[369] | 12 | #include "attribute_array.hpp" |
---|
[399] | 13 | #include "attribute_enum.hpp" |
---|
| 14 | #include "attribute_enum_impl.hpp" |
---|
[567] | 15 | #include "server_distribution_description.hpp" |
---|
[619] | 16 | #include "transformation.hpp" |
---|
| 17 | #include "transformation_enum.hpp" |
---|
[1918] | 18 | #include "element.hpp" |
---|
| 19 | #include "local_connector.hpp" |
---|
[1930] | 20 | #include "scatterer_connector.hpp" |
---|
| 21 | #include "gatherer_connector.hpp" |
---|
| 22 | #include "distribution_type.hpp" |
---|
[219] | 23 | |
---|
[1930] | 24 | |
---|
[335] | 25 | namespace xios { |
---|
[219] | 26 | /// ////////////////////// Déclarations ////////////////////// /// |
---|
| 27 | |
---|
| 28 | class CAxisGroup; |
---|
| 29 | class CAxisAttributes; |
---|
| 30 | class CAxis; |
---|
| 31 | |
---|
| 32 | ///-------------------------------------------------------------- |
---|
| 33 | |
---|
| 34 | // Declare/Define CAxisAttribute |
---|
| 35 | BEGIN_DECLARE_ATTRIBUTE_MAP(CAxis) |
---|
[231] | 36 | # include "axis_attribute.conf" |
---|
[219] | 37 | END_DECLARE_ATTRIBUTE_MAP(CAxis) |
---|
| 38 | |
---|
| 39 | ///-------------------------------------------------------------- |
---|
| 40 | |
---|
| 41 | class CAxis |
---|
| 42 | : public CObjectTemplate<CAxis> |
---|
| 43 | , public CAxisAttributes |
---|
| 44 | { |
---|
[987] | 45 | /// typedef /// |
---|
| 46 | typedef CObjectTemplate<CAxis> SuperClass; |
---|
| 47 | typedef CAxisAttributes SuperClassAttribute; |
---|
| 48 | |
---|
[1235] | 49 | public: |
---|
[567] | 50 | enum EEventId |
---|
| 51 | { |
---|
[1144] | 52 | EVENT_ID_DISTRIBUTION_ATTRIBUTE, |
---|
[633] | 53 | EVENT_ID_DISTRIBUTED_VALUE, |
---|
[1025] | 54 | EVENT_ID_NON_DISTRIBUTED_VALUE, |
---|
| 55 | EVENT_ID_NON_DISTRIBUTED_ATTRIBUTES, |
---|
[1930] | 56 | EVENT_ID_DISTRIBUTED_ATTRIBUTES, |
---|
| 57 | EVENT_ID_AXIS_DISTRIBUTION, |
---|
| 58 | EVENT_ID_SEND_DISTRIBUTED_ATTRIBUTE |
---|
[567] | 59 | } ; |
---|
| 60 | |
---|
[1235] | 61 | public: |
---|
[219] | 62 | typedef CAxisAttributes RelAttributes; |
---|
| 63 | typedef CAxisGroup RelGroup; |
---|
[621] | 64 | typedef CTransformation<CAxis>::TransformationMapTypes TransMapTypes; |
---|
[219] | 65 | |
---|
[621] | 66 | public: |
---|
[219] | 67 | /// Constructeurs /// |
---|
| 68 | CAxis(void); |
---|
| 69 | explicit CAxis(const StdString & id); |
---|
| 70 | CAxis(const CAxis & axis); // Not implemented yet. |
---|
| 71 | CAxis(const CAxis * const axis); // Not implemented yet. |
---|
| 72 | |
---|
[622] | 73 | static CAxis* createAxis(); |
---|
[1158] | 74 | |
---|
| 75 | /// Accesseurs /// |
---|
| 76 | const std::set<StdString> & getRelFiles(void) const; |
---|
| 77 | |
---|
[1639] | 78 | int getNumberWrittenIndexes(MPI_Comm writtenCom); |
---|
| 79 | int getTotalNumberWrittenIndexes(MPI_Comm writtenCom); |
---|
| 80 | int getOffsetWrittenIndexes(MPI_Comm writtenCom); |
---|
| 81 | CArray<int, 1>& getCompressedIndexToWriteOnServer(MPI_Comm writtenCom); |
---|
[676] | 82 | |
---|
[1371] | 83 | std::map<int, StdSize> getAttributesBufferSize(CContextClient* client, const std::vector<int>& globalDim, int orderPositionInGrid, |
---|
| 84 | CServerDistributionDescription::ServerDistributionType disType = CServerDistributionDescription::BAND_DISTRIBUTION); |
---|
[731] | 85 | |
---|
[219] | 86 | /// Test /// |
---|
| 87 | bool IsWritten(const StdString & filename) const; |
---|
[676] | 88 | bool isWrittenCompressed(const StdString& filename) const; |
---|
[594] | 89 | bool isDistributed(void) const; |
---|
[1956] | 90 | |
---|
| 91 | public: |
---|
| 92 | /*! |
---|
| 93 | \brief return if the axis can be written or not in a compressed way. |
---|
| 94 | ie if there are some masked or indexed point on the domain. Valid only on server side. |
---|
| 95 | \return true if domain can be writtedn in a compressed way |
---|
| 96 | */ |
---|
| 97 | bool isCompressible(void) { if (!isCompressibleComputed_) computeIsCompressible() ; return isCompressible_ ;} |
---|
| 98 | private: |
---|
| 99 | bool isCompressible_ ; /** specify if the domain can be written in a compressed way */ |
---|
| 100 | bool isCompressibleComputed_=false ; /** Indicate if compressability has been computed*/ |
---|
| 101 | void computeIsCompressible() ; |
---|
| 102 | |
---|
| 103 | public: |
---|
[219] | 104 | |
---|
| 105 | /// Mutateur /// |
---|
| 106 | void addRelFile(const StdString & filename); |
---|
[676] | 107 | void addRelFileCompressed(const StdString& filename); |
---|
[219] | 108 | |
---|
[1869] | 109 | |
---|
[219] | 110 | |
---|
| 111 | /// Destructeur /// |
---|
| 112 | virtual ~CAxis(void); |
---|
| 113 | |
---|
[619] | 114 | virtual void parse(xml::CXMLNode & node); |
---|
| 115 | |
---|
[1345] | 116 | void setContextClient(CContextClient* contextClient); |
---|
| 117 | |
---|
[219] | 118 | /// Accesseurs statiques /// |
---|
| 119 | static StdString GetName(void); |
---|
| 120 | static StdString GetDefName(void); |
---|
| 121 | static ENodeType GetType(void); |
---|
| 122 | |
---|
[1235] | 123 | static bool dispatchEvent(CEventServer& event); |
---|
[1869] | 124 | |
---|
| 125 | /// Vérifications /// |
---|
| 126 | void checkAttributes(void); |
---|
| 127 | bool checkAttributes_done_ = false ; |
---|
[1235] | 128 | |
---|
[742] | 129 | void checkAttributesOnClient(); |
---|
[927] | 130 | void checkAttributesOnClientAfterTransformation(const std::vector<int>& globalDim, int orderPositionInGrid, |
---|
| 131 | CServerDistributionDescription::ServerDistributionType distType = CServerDistributionDescription::BAND_DISTRIBUTION); |
---|
[567] | 132 | void sendCheckedAttributes(const std::vector<int>& globalDim, int orderPositionInGrid, |
---|
| 133 | CServerDistributionDescription::ServerDistributionType disType = CServerDistributionDescription::BAND_DISTRIBUTION); |
---|
[619] | 134 | |
---|
[1215] | 135 | size_t getGlobalWrittenSize(void) ; |
---|
[676] | 136 | |
---|
[1129] | 137 | void computeWrittenIndex(); |
---|
[1639] | 138 | void computeWrittenCompressedIndex(MPI_Comm); |
---|
[619] | 139 | bool hasTransformation(); |
---|
| 140 | void solveInheritanceTransformation(); |
---|
[1144] | 141 | TransMapTypes getAllTransformations(); |
---|
[836] | 142 | void duplicateTransformation(CAxis*); |
---|
| 143 | CTransformation<CAxis>* addTransformation(ETranformationType transType, const StdString& id=""); |
---|
[1158] | 144 | bool isEqual(CAxis* axis); |
---|
[619] | 145 | |
---|
[1235] | 146 | public: |
---|
| 147 | bool hasValue; |
---|
[1558] | 148 | bool hasBounds; |
---|
| 149 | bool hasLabel; |
---|
| 150 | |
---|
[1637] | 151 | CArray<int,1> localIndexToWriteOnServer; |
---|
[1869] | 152 | |
---|
| 153 | void computeConnectedClients(CContextClient* client, const std::vector<int>& globalDim, int orderPositionInGrid); |
---|
| 154 | private: std::set<CContextClient*> computeConnectedClients_done_ ; public : |
---|
| 155 | /** The number of server of a context client. Avoid to re-compute indice computed in a previous computeConnectedClient */ |
---|
| 156 | private: std::set<int> listNbServer_ ; public: |
---|
[676] | 157 | |
---|
| 158 | private: |
---|
[551] | 159 | void checkData(); |
---|
| 160 | void checkMask(); |
---|
[1158] | 161 | void checkBounds(); |
---|
| 162 | void checkLabel(); |
---|
[1870] | 163 | public: |
---|
| 164 | void sendAxisToFileServer(CContextClient* client, const std::vector<int>& globalDim, int orderPositionInGrid) ; |
---|
| 165 | private: |
---|
| 166 | std::set<CContextClient*> sendAxisToFileServer_done_ ; |
---|
| 167 | |
---|
[1875] | 168 | public: |
---|
| 169 | void sendAxisToCouplerOut(CContextClient* client, const std::vector<int>& globalDim, int orderPositionInGrid, const string& fieldId, int posInGrid) ; |
---|
[1870] | 170 | private: |
---|
[1875] | 171 | std::set<CContextClient*> sendAxisToCouplerOut_done_ ; |
---|
| 172 | |
---|
| 173 | public: |
---|
| 174 | void makeAliasForCoupling(const string& fieldId, int posInGrid) ; |
---|
| 175 | |
---|
| 176 | private: |
---|
[1870] | 177 | void sendAttributes(CContextClient* client, const std::vector<int>& globalDim, int orderPositionInGrid, |
---|
[1875] | 178 | CServerDistributionDescription::ServerDistributionType distType, const string& axisId=""); |
---|
[1870] | 179 | void sendDistributionAttribute(CContextClient* client, const std::vector<int>& globalDim, int orderPositionInGrid, |
---|
[1875] | 180 | CServerDistributionDescription::ServerDistributionType distType, const string& axisId=""); |
---|
[1869] | 181 | |
---|
[595] | 182 | |
---|
[1875] | 183 | void sendNonDistributedAttributes(CContextClient* client, const string& axisId=""); |
---|
[1930] | 184 | void sendDistributedAttributes_old(CContextClient* client, const string& axisId=""); |
---|
[619] | 185 | |
---|
[1025] | 186 | static void recvNonDistributedAttributes(CEventServer& event); |
---|
[1930] | 187 | static void recvDistributedAttributes_old(CEventServer& event); |
---|
[1235] | 188 | static void recvDistributionAttribute(CEventServer& event); |
---|
[1025] | 189 | void recvNonDistributedAttributes(int rank, CBufferIn& buffer); |
---|
[1930] | 190 | void recvDistributedAttributes_old(vector<int>& rank, vector<CBufferIn*> buffers); |
---|
[1235] | 191 | void recvDistributionAttribute(CBufferIn& buffer); |
---|
[1025] | 192 | |
---|
[621] | 193 | void setTransformations(const TransMapTypes&); |
---|
[676] | 194 | |
---|
[567] | 195 | private: |
---|
[1345] | 196 | |
---|
[1875] | 197 | /** Clients that have to send a axis. There can be multiple clients in case of secondary server, otherwise only one client. */ |
---|
[1353] | 198 | std::list<CContextClient*> clients; |
---|
| 199 | std::set<CContextClient*> clientsSet; |
---|
[1345] | 200 | |
---|
[1875] | 201 | private: |
---|
[1869] | 202 | /** define if the axis is completed or not ie all attributes have been received before in case |
---|
| 203 | of grid reading from file or coupling */ |
---|
| 204 | bool isCompleted_=true ; |
---|
[1875] | 205 | public: |
---|
| 206 | /*! |
---|
| 207 | \brief Check if a axis is completed |
---|
| 208 | Before make any axis processing, we must be sure that all axis informations have |
---|
| 209 | been sent, for exemple when reading a grid in a file or when grid elements are sent by an |
---|
| 210 | other context (coupling). So all direct reference of the axis (axis_ref) must be also completed |
---|
| 211 | \return true if axis and axis reference are completed |
---|
| 212 | */ |
---|
| 213 | bool isCompleted(void) |
---|
| 214 | { |
---|
| 215 | if (hasDirectAxisReference()) if (!getDirectAxisReference()->isCompleted()) return false; |
---|
| 216 | else return isCompleted_ ; |
---|
| 217 | } |
---|
| 218 | void setCompleted(void) { isCompleted_=true ; } |
---|
| 219 | void unsetCompleted(void) { isCompleted_=false ; } |
---|
| 220 | |
---|
| 221 | private: |
---|
[219] | 222 | bool isChecked; |
---|
[567] | 223 | bool areClientAttributesChecked_; |
---|
[927] | 224 | bool isClientAfterTransformationChecked; |
---|
[676] | 225 | std::set<StdString> relFiles, relFilesCompressed; |
---|
[1143] | 226 | TransMapTypes transformationMap_; |
---|
[1869] | 227 | |
---|
[1337] | 228 | std::map<int, map<int,int> > nbSenders; // Mapping of number of communicating client to a server |
---|
[1542] | 229 | std::map<int, std::unordered_map<int, vector<size_t> > > indSrv_; // Global index of each client sent to server |
---|
[1236] | 230 | // std::map<int, vector<int> > indWrittenSrv_; // Global written index of each client sent to server |
---|
[1542] | 231 | std::unordered_map<size_t,size_t> globalLocalIndexMap_; |
---|
[1249] | 232 | std::map<int,int> numberWrittenIndexes_, totalNumberWrittenIndexes_, offsetWrittenIndexes_; |
---|
| 233 | std::map<int, CArray<int, 1> > compressedIndexToWriteOnServer; |
---|
[1337] | 234 | std::map<int, std::vector<int> > connectedServerRank_; |
---|
[1235] | 235 | bool computedWrittenIndex_; |
---|
[1099] | 236 | |
---|
[836] | 237 | private: |
---|
| 238 | static bool initializeTransformationMap(std::map<StdString, ETranformationType>& m); |
---|
| 239 | static std::map<StdString, ETranformationType> transformationMapList_; |
---|
| 240 | static bool dummyTransformationMapList_; |
---|
| 241 | |
---|
[1918] | 242 | |
---|
[1930] | 243 | ////////////////////////////////////////////////////////////////////////////////////// |
---|
| 244 | // this part is related to distribution, element definition, views and connectors // |
---|
| 245 | ////////////////////////////////////////////////////////////////////////////////////// |
---|
[1918] | 246 | |
---|
| 247 | private: |
---|
| 248 | CLocalElement* localElement_ = nullptr ; |
---|
| 249 | void initializeLocalElement(void) ; |
---|
| 250 | public: |
---|
| 251 | CLocalElement* getLocalElement(void) { if (localElement_==nullptr) initializeLocalElement() ; return localElement_ ; } |
---|
| 252 | CLocalView* getLocalView(CElementView::type type) { return getLocalElement()->getView(type) ;} |
---|
| 253 | private: |
---|
| 254 | void addFullView(void) ; |
---|
| 255 | void addWorkflowView(void) ; |
---|
| 256 | void addModelView(void) ; |
---|
| 257 | |
---|
| 258 | private: |
---|
| 259 | CLocalConnector* modelToWorkflowConnector_ ; |
---|
| 260 | void computeModelToWorkflowConnector(void) ; |
---|
| 261 | public: |
---|
| 262 | CLocalConnector* getModelToWorkflowConnector(void) { if (modelToWorkflowConnector_==nullptr) computeModelToWorkflowConnector() ; return modelToWorkflowConnector_ ;} |
---|
[1930] | 263 | |
---|
| 264 | public: |
---|
| 265 | void computeRemoteElement(CContextClient* client, EDistributionType) ; |
---|
[1956] | 266 | void distributeToServer(CContextClient* client, std::map<int, CArray<size_t,1>>& globalIndex, CScattererConnector* &scattererConnector, |
---|
| 267 | const string& axisId="") ; |
---|
[1918] | 268 | |
---|
[1930] | 269 | static void recvAxisDistribution(CEventServer& event) ; |
---|
| 270 | void receivedAxisDistribution(CEventServer& event, int phasis) ; |
---|
[1943] | 271 | void setServerMask(CArray<bool,1>& serverMask, CContextClient* client ) ; |
---|
[1930] | 272 | void sendDistributedAttributes(CContextClient* client, CScattererConnector& scattererConnector, const string& axisId) ; |
---|
| 273 | static void recvDistributedAttributes(CEventServer& event) ; |
---|
| 274 | void recvDistributedAttributes(CEventServer& event, const string& type) ; |
---|
| 275 | private: |
---|
| 276 | map<CContextClient*, CDistributedElement*> remoteElement_ ; |
---|
| 277 | public: |
---|
| 278 | CDistributedElement* getRemoteElement(CContextClient* client) {return remoteElement_[client] ;} |
---|
| 279 | private: |
---|
| 280 | map<CContextClient*, CScattererConnector*> clientToServerConnector_ ; |
---|
| 281 | public: |
---|
| 282 | CScattererConnector* getClientToServerConnector(CContextClient* client) { return clientToServerConnector_[client] ;} |
---|
| 283 | private: |
---|
| 284 | CGathererConnector* gathererConnector_ ; |
---|
[1943] | 285 | public: |
---|
| 286 | CGathererConnector* getGathererConnector(void) { return gathererConnector_ ;} |
---|
| 287 | private: |
---|
[1930] | 288 | CGathererConnector* serverFromClientConnector_ ; |
---|
| 289 | CDistributedElement* elementFrom_ ; |
---|
| 290 | public: |
---|
| 291 | CGathererConnector* getServerFromClientConnector(void) { return serverFromClientConnector_ ;} |
---|
| 292 | |
---|
[1934] | 293 | private: |
---|
| 294 | CScattererConnector* serverToClientConnector_ = nullptr ; |
---|
| 295 | public: |
---|
| 296 | CScattererConnector* getServerToClientConnector(void) { return serverToClientConnector_ ;} |
---|
[1930] | 297 | |
---|
[1934] | 298 | private: |
---|
| 299 | map<CContextClient*,CGathererConnector*> clientFromServerConnector_ ; |
---|
| 300 | public: |
---|
| 301 | CGathererConnector* getClientFromServerConnector(CContextClient* client) { return clientFromServerConnector_[client] ;} |
---|
[1930] | 302 | |
---|
[540] | 303 | DECLARE_REF_FUNC(Axis,axis) |
---|
[219] | 304 | }; // class CAxis |
---|
| 305 | |
---|
| 306 | ///-------------------------------------------------------------- |
---|
| 307 | |
---|
| 308 | // Declare/Define CAxisGroup and CAxisDefinition |
---|
| 309 | DECLARE_GROUP(CAxis); |
---|
[335] | 310 | } // namespace xios |
---|
[219] | 311 | |
---|
[591] | 312 | #endif // __XIOS_CAxis__ |
---|