[219] | 1 | #include "context.hpp" |
---|
[352] | 2 | #include "attribute_template.hpp" |
---|
| 3 | #include "object_template.hpp" |
---|
| 4 | #include "group_template.hpp" |
---|
[219] | 5 | |
---|
| 6 | #include "calendar_type.hpp" |
---|
[278] | 7 | #include "duration.hpp" |
---|
[219] | 8 | |
---|
[300] | 9 | #include "context_client.hpp" |
---|
| 10 | #include "context_server.hpp" |
---|
| 11 | #include "nc4_data_output.hpp" |
---|
[346] | 12 | #include "node_type.hpp" |
---|
[352] | 13 | #include "message.hpp" |
---|
| 14 | #include "type.hpp" |
---|
[591] | 15 | #include "xios_spl.hpp" |
---|
[1158] | 16 | #include "timer.hpp" |
---|
[2428] | 17 | #include "mem_checker.hpp" |
---|
[1158] | 18 | #include "memtrack.hpp" |
---|
[1215] | 19 | #include <limits> |
---|
[1349] | 20 | #include <fstream> |
---|
[992] | 21 | #include "server.hpp" |
---|
[1349] | 22 | #include "distribute_file_server2.hpp" |
---|
[697] | 23 | |
---|
[335] | 24 | namespace xios { |
---|
[509] | 25 | |
---|
[1542] | 26 | std::shared_ptr<CContextGroup> CContext::root; |
---|
[509] | 27 | |
---|
[219] | 28 | /// ////////////////////// Définitions ////////////////////// /// |
---|
| 29 | |
---|
| 30 | CContext::CContext(void) |
---|
| 31 | : CObjectTemplate<CContext>(), CContextAttributes() |
---|
[983] | 32 | , calendar(), hasClient(false), hasServer(false) |
---|
[1139] | 33 | , isPostProcessed(false), finalized(false) |
---|
[1009] | 34 | , idServer_(), client(0), server(0) |
---|
[1130] | 35 | , allProcessed(false), countChildCtx_(0) |
---|
[1622] | 36 | |
---|
[219] | 37 | { /* Ne rien faire de plus */ } |
---|
| 38 | |
---|
| 39 | CContext::CContext(const StdString & id) |
---|
| 40 | : CObjectTemplate<CContext>(id), CContextAttributes() |
---|
[983] | 41 | , calendar(), hasClient(false), hasServer(false) |
---|
[1139] | 42 | , isPostProcessed(false), finalized(false) |
---|
[1009] | 43 | , idServer_(), client(0), server(0) |
---|
[1130] | 44 | , allProcessed(false), countChildCtx_(0) |
---|
[219] | 45 | { /* Ne rien faire de plus */ } |
---|
| 46 | |
---|
| 47 | CContext::~CContext(void) |
---|
[509] | 48 | { |
---|
[597] | 49 | delete client; |
---|
| 50 | delete server; |
---|
[1071] | 51 | for (std::vector<CContextClient*>::iterator it = clientPrimServer.begin(); it != clientPrimServer.end(); it++) delete *it; |
---|
| 52 | for (std::vector<CContextServer*>::iterator it = serverPrimServer.begin(); it != serverPrimServer.end(); it++) delete *it; |
---|
[1139] | 53 | |
---|
[300] | 54 | } |
---|
[219] | 55 | |
---|
| 56 | //---------------------------------------------------------------- |
---|
[509] | 57 | //! Get name of context |
---|
[219] | 58 | StdString CContext::GetName(void) { return (StdString("context")); } |
---|
| 59 | StdString CContext::GetDefName(void){ return (CContext::GetName()); } |
---|
| 60 | ENodeType CContext::GetType(void) { return (eContext); } |
---|
| 61 | |
---|
| 62 | //---------------------------------------------------------------- |
---|
[640] | 63 | |
---|
[509] | 64 | /*! |
---|
| 65 | \brief Get context group (context root) |
---|
| 66 | \return Context root |
---|
| 67 | */ |
---|
[347] | 68 | CContextGroup* CContext::getRoot(void) |
---|
[1622] | 69 | TRY |
---|
[509] | 70 | { |
---|
[1542] | 71 | if (root.get()==NULL) root=std::shared_ptr<CContextGroup>(new CContextGroup(xml::CXMLNode::GetRootName())); |
---|
[509] | 72 | return root.get(); |
---|
[219] | 73 | } |
---|
[1622] | 74 | CATCH |
---|
[219] | 75 | |
---|
[640] | 76 | //---------------------------------------------------------------- |
---|
[509] | 77 | |
---|
| 78 | /*! |
---|
| 79 | \brief Get calendar of a context |
---|
| 80 | \return Calendar |
---|
| 81 | */ |
---|
[1542] | 82 | std::shared_ptr<CCalendar> CContext::getCalendar(void) const |
---|
[1622] | 83 | TRY |
---|
[219] | 84 | { |
---|
| 85 | return (this->calendar); |
---|
| 86 | } |
---|
[1622] | 87 | CATCH |
---|
[509] | 88 | |
---|
[219] | 89 | //---------------------------------------------------------------- |
---|
[640] | 90 | |
---|
[509] | 91 | /*! |
---|
| 92 | \brief Set a context with a calendar |
---|
| 93 | \param[in] newCalendar new calendar |
---|
| 94 | */ |
---|
[1542] | 95 | void CContext::setCalendar(std::shared_ptr<CCalendar> newCalendar) |
---|
[1622] | 96 | TRY |
---|
[219] | 97 | { |
---|
| 98 | this->calendar = newCalendar; |
---|
| 99 | } |
---|
[1622] | 100 | CATCH_DUMP_ATTR |
---|
[509] | 101 | |
---|
[219] | 102 | //---------------------------------------------------------------- |
---|
[509] | 103 | /*! |
---|
| 104 | \brief Parse xml file and write information into context object |
---|
| 105 | \param [in] node xmld node corresponding in xml file |
---|
| 106 | */ |
---|
[219] | 107 | void CContext::parse(xml::CXMLNode & node) |
---|
[1622] | 108 | TRY |
---|
[219] | 109 | { |
---|
| 110 | CContext::SuperClass::parse(node); |
---|
| 111 | |
---|
| 112 | // PARSING POUR GESTION DES ENFANTS |
---|
[278] | 113 | xml::THashAttributes attributes = node.getAttributes(); |
---|
[219] | 114 | |
---|
[278] | 115 | if (attributes.end() != attributes.find("src")) |
---|
| 116 | { |
---|
| 117 | StdIFStream ifs ( attributes["src"].c_str() , StdIFStream::in ); |
---|
[462] | 118 | if ( (ifs.rdstate() & std::ifstream::failbit ) != 0 ) |
---|
| 119 | ERROR("void CContext::parse(xml::CXMLNode & node)", |
---|
| 120 | <<endl<< "Can not open <"<<attributes["src"].c_str()<<"> file" ); |
---|
[278] | 121 | if (!ifs.good()) |
---|
| 122 | ERROR("CContext::parse(xml::CXMLNode & node)", |
---|
| 123 | << "[ filename = " << attributes["src"] << " ] Bad xml stream !"); |
---|
[462] | 124 | xml::CXMLParser::ParseInclude(ifs, attributes["src"], *this); |
---|
[278] | 125 | } |
---|
| 126 | |
---|
[219] | 127 | if (node.getElementName().compare(CContext::GetName())) |
---|
[421] | 128 | DEBUG("Le noeud is wrong defined but will be considered as a context !"); |
---|
[219] | 129 | |
---|
| 130 | if (!(node.goToChildElement())) |
---|
| 131 | { |
---|
| 132 | DEBUG("Le context ne contient pas d'enfant !"); |
---|
| 133 | } |
---|
| 134 | else |
---|
| 135 | { |
---|
| 136 | do { // Parcours des contextes pour traitement. |
---|
| 137 | |
---|
| 138 | StdString name = node.getElementName(); |
---|
| 139 | attributes.clear(); |
---|
| 140 | attributes = node.getAttributes(); |
---|
| 141 | |
---|
| 142 | if (attributes.end() != attributes.find("id")) |
---|
[509] | 143 | { |
---|
| 144 | DEBUG(<< "Definition node has an id," |
---|
| 145 | << "it will not be taking account !"); |
---|
| 146 | } |
---|
[219] | 147 | |
---|
| 148 | #define DECLARE_NODE(Name_, name_) \ |
---|
| 149 | if (name.compare(C##Name_##Definition::GetDefName()) == 0) \ |
---|
[549] | 150 | { C##Name_##Definition::create(C##Name_##Definition::GetDefName()) -> parse(node); continue; } |
---|
[219] | 151 | #define DECLARE_NODE_PAR(Name_, name_) |
---|
| 152 | #include "node_type.conf" |
---|
[286] | 153 | |
---|
[421] | 154 | DEBUG(<< "The element \'" << name |
---|
| 155 | << "\' in the context \'" << CContext::getCurrent()->getId() |
---|
| 156 | << "\' is not a definition !"); |
---|
[219] | 157 | |
---|
| 158 | } while (node.goToNextElement()); |
---|
| 159 | |
---|
| 160 | node.goToParentElement(); // Retour au parent |
---|
| 161 | } |
---|
| 162 | } |
---|
[1622] | 163 | CATCH_DUMP_ATTR |
---|
[219] | 164 | |
---|
| 165 | //---------------------------------------------------------------- |
---|
[509] | 166 | //! Show tree structure of context |
---|
[219] | 167 | void CContext::ShowTree(StdOStream & out) |
---|
[1622] | 168 | TRY |
---|
[219] | 169 | { |
---|
[549] | 170 | StdString currentContextId = CContext::getCurrent() -> getId(); |
---|
[347] | 171 | std::vector<CContext*> def_vector = |
---|
[346] | 172 | CContext::getRoot()->getChildList(); |
---|
[347] | 173 | std::vector<CContext*>::iterator |
---|
[219] | 174 | it = def_vector.begin(), end = def_vector.end(); |
---|
| 175 | |
---|
| 176 | out << "<? xml version=\"1.0\" ?>" << std::endl; |
---|
| 177 | out << "<" << xml::CXMLNode::GetRootName() << " >" << std::endl; |
---|
[509] | 178 | |
---|
[219] | 179 | for (; it != end; it++) |
---|
| 180 | { |
---|
[509] | 181 | CContext* context = *it; |
---|
| 182 | CContext::setCurrent(context->getId()); |
---|
[219] | 183 | out << *context << std::endl; |
---|
| 184 | } |
---|
[509] | 185 | |
---|
[219] | 186 | out << "</" << xml::CXMLNode::GetRootName() << " >" << std::endl; |
---|
[509] | 187 | CContext::setCurrent(currentContextId); |
---|
[219] | 188 | } |
---|
[1622] | 189 | CATCH |
---|
[346] | 190 | |
---|
[219] | 191 | //---------------------------------------------------------------- |
---|
| 192 | |
---|
[509] | 193 | //! Convert context object into string (to print) |
---|
[219] | 194 | StdString CContext::toString(void) const |
---|
[1622] | 195 | TRY |
---|
[219] | 196 | { |
---|
| 197 | StdOStringStream oss; |
---|
| 198 | oss << "<" << CContext::GetName() |
---|
| 199 | << " id=\"" << this->getId() << "\" " |
---|
| 200 | << SuperClassAttribute::toString() << ">" << std::endl; |
---|
| 201 | if (!this->hasChild()) |
---|
| 202 | { |
---|
| 203 | //oss << "<!-- No definition -->" << std::endl; // fait planter l'incrémentation |
---|
| 204 | } |
---|
| 205 | else |
---|
| 206 | { |
---|
| 207 | |
---|
| 208 | #define DECLARE_NODE(Name_, name_) \ |
---|
[346] | 209 | if (C##Name_##Definition::has(C##Name_##Definition::GetDefName())) \ |
---|
| 210 | oss << * C##Name_##Definition::get(C##Name_##Definition::GetDefName()) << std::endl; |
---|
[219] | 211 | #define DECLARE_NODE_PAR(Name_, name_) |
---|
| 212 | #include "node_type.conf" |
---|
| 213 | |
---|
| 214 | } |
---|
| 215 | oss << "</" << CContext::GetName() << " >"; |
---|
| 216 | return (oss.str()); |
---|
| 217 | } |
---|
[1622] | 218 | CATCH |
---|
[219] | 219 | |
---|
| 220 | //---------------------------------------------------------------- |
---|
| 221 | |
---|
[509] | 222 | /*! |
---|
| 223 | \brief Find all inheritace among objects in a context. |
---|
| 224 | \param [in] apply (true) write attributes of parent into ones of child if they are empty |
---|
| 225 | (false) write attributes of parent into a new container of child |
---|
| 226 | \param [in] parent unused |
---|
| 227 | */ |
---|
[445] | 228 | void CContext::solveDescInheritance(bool apply, const CAttributeMap * const UNUSED(parent)) |
---|
[1622] | 229 | TRY |
---|
[219] | 230 | { |
---|
| 231 | #define DECLARE_NODE(Name_, name_) \ |
---|
[354] | 232 | if (C##Name_##Definition::has(C##Name_##Definition::GetDefName())) \ |
---|
[445] | 233 | C##Name_##Definition::get(C##Name_##Definition::GetDefName())->solveDescInheritance(apply); |
---|
[219] | 234 | #define DECLARE_NODE_PAR(Name_, name_) |
---|
| 235 | #include "node_type.conf" |
---|
| 236 | } |
---|
[1622] | 237 | CATCH_DUMP_ATTR |
---|
[219] | 238 | |
---|
| 239 | //---------------------------------------------------------------- |
---|
| 240 | |
---|
[509] | 241 | //! Verify if all root definition in the context have child. |
---|
[219] | 242 | bool CContext::hasChild(void) const |
---|
[1622] | 243 | TRY |
---|
[219] | 244 | { |
---|
| 245 | return ( |
---|
| 246 | #define DECLARE_NODE(Name_, name_) \ |
---|
[346] | 247 | C##Name_##Definition::has(C##Name_##Definition::GetDefName()) || |
---|
[219] | 248 | #define DECLARE_NODE_PAR(Name_, name_) |
---|
| 249 | #include "node_type.conf" |
---|
| 250 | false); |
---|
| 251 | } |
---|
[1622] | 252 | CATCH |
---|
[219] | 253 | |
---|
| 254 | //---------------------------------------------------------------- |
---|
| 255 | |
---|
| 256 | void CContext::CleanTree(void) |
---|
[1622] | 257 | TRY |
---|
[219] | 258 | { |
---|
[549] | 259 | #define DECLARE_NODE(Name_, name_) C##Name_##Definition::ClearAllAttributes(); |
---|
[219] | 260 | #define DECLARE_NODE_PAR(Name_, name_) |
---|
| 261 | #include "node_type.conf" |
---|
| 262 | } |
---|
[1622] | 263 | CATCH |
---|
| 264 | |
---|
[219] | 265 | ///--------------------------------------------------------------- |
---|
[509] | 266 | |
---|
| 267 | //! Initialize client side |
---|
[1639] | 268 | void CContext::initClient(MPI_Comm intraComm, MPI_Comm interComm, CContext* cxtServer /*= 0*/) |
---|
[1622] | 269 | TRY |
---|
[300] | 270 | { |
---|
[983] | 271 | |
---|
| 272 | hasClient = true; |
---|
[1639] | 273 | MPI_Comm intraCommServer, interCommServer; |
---|
[1316] | 274 | |
---|
[1054] | 275 | |
---|
[1021] | 276 | if (CServer::serverLevel != 1) |
---|
[1071] | 277 | // initClient is called by client |
---|
[983] | 278 | { |
---|
| 279 | client = new CContextClient(this, intraComm, interComm, cxtServer); |
---|
[1054] | 280 | if (cxtServer) // Attached mode |
---|
| 281 | { |
---|
| 282 | intraCommServer = intraComm; |
---|
| 283 | interCommServer = interComm; |
---|
| 284 | } |
---|
| 285 | else |
---|
| 286 | { |
---|
[1639] | 287 | MPI_Comm_dup(intraComm, &intraCommServer); |
---|
[1071] | 288 | comms.push_back(intraCommServer); |
---|
[1639] | 289 | MPI_Comm_dup(interComm, &interCommServer); |
---|
[1071] | 290 | comms.push_back(interCommServer); |
---|
[1054] | 291 | } |
---|
[1316] | 292 | /* for registry take the id of client context */ |
---|
| 293 | /* for servers, supress the _server_ from id */ |
---|
| 294 | string contextRegistryId=getId() ; |
---|
| 295 | size_t pos=contextRegistryId.find("_server_") ; |
---|
| 296 | if (pos!=std::string::npos) contextRegistryId=contextRegistryId.substr(0,pos) ; |
---|
| 297 | |
---|
[1071] | 298 | registryIn=new CRegistry(intraComm); |
---|
[1316] | 299 | registryIn->setPath(contextRegistryId) ; |
---|
[1071] | 300 | if (client->clientRank==0) registryIn->fromFile("xios_registry.bin") ; |
---|
| 301 | registryIn->bcastRegistry() ; |
---|
| 302 | registryOut=new CRegistry(intraComm) ; |
---|
[1316] | 303 | |
---|
| 304 | registryOut->setPath(contextRegistryId) ; |
---|
[1071] | 305 | |
---|
| 306 | server = new CContextServer(this, intraCommServer, interCommServer); |
---|
[983] | 307 | } |
---|
[1021] | 308 | else |
---|
[1054] | 309 | // initClient is called by primary server |
---|
[983] | 310 | { |
---|
[1009] | 311 | clientPrimServer.push_back(new CContextClient(this, intraComm, interComm)); |
---|
[1639] | 312 | MPI_Comm_dup(intraComm, &intraCommServer); |
---|
[1071] | 313 | comms.push_back(intraCommServer); |
---|
[1639] | 314 | MPI_Comm_dup(interComm, &interCommServer); |
---|
[1071] | 315 | comms.push_back(interCommServer); |
---|
| 316 | serverPrimServer.push_back(new CContextServer(this, intraCommServer, interCommServer)); |
---|
[983] | 317 | } |
---|
[509] | 318 | } |
---|
[1622] | 319 | CATCH_DUMP_ATTR |
---|
[219] | 320 | |
---|
[1330] | 321 | /*! |
---|
| 322 | Sets client buffers. |
---|
| 323 | \param [in] contextClient |
---|
| 324 | \param [in] bufferForWriting True if buffers are used for sending data for writing |
---|
| 325 | This flag is only true for client and server-1 for communication with server-2 |
---|
| 326 | */ |
---|
| 327 | void CContext::setClientServerBuffer(CContextClient* contextClient, bool bufferForWriting) |
---|
[1622] | 328 | TRY |
---|
[509] | 329 | { |
---|
[1201] | 330 | // Estimated minimum event size for small events (10 is an arbitrary constant just for safety) |
---|
[1372] | 331 | const size_t minEventSize = CEventClient::headerSize + getIdServer().size() + 10 * sizeof(int); |
---|
[1201] | 332 | |
---|
| 333 | // Ensure there is at least some room for 20 of such events in the buffers |
---|
| 334 | size_t minBufferSize = std::max(CXios::minBufferSize, 20 * minEventSize); |
---|
| 335 | |
---|
[583] | 336 | #define DECLARE_NODE(Name_, name_) \ |
---|
[731] | 337 | if (minBufferSize < sizeof(C##Name_##Definition)) minBufferSize = sizeof(C##Name_##Definition); |
---|
[583] | 338 | #define DECLARE_NODE_PAR(Name_, name_) |
---|
| 339 | #include "node_type.conf" |
---|
[719] | 340 | #undef DECLARE_NODE |
---|
| 341 | #undef DECLARE_NODE_PAR |
---|
| 342 | |
---|
[1201] | 343 | // Compute the buffer sizes needed to send the attributes and data corresponding to fields |
---|
[917] | 344 | std::map<int, StdSize> maxEventSize; |
---|
[1330] | 345 | std::map<int, StdSize> bufferSize = getAttributesBufferSize(maxEventSize, contextClient, bufferForWriting); |
---|
| 346 | std::map<int, StdSize> dataBufferSize = getDataBufferSize(maxEventSize, contextClient, bufferForWriting); |
---|
[729] | 347 | |
---|
[909] | 348 | std::map<int, StdSize>::iterator it, ite = dataBufferSize.end(); |
---|
[731] | 349 | for (it = dataBufferSize.begin(); it != ite; ++it) |
---|
| 350 | if (it->second > bufferSize[it->first]) bufferSize[it->first] = it->second; |
---|
| 351 | |
---|
[1227] | 352 | // Apply the buffer size factor, check that we are above the minimum buffer size and below the maximum size |
---|
[909] | 353 | ite = bufferSize.end(); |
---|
| 354 | for (it = bufferSize.begin(); it != ite; ++it) |
---|
| 355 | { |
---|
| 356 | it->second *= CXios::bufferSizeFactor; |
---|
| 357 | if (it->second < minBufferSize) it->second = minBufferSize; |
---|
[1227] | 358 | if (it->second > CXios::maxBufferSize) it->second = CXios::maxBufferSize; |
---|
[909] | 359 | } |
---|
| 360 | |
---|
[1201] | 361 | // Leaders will have to send some control events so ensure there is some room for those in the buffers |
---|
[1184] | 362 | if (contextClient->isServerLeader()) |
---|
[598] | 363 | { |
---|
[1184] | 364 | const std::list<int>& ranks = contextClient->getRanksServerLeader(); |
---|
[729] | 365 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
[1201] | 366 | { |
---|
| 367 | if (!bufferSize.count(*itRank)) |
---|
| 368 | { |
---|
| 369 | bufferSize[*itRank] = minBufferSize; |
---|
| 370 | maxEventSize[*itRank] = minEventSize; |
---|
| 371 | } |
---|
| 372 | } |
---|
[598] | 373 | } |
---|
[1184] | 374 | contextClient->setBufferSize(bufferSize, maxEventSize); |
---|
[509] | 375 | } |
---|
[1622] | 376 | CATCH_DUMP_ATTR |
---|
[509] | 377 | |
---|
| 378 | //! Verify whether a context is initialized |
---|
[461] | 379 | bool CContext::isInitialized(void) |
---|
[1622] | 380 | TRY |
---|
[461] | 381 | { |
---|
[549] | 382 | return hasClient; |
---|
[461] | 383 | } |
---|
[1622] | 384 | CATCH_DUMP_ATTR |
---|
[509] | 385 | |
---|
[1639] | 386 | void CContext::initServer(MPI_Comm intraComm, MPI_Comm interComm, CContext* cxtClient /*= 0*/) |
---|
[1622] | 387 | TRY |
---|
[300] | 388 | { |
---|
[549] | 389 | hasServer=true; |
---|
| 390 | server = new CContextServer(this,intraComm,interComm); |
---|
[697] | 391 | |
---|
[1316] | 392 | /* for registry take the id of client context */ |
---|
| 393 | /* for servers, supress the _server_ from id */ |
---|
| 394 | string contextRegistryId=getId() ; |
---|
| 395 | size_t pos=contextRegistryId.find("_server_") ; |
---|
| 396 | if (pos!=std::string::npos) contextRegistryId=contextRegistryId.substr(0,pos) ; |
---|
| 397 | |
---|
[1071] | 398 | registryIn=new CRegistry(intraComm); |
---|
[1316] | 399 | registryIn->setPath(contextRegistryId) ; |
---|
[1071] | 400 | if (server->intraCommRank==0) registryIn->fromFile("xios_registry.bin") ; |
---|
| 401 | registryIn->bcastRegistry() ; |
---|
| 402 | registryOut=new CRegistry(intraComm) ; |
---|
[1316] | 403 | registryOut->setPath(contextRegistryId) ; |
---|
[775] | 404 | |
---|
[1639] | 405 | MPI_Comm intraCommClient, interCommClient; |
---|
[597] | 406 | if (cxtClient) // Attached mode |
---|
| 407 | { |
---|
| 408 | intraCommClient = intraComm; |
---|
| 409 | interCommClient = interComm; |
---|
| 410 | } |
---|
| 411 | else |
---|
| 412 | { |
---|
[1639] | 413 | MPI_Comm_dup(intraComm, &intraCommClient); |
---|
[1071] | 414 | comms.push_back(intraCommClient); |
---|
[1639] | 415 | MPI_Comm_dup(interComm, &interCommClient); |
---|
[1071] | 416 | comms.push_back(interCommClient); |
---|
[597] | 417 | } |
---|
[1158] | 418 | client = new CContextClient(this,intraCommClient,interCommClient, cxtClient); |
---|
[509] | 419 | } |
---|
[1622] | 420 | CATCH_DUMP_ATTR |
---|
[300] | 421 | |
---|
[597] | 422 | //! Try to send the buffers and receive possible answers |
---|
[1378] | 423 | bool CContext::checkBuffersAndListen(bool enableEventsProcessing /*= true*/) |
---|
[1622] | 424 | TRY |
---|
[1130] | 425 | { |
---|
| 426 | bool clientReady, serverFinished; |
---|
[1054] | 427 | |
---|
[1130] | 428 | // Only classical servers are non-blocking |
---|
| 429 | if (CServer::serverLevel == 0) |
---|
| 430 | { |
---|
| 431 | client->checkBuffers(); |
---|
| 432 | bool hasTmpBufferedEvent = client->hasTemporarilyBufferedEvent(); |
---|
| 433 | if (hasTmpBufferedEvent) |
---|
| 434 | hasTmpBufferedEvent = !client->sendTemporarilyBufferedEvent(); |
---|
| 435 | // Don't process events if there is a temporarily buffered event |
---|
[1378] | 436 | return server->eventLoop(!hasTmpBufferedEvent || !enableEventsProcessing); |
---|
[1130] | 437 | } |
---|
| 438 | else if (CServer::serverLevel == 1) |
---|
| 439 | { |
---|
[1139] | 440 | if (!finalized) |
---|
| 441 | client->checkBuffers(); |
---|
| 442 | bool serverFinished = true; |
---|
| 443 | if (!finalized) |
---|
[1380] | 444 | serverFinished = server->eventLoop(enableEventsProcessing); |
---|
[1130] | 445 | bool serverPrimFinished = true; |
---|
| 446 | for (int i = 0; i < clientPrimServer.size(); ++i) |
---|
| 447 | { |
---|
[1139] | 448 | if (!finalized) |
---|
| 449 | clientPrimServer[i]->checkBuffers(); |
---|
| 450 | if (!finalized) |
---|
[1378] | 451 | serverPrimFinished *= serverPrimServer[i]->eventLoop(enableEventsProcessing); |
---|
[1130] | 452 | } |
---|
| 453 | return ( serverFinished && serverPrimFinished); |
---|
| 454 | } |
---|
[1054] | 455 | |
---|
[1130] | 456 | else if (CServer::serverLevel == 2) |
---|
| 457 | { |
---|
| 458 | client->checkBuffers(); |
---|
[1378] | 459 | return server->eventLoop(enableEventsProcessing); |
---|
[1130] | 460 | } |
---|
| 461 | } |
---|
[1622] | 462 | CATCH_DUMP_ATTR |
---|
[1054] | 463 | |
---|
[509] | 464 | //! Terminate a context |
---|
[300] | 465 | void CContext::finalize(void) |
---|
[1622] | 466 | TRY |
---|
[300] | 467 | { |
---|
[1418] | 468 | if (hasClient && !hasServer) // For now we only use server level 1 to read data |
---|
| 469 | { |
---|
| 470 | doPreTimestepOperationsForEnabledReadModeFiles(); |
---|
| 471 | } |
---|
[1130] | 472 | // Send registry upon calling the function the first time |
---|
| 473 | if (countChildCtx_ == 0) |
---|
| 474 | if (hasClient) sendRegistry() ; |
---|
| 475 | |
---|
| 476 | // Client: |
---|
| 477 | // (1) blocking send context finalize to its server |
---|
| 478 | // (2) blocking receive context finalize from its server |
---|
[1194] | 479 | // (3) some memory deallocations |
---|
[1130] | 480 | if (CXios::isClient) |
---|
[1009] | 481 | { |
---|
[1130] | 482 | // Make sure that client (model) enters the loop only once |
---|
| 483 | if (countChildCtx_ < 1) |
---|
| 484 | { |
---|
| 485 | ++countChildCtx_; |
---|
[983] | 486 | |
---|
[1130] | 487 | client->finalize(); |
---|
| 488 | while (client->havePendingRequests()) |
---|
| 489 | client->checkBuffers(); |
---|
[1054] | 490 | |
---|
[1130] | 491 | while (!server->hasFinished()) |
---|
| 492 | server->eventLoop(); |
---|
[1139] | 493 | |
---|
[1194] | 494 | if (hasServer) // Mode attache |
---|
| 495 | { |
---|
| 496 | closeAllFile(); |
---|
| 497 | registryOut->hierarchicalGatherRegistry() ; |
---|
| 498 | if (server->intraCommRank==0) CXios::globalRegistry->mergeRegistry(*registryOut) ; |
---|
| 499 | } |
---|
[1139] | 500 | |
---|
[1194] | 501 | //! Deallocate client buffers |
---|
| 502 | client->releaseBuffers(); |
---|
| 503 | |
---|
| 504 | //! Free internally allocated communicators |
---|
[1639] | 505 | for (std::list<MPI_Comm>::iterator it = comms.begin(); it != comms.end(); ++it) |
---|
[2029] | 506 | /* MPI_Comm_free(&(*it)) */ ; // WARNING remove freeing communicator !! --> deadlock raised, to be checked |
---|
[1194] | 507 | comms.clear(); |
---|
| 508 | |
---|
| 509 | info(20)<<"CContext: Context <"<<getId()<<"> is finalized."<<endl; |
---|
[1130] | 510 | } |
---|
| 511 | } |
---|
| 512 | else if (CXios::isServer) |
---|
| 513 | { |
---|
[1194] | 514 | // First context finalize message received from a model |
---|
| 515 | // Send context finalize to its child contexts (if any) |
---|
[1130] | 516 | if (countChildCtx_ == 0) |
---|
[1009] | 517 | for (int i = 0; i < clientPrimServer.size(); ++i) |
---|
| 518 | clientPrimServer[i]->finalize(); |
---|
[983] | 519 | |
---|
[1139] | 520 | // (Last) context finalized message received |
---|
[1130] | 521 | if (countChildCtx_ == clientPrimServer.size()) |
---|
[1194] | 522 | { |
---|
| 523 | // Blocking send of context finalize message to its client (e.g. primary server or model) |
---|
[1378] | 524 | info(100)<<"DEBUG: context "<<getId()<<" Send client finalize<<"<<endl ; |
---|
[1130] | 525 | client->finalize(); |
---|
[1194] | 526 | bool bufferReleased; |
---|
| 527 | do |
---|
| 528 | { |
---|
| 529 | client->checkBuffers(); |
---|
| 530 | bufferReleased = !client->havePendingRequests(); |
---|
| 531 | } while (!bufferReleased); |
---|
| 532 | finalized = true; |
---|
[983] | 533 | |
---|
[1232] | 534 | closeAllFile(); // Just move to here to make sure that server-level 1 can close files |
---|
[1194] | 535 | if (hasServer && !hasClient) |
---|
[1232] | 536 | { |
---|
[1194] | 537 | registryOut->hierarchicalGatherRegistry() ; |
---|
| 538 | if (server->intraCommRank==0) CXios::globalRegistry->mergeRegistry(*registryOut) ; |
---|
| 539 | } |
---|
[1077] | 540 | |
---|
[1194] | 541 | //! Deallocate client buffers |
---|
| 542 | client->releaseBuffers(); |
---|
| 543 | for (int i = 0; i < clientPrimServer.size(); ++i) |
---|
| 544 | clientPrimServer[i]->releaseBuffers(); |
---|
[1139] | 545 | |
---|
[1194] | 546 | //! Free internally allocated communicators |
---|
[1639] | 547 | for (std::list<MPI_Comm>::iterator it = comms.begin(); it != comms.end(); ++it) |
---|
[2029] | 548 | /* MPI_Comm_free(&(*it)) */; // WARNING remove freeing communicator !! --> deadlock raised, to be checked |
---|
[1194] | 549 | comms.clear(); |
---|
| 550 | |
---|
| 551 | info(20)<<"CContext: Context <"<<getId()<<"> is finalized."<<endl; |
---|
[1139] | 552 | } |
---|
| 553 | |
---|
[1194] | 554 | ++countChildCtx_; |
---|
[1130] | 555 | } |
---|
| 556 | } |
---|
[1622] | 557 | CATCH_DUMP_ATTR |
---|
[1130] | 558 | |
---|
[1071] | 559 | //! Free internally allocated communicators |
---|
| 560 | void CContext::freeComms(void) |
---|
[1622] | 561 | TRY |
---|
[1071] | 562 | { |
---|
[1639] | 563 | for (std::list<MPI_Comm>::iterator it = comms.begin(); it != comms.end(); ++it) |
---|
[2029] | 564 | /* MPI_Comm_free(&(*it)) */ ; // WARNING remove freeing communicator !! --> deadlock raised, to be checked |
---|
[1071] | 565 | comms.clear(); |
---|
| 566 | } |
---|
[1622] | 567 | CATCH_DUMP_ATTR |
---|
[509] | 568 | |
---|
[1130] | 569 | //! Deallocate buffers allocated by clientContexts |
---|
| 570 | void CContext::releaseClientBuffers(void) |
---|
[1622] | 571 | TRY |
---|
[1130] | 572 | { |
---|
| 573 | client->releaseBuffers(); |
---|
| 574 | for (int i = 0; i < clientPrimServer.size(); ++i) |
---|
| 575 | clientPrimServer[i]->releaseBuffers(); |
---|
| 576 | } |
---|
[1622] | 577 | CATCH_DUMP_ATTR |
---|
[1130] | 578 | |
---|
[1025] | 579 | void CContext::postProcessingGlobalAttributes() |
---|
[1622] | 580 | TRY |
---|
[300] | 581 | { |
---|
[1144] | 582 | if (allProcessed) return; |
---|
[1025] | 583 | |
---|
[1144] | 584 | // After xml is parsed, there are some more works with post processing |
---|
| 585 | postProcessing(); |
---|
[983] | 586 | |
---|
[1144] | 587 | // Check grid and calculate its distribution |
---|
[1232] | 588 | checkGridEnabledFields(); |
---|
| 589 | |
---|
[1208] | 590 | // Distribute files between secondary servers according to the data size |
---|
| 591 | distributeFiles(); |
---|
| 592 | |
---|
[1330] | 593 | setClientServerBuffer(client, (hasClient && !hasServer)); |
---|
[1255] | 594 | for (int i = 0; i < clientPrimServer.size(); ++i) |
---|
[1330] | 595 | setClientServerBuffer(clientPrimServer[i], true); |
---|
[300] | 596 | |
---|
[983] | 597 | if (hasClient) |
---|
[510] | 598 | { |
---|
[509] | 599 | // Send all attributes of current context to server |
---|
| 600 | this->sendAllAttributesToServer(); |
---|
[459] | 601 | |
---|
[549] | 602 | // Send all attributes of current calendar |
---|
| 603 | CCalendarWrapper::get(CCalendarWrapper::GetDefName())->sendAllAttributesToServer(); |
---|
| 604 | |
---|
[509] | 605 | // We have enough information to send to server |
---|
[1021] | 606 | // First of all, send all enabled files |
---|
[1232] | 607 | sendEnabledFiles(this->enabledWriteModeFiles); |
---|
| 608 | // We only use server-level 1 (for now) to read data |
---|
| 609 | if (!hasServer) |
---|
| 610 | sendEnabledFiles(this->enabledReadModeFiles); |
---|
[509] | 611 | |
---|
[1232] | 612 | // Then, send all enabled fields |
---|
| 613 | sendEnabledFieldsInFiles(this->enabledWriteModeFiles); |
---|
| 614 | if (!hasServer) |
---|
| 615 | sendEnabledFieldsInFiles(this->enabledReadModeFiles); |
---|
[1021] | 616 | |
---|
[1239] | 617 | // Then, check whether we have domain_ref, axis_ref or scalar_ref attached to the enabled fields |
---|
| 618 | // If any, so send them to server |
---|
[1232] | 619 | sendRefDomainsAxisScalars(this->enabledWriteModeFiles); |
---|
| 620 | if (!hasServer) |
---|
| 621 | sendRefDomainsAxisScalars(this->enabledReadModeFiles); |
---|
[1021] | 622 | |
---|
[1239] | 623 | // Check whether enabled fields have grid_ref, if any, send this info to server |
---|
[1237] | 624 | sendRefGrid(this->enabledFiles); |
---|
| 625 | // This code may be useful in the future when we want to seperate completely read and write |
---|
| 626 | // sendRefGrid(this->enabledWriteModeFiles); |
---|
| 627 | // if (!hasServer) |
---|
| 628 | // sendRefGrid(this->enabledReadModeFiles); |
---|
[1239] | 629 | |
---|
| 630 | // A grid of enabled fields composed of several components which must be checked then their |
---|
| 631 | // checked attributes should be sent to server |
---|
| 632 | sendGridComponentEnabledFieldsInFiles(this->enabledFiles); // This code can be seperated in two (one for reading, another for writing) |
---|
[1021] | 633 | |
---|
[983] | 634 | // We have a xml tree on the server side and now, it should be also processed |
---|
[1239] | 635 | sendPostProcessing(); |
---|
[1232] | 636 | |
---|
[1239] | 637 | // Finally, we send information of grid itself to server |
---|
| 638 | sendGridEnabledFieldsInFiles(this->enabledWriteModeFiles); |
---|
| 639 | if (!hasServer) |
---|
[1232] | 640 | sendGridEnabledFieldsInFiles(this->enabledReadModeFiles); |
---|
[983] | 641 | } |
---|
[1025] | 642 | allProcessed = true; |
---|
| 643 | } |
---|
[1622] | 644 | CATCH_DUMP_ATTR |
---|
[983] | 645 | |
---|
[1025] | 646 | void CContext::sendPostProcessingGlobalAttributes() |
---|
[1622] | 647 | TRY |
---|
[1025] | 648 | { |
---|
[1027] | 649 | // Use correct context client to send message |
---|
[1030] | 650 | // int nbSrvPools = (hasServer) ? clientPrimServer.size() : 1; |
---|
| 651 | int nbSrvPools = (this->hasServer) ? (this->hasClient ? this->clientPrimServer.size() : 0) : 1; |
---|
[1027] | 652 | for (int i = 0; i < nbSrvPools; ++i) |
---|
| 653 | { |
---|
| 654 | CContextClient* contextClientTmp = (0 != clientPrimServer.size()) ? clientPrimServer[i] : client; |
---|
| 655 | CEventClient event(getType(),EVENT_ID_POST_PROCESS_GLOBAL_ATTRIBUTES); |
---|
[987] | 656 | |
---|
[1027] | 657 | if (contextClientTmp->isServerLeader()) |
---|
| 658 | { |
---|
| 659 | CMessage msg; |
---|
[1099] | 660 | if (hasServer) |
---|
| 661 | msg<<this->getIdServer(i); |
---|
| 662 | else |
---|
| 663 | msg<<this->getIdServer(); |
---|
[1027] | 664 | const std::list<int>& ranks = contextClientTmp->getRanksServerLeader(); |
---|
| 665 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 666 | event.push(*itRank,1,msg); |
---|
| 667 | contextClientTmp->sendEvent(event); |
---|
| 668 | } |
---|
| 669 | else contextClientTmp->sendEvent(event); |
---|
[1025] | 670 | } |
---|
| 671 | } |
---|
[1622] | 672 | CATCH_DUMP_ATTR |
---|
[1025] | 673 | |
---|
| 674 | void CContext::recvPostProcessingGlobalAttributes(CEventServer& event) |
---|
[1622] | 675 | TRY |
---|
[1025] | 676 | { |
---|
| 677 | CBufferIn* buffer=event.subEvents.begin()->buffer; |
---|
| 678 | string id; |
---|
| 679 | *buffer>>id; |
---|
[1099] | 680 | get(id)->recvPostProcessingGlobalAttributes(*buffer); |
---|
[1025] | 681 | } |
---|
[1622] | 682 | CATCH |
---|
[1025] | 683 | |
---|
| 684 | void CContext::recvPostProcessingGlobalAttributes(CBufferIn& buffer) |
---|
[1622] | 685 | TRY |
---|
[1144] | 686 | { |
---|
[1025] | 687 | postProcessingGlobalAttributes(); |
---|
| 688 | } |
---|
[1622] | 689 | CATCH_DUMP_ATTR |
---|
[1025] | 690 | |
---|
| 691 | /*! |
---|
| 692 | \brief Close all the context defintion and do processing data |
---|
| 693 | After everything is well defined on client side, they will be processed and sent to server |
---|
| 694 | From the version 2.0, sever and client work no more on the same database. Moreover, client(s) will send |
---|
| 695 | all necessary information to server, from which each server can build its own database. |
---|
| 696 | Because the role of server is to write out field data on a specific netcdf file, |
---|
| 697 | the only information that it needs is the enabled files |
---|
| 698 | and the active fields (fields will be written onto active files) |
---|
| 699 | */ |
---|
[1622] | 700 | |
---|
[1025] | 701 | void CContext::closeDefinition(void) |
---|
[1622] | 702 | TRY |
---|
[1025] | 703 | { |
---|
[2428] | 704 | CMemChecker::logMem( "CContext::closeDefinition" ); |
---|
[1158] | 705 | CTimer::get("Context : close definition").resume() ; |
---|
[1025] | 706 | postProcessingGlobalAttributes(); |
---|
[983] | 707 | |
---|
[1130] | 708 | if (hasClient) sendPostProcessingGlobalAttributes(); |
---|
| 709 | |
---|
| 710 | // There are some processings that should be done after all of above. For example: check mask or index |
---|
[1025] | 711 | this->buildFilterGraphOfEnabledFields(); |
---|
| 712 | |
---|
[1130] | 713 | if (hasClient && !hasServer) |
---|
[509] | 714 | { |
---|
[1130] | 715 | buildFilterGraphOfFieldsWithReadAccess(); |
---|
[1358] | 716 | postProcessFilterGraph(); |
---|
[509] | 717 | } |
---|
[1144] | 718 | |
---|
[1232] | 719 | checkGridEnabledFields(); |
---|
[509] | 720 | |
---|
[1025] | 721 | if (hasClient) this->sendProcessingGridOfEnabledFields(); |
---|
[1077] | 722 | if (hasClient) this->sendCloseDefinition(); |
---|
[510] | 723 | |
---|
[584] | 724 | // Nettoyage de l'arborescence |
---|
[983] | 725 | if (hasClient) CleanTree(); // Only on client side?? |
---|
[510] | 726 | |
---|
[598] | 727 | if (hasClient) |
---|
| 728 | { |
---|
| 729 | sendCreateFileHeader(); |
---|
[983] | 730 | if (!hasServer) startPrefetchingOfEnabledReadModeFiles(); |
---|
[598] | 731 | } |
---|
[1158] | 732 | CTimer::get("Context : close definition").suspend() ; |
---|
[2428] | 733 | CMemChecker::logMem( "CContext::closeDefinition_END" ); |
---|
[300] | 734 | } |
---|
[1622] | 735 | CATCH_DUMP_ATTR |
---|
[509] | 736 | |
---|
[1232] | 737 | void CContext::findAllEnabledFieldsInFiles(const std::vector<CFile*>& activeFiles) |
---|
[1622] | 738 | TRY |
---|
[300] | 739 | { |
---|
[1232] | 740 | for (unsigned int i = 0; i < activeFiles.size(); i++) |
---|
| 741 | (void)activeFiles[i]->getEnabledFields(); |
---|
[300] | 742 | } |
---|
[1622] | 743 | CATCH_DUMP_ATTR |
---|
[300] | 744 | |
---|
[775] | 745 | void CContext::readAttributesOfEnabledFieldsInReadModeFiles() |
---|
[1622] | 746 | TRY |
---|
[775] | 747 | { |
---|
| 748 | for (unsigned int i = 0; i < this->enabledReadModeFiles.size(); ++i) |
---|
| 749 | (void)this->enabledReadModeFiles[i]->readAttributesOfEnabledFieldsInReadMode(); |
---|
| 750 | } |
---|
[1622] | 751 | CATCH_DUMP_ATTR |
---|
[775] | 752 | |
---|
[1239] | 753 | void CContext::sendGridComponentEnabledFieldsInFiles(const std::vector<CFile*>& activeFiles) |
---|
[1622] | 754 | TRY |
---|
[1239] | 755 | { |
---|
| 756 | int size = activeFiles.size(); |
---|
| 757 | for (int i = 0; i < size; ++i) |
---|
| 758 | { |
---|
| 759 | activeFiles[i]->sendGridComponentOfEnabledFields(); |
---|
| 760 | } |
---|
| 761 | } |
---|
[1622] | 762 | CATCH_DUMP_ATTR |
---|
[1239] | 763 | |
---|
[1232] | 764 | /*! |
---|
| 765 | Send active (enabled) fields in file from a client to others |
---|
| 766 | \param [in] activeFiles files contains enabled fields to send |
---|
| 767 | */ |
---|
| 768 | void CContext::sendGridEnabledFieldsInFiles(const std::vector<CFile*>& activeFiles) |
---|
[1622] | 769 | TRY |
---|
[1025] | 770 | { |
---|
[1232] | 771 | int size = activeFiles.size(); |
---|
[1025] | 772 | for (int i = 0; i < size; ++i) |
---|
[1099] | 773 | { |
---|
[1232] | 774 | activeFiles[i]->sendGridOfEnabledFields(); |
---|
[1025] | 775 | } |
---|
| 776 | } |
---|
[1622] | 777 | CATCH_DUMP_ATTR |
---|
[1025] | 778 | |
---|
[1099] | 779 | void CContext::checkGridEnabledFields() |
---|
[1622] | 780 | TRY |
---|
[1099] | 781 | { |
---|
[1232] | 782 | int size = enabledFiles.size(); |
---|
[1099] | 783 | for (int i = 0; i < size; ++i) |
---|
| 784 | { |
---|
[1232] | 785 | enabledFiles[i]->checkGridOfEnabledFields(); |
---|
[1099] | 786 | } |
---|
| 787 | } |
---|
[1622] | 788 | CATCH_DUMP_ATTR |
---|
[1025] | 789 | |
---|
[1232] | 790 | /*! |
---|
| 791 | Check grid of active (enabled) fields in file |
---|
| 792 | \param [in] activeFiles files contains enabled fields whose grid needs checking |
---|
| 793 | */ |
---|
| 794 | void CContext::checkGridEnabledFieldsInFiles(const std::vector<CFile*>& activeFiles) |
---|
[1622] | 795 | TRY |
---|
[1232] | 796 | { |
---|
| 797 | int size = activeFiles.size(); |
---|
| 798 | for (int i = 0; i < size; ++i) |
---|
| 799 | { |
---|
| 800 | activeFiles[i]->checkGridOfEnabledFields(); |
---|
| 801 | } |
---|
| 802 | } |
---|
[1622] | 803 | CATCH_DUMP_ATTR |
---|
[1232] | 804 | |
---|
| 805 | /*! |
---|
| 806 | Go up the hierachical tree via field_ref and do check of attributes of fields |
---|
| 807 | This can be done in a client then all computed information will be sent from this client to others |
---|
| 808 | \param [in] sendToServer Flag to indicate whether calculated information will be sent |
---|
| 809 | */ |
---|
[823] | 810 | void CContext::solveOnlyRefOfEnabledFields(bool sendToServer) |
---|
[1622] | 811 | TRY |
---|
[823] | 812 | { |
---|
| 813 | int size = this->enabledFiles.size(); |
---|
| 814 | for (int i = 0; i < size; ++i) |
---|
| 815 | { |
---|
| 816 | this->enabledFiles[i]->solveOnlyRefOfEnabledFields(sendToServer); |
---|
| 817 | } |
---|
| 818 | |
---|
| 819 | for (int i = 0; i < size; ++i) |
---|
| 820 | { |
---|
| 821 | this->enabledFiles[i]->generateNewTransformationGridDest(); |
---|
| 822 | } |
---|
| 823 | } |
---|
[1622] | 824 | CATCH_DUMP_ATTR |
---|
[823] | 825 | |
---|
[1232] | 826 | /*! |
---|
| 827 | Go up the hierachical tree via field_ref and do check of attributes of fields. |
---|
| 828 | The transformation can be done in this step. |
---|
| 829 | All computed information will be sent from this client to others. |
---|
| 830 | \param [in] sendToServer Flag to indicate whether calculated information will be sent |
---|
| 831 | */ |
---|
[1129] | 832 | void CContext::solveAllRefOfEnabledFieldsAndTransform(bool sendToServer) |
---|
[1622] | 833 | TRY |
---|
[300] | 834 | { |
---|
[509] | 835 | int size = this->enabledFiles.size(); |
---|
| 836 | for (int i = 0; i < size; ++i) |
---|
| 837 | { |
---|
[1129] | 838 | this->enabledFiles[i]->solveAllRefOfEnabledFieldsAndTransform(sendToServer); |
---|
[509] | 839 | } |
---|
[300] | 840 | } |
---|
[1622] | 841 | CATCH_DUMP_ATTR |
---|
[300] | 842 | |
---|
[640] | 843 | void CContext::buildFilterGraphOfEnabledFields() |
---|
[1622] | 844 | TRY |
---|
[640] | 845 | { |
---|
| 846 | int size = this->enabledFiles.size(); |
---|
| 847 | for (int i = 0; i < size; ++i) |
---|
| 848 | { |
---|
| 849 | this->enabledFiles[i]->buildFilterGraphOfEnabledFields(garbageCollector); |
---|
| 850 | } |
---|
| 851 | } |
---|
[1622] | 852 | CATCH_DUMP_ATTR |
---|
[640] | 853 | |
---|
[1358] | 854 | void CContext::postProcessFilterGraph() |
---|
[1622] | 855 | TRY |
---|
[1358] | 856 | { |
---|
| 857 | int size = enabledFiles.size(); |
---|
| 858 | for (int i = 0; i < size; ++i) |
---|
| 859 | { |
---|
| 860 | enabledFiles[i]->postProcessFilterGraph(); |
---|
| 861 | } |
---|
| 862 | } |
---|
[1622] | 863 | CATCH_DUMP_ATTR |
---|
[1358] | 864 | |
---|
[598] | 865 | void CContext::startPrefetchingOfEnabledReadModeFiles() |
---|
[1622] | 866 | TRY |
---|
[598] | 867 | { |
---|
| 868 | int size = enabledReadModeFiles.size(); |
---|
| 869 | for (int i = 0; i < size; ++i) |
---|
| 870 | { |
---|
| 871 | enabledReadModeFiles[i]->prefetchEnabledReadModeFields(); |
---|
| 872 | } |
---|
| 873 | } |
---|
[1622] | 874 | CATCH_DUMP_ATTR |
---|
[598] | 875 | |
---|
[1358] | 876 | void CContext::doPreTimestepOperationsForEnabledReadModeFiles() |
---|
[1622] | 877 | TRY |
---|
[1358] | 878 | { |
---|
| 879 | int size = enabledReadModeFiles.size(); |
---|
| 880 | for (int i = 0; i < size; ++i) |
---|
| 881 | { |
---|
| 882 | enabledReadModeFiles[i]->doPreTimestepOperationsForEnabledReadModeFields(); |
---|
| 883 | } |
---|
| 884 | } |
---|
[1622] | 885 | CATCH_DUMP_ATTR |
---|
[1358] | 886 | |
---|
[1318] | 887 | void CContext::doPostTimestepOperationsForEnabledReadModeFiles() |
---|
[1622] | 888 | TRY |
---|
[598] | 889 | { |
---|
| 890 | int size = enabledReadModeFiles.size(); |
---|
| 891 | for (int i = 0; i < size; ++i) |
---|
| 892 | { |
---|
[1318] | 893 | enabledReadModeFiles[i]->doPostTimestepOperationsForEnabledReadModeFields(); |
---|
[598] | 894 | } |
---|
| 895 | } |
---|
[1622] | 896 | CATCH_DUMP_ATTR |
---|
[598] | 897 | |
---|
[593] | 898 | void CContext::findFieldsWithReadAccess(void) |
---|
[1622] | 899 | TRY |
---|
[593] | 900 | { |
---|
| 901 | fieldsWithReadAccess.clear(); |
---|
| 902 | const vector<CField*> allFields = CField::getAll(); |
---|
| 903 | for (size_t i = 0; i < allFields.size(); ++i) |
---|
| 904 | { |
---|
[740] | 905 | CField* field = allFields[i]; |
---|
| 906 | |
---|
| 907 | if (field->file && !field->file->mode.isEmpty() && field->file->mode == CFile::mode_attr::read) |
---|
| 908 | field->read_access = true; |
---|
| 909 | else if (!field->read_access.isEmpty() && field->read_access && (field->enabled.isEmpty() || field->enabled)) |
---|
| 910 | fieldsWithReadAccess.push_back(field); |
---|
[593] | 911 | } |
---|
| 912 | } |
---|
[1622] | 913 | CATCH_DUMP_ATTR |
---|
[593] | 914 | |
---|
| 915 | void CContext::solveAllRefOfFieldsWithReadAccess() |
---|
[1622] | 916 | TRY |
---|
[593] | 917 | { |
---|
| 918 | for (size_t i = 0; i < fieldsWithReadAccess.size(); ++i) |
---|
| 919 | fieldsWithReadAccess[i]->solveAllReferenceEnabledField(false); |
---|
| 920 | } |
---|
[1622] | 921 | CATCH_DUMP_ATTR |
---|
[593] | 922 | |
---|
[640] | 923 | void CContext::buildFilterGraphOfFieldsWithReadAccess() |
---|
[1622] | 924 | TRY |
---|
[640] | 925 | { |
---|
| 926 | for (size_t i = 0; i < fieldsWithReadAccess.size(); ++i) |
---|
| 927 | fieldsWithReadAccess[i]->buildFilterGraph(garbageCollector, true); |
---|
| 928 | } |
---|
[1622] | 929 | CATCH_DUMP_ATTR |
---|
[640] | 930 | |
---|
[445] | 931 | void CContext::solveAllInheritance(bool apply) |
---|
[1622] | 932 | TRY |
---|
[300] | 933 | { |
---|
| 934 | // Résolution des héritages descendants (cà d des héritages de groupes) |
---|
| 935 | // pour chacun des contextes. |
---|
[445] | 936 | solveDescInheritance(apply); |
---|
[300] | 937 | |
---|
| 938 | // Résolution des héritages par référence au niveau des fichiers. |
---|
[549] | 939 | const vector<CFile*> allFiles=CFile::getAll(); |
---|
[540] | 940 | const vector<CGrid*> allGrids= CGrid::getAll(); |
---|
[300] | 941 | |
---|
[983] | 942 | if (hasClient && !hasServer) |
---|
| 943 | //if (hasClient) |
---|
[540] | 944 | { |
---|
[510] | 945 | for (unsigned int i = 0; i < allFiles.size(); i++) |
---|
| 946 | allFiles[i]->solveFieldRefInheritance(apply); |
---|
[540] | 947 | } |
---|
| 948 | |
---|
| 949 | unsigned int vecSize = allGrids.size(); |
---|
| 950 | unsigned int i = 0; |
---|
| 951 | for (i = 0; i < vecSize; ++i) |
---|
| 952 | allGrids[i]->solveDomainAxisRefInheritance(apply); |
---|
| 953 | |
---|
[300] | 954 | } |
---|
[1622] | 955 | CATCH_DUMP_ATTR |
---|
[300] | 956 | |
---|
| 957 | void CContext::findEnabledFiles(void) |
---|
[1622] | 958 | TRY |
---|
[300] | 959 | { |
---|
[347] | 960 | const std::vector<CFile*> allFiles = CFile::getAll(); |
---|
[1158] | 961 | const CDate& initDate = calendar->getInitDate(); |
---|
[300] | 962 | |
---|
| 963 | for (unsigned int i = 0; i < allFiles.size(); i++) |
---|
| 964 | if (!allFiles[i]->enabled.isEmpty()) // Si l'attribut 'enabled' est défini. |
---|
[430] | 965 | { |
---|
[300] | 966 | if (allFiles[i]->enabled.getValue()) // Si l'attribut 'enabled' est fixé à vrai. |
---|
[1158] | 967 | { |
---|
[1489] | 968 | if (allFiles[i]->output_freq.isEmpty()) |
---|
[1488] | 969 | { |
---|
| 970 | ERROR("CContext::findEnabledFiles()", |
---|
| 971 | << "Mandatory attribute output_freq must be defined for file \""<<allFiles[i]->getFileOutputName() |
---|
| 972 | <<" \".") |
---|
| 973 | } |
---|
[1158] | 974 | if ((initDate + allFiles[i]->output_freq.getValue()) < (initDate + this->getCalendar()->getTimeStep())) |
---|
| 975 | { |
---|
| 976 | error(0)<<"WARNING: void CContext::findEnabledFiles()"<<endl |
---|
| 977 | << "Output frequency in file \""<<allFiles[i]->getFileOutputName() |
---|
| 978 | <<"\" is less than the time step. File will not be written."<<endl; |
---|
| 979 | } |
---|
| 980 | else |
---|
[300] | 981 | enabledFiles.push_back(allFiles[i]); |
---|
[1158] | 982 | } |
---|
[430] | 983 | } |
---|
[1158] | 984 | else |
---|
| 985 | { |
---|
[1489] | 986 | if (allFiles[i]->output_freq.isEmpty()) |
---|
[1488] | 987 | { |
---|
| 988 | ERROR("CContext::findEnabledFiles()", |
---|
| 989 | << "Mandatory attribute output_freq must be defined for file \""<<allFiles[i]->getFileOutputName() |
---|
| 990 | <<" \".") |
---|
| 991 | } |
---|
[1158] | 992 | if ( (initDate + allFiles[i]->output_freq.getValue()) < (initDate + this->getCalendar()->getTimeStep())) |
---|
| 993 | { |
---|
| 994 | error(0)<<"WARNING: void CContext::findEnabledFiles()"<<endl |
---|
| 995 | << "Output frequency in file \""<<allFiles[i]->getFileOutputName() |
---|
| 996 | <<"\" is less than the time step. File will not be written."<<endl; |
---|
| 997 | } |
---|
| 998 | else |
---|
| 999 | enabledFiles.push_back(allFiles[i]); // otherwise true by default |
---|
| 1000 | } |
---|
[300] | 1001 | |
---|
| 1002 | if (enabledFiles.size() == 0) |
---|
| 1003 | DEBUG(<<"Aucun fichier ne va être sorti dans le contexte nommé \"" |
---|
| 1004 | << getId() << "\" !"); |
---|
[1021] | 1005 | |
---|
[300] | 1006 | } |
---|
[1622] | 1007 | CATCH_DUMP_ATTR |
---|
[300] | 1008 | |
---|
[1208] | 1009 | void CContext::distributeFiles(void) |
---|
[1622] | 1010 | TRY |
---|
[1208] | 1011 | { |
---|
[1349] | 1012 | bool distFileMemory=false ; |
---|
| 1013 | distFileMemory=CXios::getin<bool>("server2_dist_file_memory", distFileMemory); |
---|
| 1014 | |
---|
| 1015 | if (distFileMemory) distributeFileOverMemoryBandwith() ; |
---|
| 1016 | else distributeFileOverBandwith() ; |
---|
| 1017 | } |
---|
[1622] | 1018 | CATCH_DUMP_ATTR |
---|
[1349] | 1019 | |
---|
| 1020 | void CContext::distributeFileOverBandwith(void) |
---|
[1622] | 1021 | TRY |
---|
[1349] | 1022 | { |
---|
[1215] | 1023 | double eps=std::numeric_limits<double>::epsilon()*10 ; |
---|
| 1024 | |
---|
[1208] | 1025 | // If primary server |
---|
| 1026 | if (hasServer && hasClient) |
---|
| 1027 | { |
---|
[1349] | 1028 | std::ofstream ofs(("distribute_file_"+getId()+".dat").c_str(), std::ofstream::out); |
---|
[1212] | 1029 | int nbPools = clientPrimServer.size(); |
---|
| 1030 | |
---|
[1208] | 1031 | // (1) Find all enabled files in write mode |
---|
[1232] | 1032 | // for (int i = 0; i < this->enabledFiles.size(); ++i) |
---|
| 1033 | // { |
---|
| 1034 | // if (enabledFiles[i]->mode.isEmpty() || (!enabledFiles[i]->mode.isEmpty() && enabledFiles[i]->mode.getValue() == CFile::mode_attr::write )) |
---|
| 1035 | // enabledWriteModeFiles.push_back(enabledFiles[i]); |
---|
| 1036 | // } |
---|
[1208] | 1037 | |
---|
| 1038 | // (2) Estimate the data volume for each file |
---|
| 1039 | int size = this->enabledWriteModeFiles.size(); |
---|
[1215] | 1040 | std::vector<std::pair<double, CFile*> > dataSizeMap; |
---|
| 1041 | double dataPerPool = 0; |
---|
| 1042 | int nfield=0 ; |
---|
[1349] | 1043 | ofs<<size<<endl ; |
---|
[1208] | 1044 | for (size_t i = 0; i < size; ++i) |
---|
| 1045 | { |
---|
| 1046 | CFile* file = this->enabledWriteModeFiles[i]; |
---|
[1349] | 1047 | ofs<<file->getId()<<endl ; |
---|
[1215] | 1048 | StdSize dataSize=0; |
---|
[1208] | 1049 | std::vector<CField*> enabledFields = file->getEnabledFields(); |
---|
| 1050 | size_t numEnabledFields = enabledFields.size(); |
---|
[1349] | 1051 | ofs<<numEnabledFields<<endl ; |
---|
| 1052 | for (size_t j = 0; j < numEnabledFields; ++j) |
---|
| 1053 | { |
---|
| 1054 | dataSize += enabledFields[j]->getGlobalWrittenSize() ; |
---|
| 1055 | ofs<<enabledFields[j]->grid->getId()<<endl ; |
---|
| 1056 | ofs<<enabledFields[j]->getGlobalWrittenSize()<<endl ; |
---|
| 1057 | } |
---|
[1215] | 1058 | double outFreqSec = (Time)(calendar->getCurrentDate()+file->output_freq)-(Time)(calendar->getCurrentDate()) ; |
---|
| 1059 | double dataSizeSec= dataSize/ outFreqSec; |
---|
[1349] | 1060 | ofs<<dataSizeSec<<endl ; |
---|
[1215] | 1061 | nfield++ ; |
---|
| 1062 | // add epsilon*nField to dataSizeSec in order to preserve reproductive ordering when sorting |
---|
| 1063 | dataSizeMap.push_back(make_pair(dataSizeSec + dataSizeSec * eps * nfield , file)); |
---|
| 1064 | dataPerPool += dataSizeSec; |
---|
[1208] | 1065 | } |
---|
[1212] | 1066 | dataPerPool /= nbPools; |
---|
[1208] | 1067 | std::sort(dataSizeMap.begin(), dataSizeMap.end()); |
---|
| 1068 | |
---|
[1212] | 1069 | // (3) Assign contextClient to each enabled file |
---|
[1215] | 1070 | |
---|
| 1071 | std::multimap<double,int> poolDataSize ; |
---|
| 1072 | // multimap is not garanty to preserve stable sorting in c++98 but it seems it does for c++11 |
---|
| 1073 | |
---|
| 1074 | int j; |
---|
| 1075 | double dataSize ; |
---|
| 1076 | for (j = 0 ; j < nbPools ; ++j) poolDataSize.insert(std::pair<double,int>(0.,j)) ; |
---|
| 1077 | |
---|
[1212] | 1078 | for (int i = dataSizeMap.size()-1; i >= 0; --i) |
---|
[1208] | 1079 | { |
---|
[1215] | 1080 | dataSize=(*poolDataSize.begin()).first ; |
---|
| 1081 | j=(*poolDataSize.begin()).second ; |
---|
| 1082 | dataSizeMap[i].second->setContextClient(clientPrimServer[j]); |
---|
| 1083 | dataSize+=dataSizeMap[i].first; |
---|
| 1084 | poolDataSize.erase(poolDataSize.begin()) ; |
---|
| 1085 | poolDataSize.insert(std::pair<double,int>(dataSize,j)) ; |
---|
[1208] | 1086 | } |
---|
[1212] | 1087 | |
---|
[1215] | 1088 | for (std::multimap<double,int>:: iterator it=poolDataSize.begin() ; it!=poolDataSize.end(); ++it) info(30)<<"Load Balancing for servers (perfect=1) : "<<it->second<<" : ratio "<<it->first*1./dataPerPool<<endl ; |
---|
| 1089 | |
---|
[1212] | 1090 | for (int i = 0; i < this->enabledReadModeFiles.size(); ++i) |
---|
[1232] | 1091 | { |
---|
| 1092 | enabledReadModeFiles[i]->setContextClient(client); |
---|
| 1093 | } |
---|
[1208] | 1094 | } |
---|
| 1095 | else |
---|
| 1096 | { |
---|
| 1097 | for (int i = 0; i < this->enabledFiles.size(); ++i) |
---|
| 1098 | enabledFiles[i]->setContextClient(client); |
---|
| 1099 | } |
---|
| 1100 | } |
---|
[1622] | 1101 | CATCH_DUMP_ATTR |
---|
[1208] | 1102 | |
---|
[1349] | 1103 | void CContext::distributeFileOverMemoryBandwith(void) |
---|
[1622] | 1104 | TRY |
---|
[1349] | 1105 | { |
---|
| 1106 | // If primary server |
---|
| 1107 | if (hasServer && hasClient) |
---|
| 1108 | { |
---|
| 1109 | int nbPools = clientPrimServer.size(); |
---|
| 1110 | double ratio=0.5 ; |
---|
| 1111 | ratio=CXios::getin<double>("server2_dist_file_memory_ratio", ratio); |
---|
| 1112 | |
---|
| 1113 | int nFiles = this->enabledWriteModeFiles.size(); |
---|
| 1114 | vector<SDistFile> files(nFiles); |
---|
| 1115 | vector<SDistGrid> grids; |
---|
| 1116 | map<string,int> gridMap ; |
---|
| 1117 | string gridId; |
---|
| 1118 | int gridIndex=0 ; |
---|
| 1119 | |
---|
| 1120 | for (size_t i = 0; i < nFiles; ++i) |
---|
| 1121 | { |
---|
| 1122 | StdSize dataSize=0; |
---|
| 1123 | CFile* file = this->enabledWriteModeFiles[i]; |
---|
| 1124 | std::vector<CField*> enabledFields = file->getEnabledFields(); |
---|
| 1125 | size_t numEnabledFields = enabledFields.size(); |
---|
| 1126 | |
---|
| 1127 | files[i].id_=file->getId() ; |
---|
| 1128 | files[i].nbGrids_=numEnabledFields; |
---|
| 1129 | files[i].assignedGrid_ = new int[files[i].nbGrids_] ; |
---|
| 1130 | |
---|
| 1131 | for (size_t j = 0; j < numEnabledFields; ++j) |
---|
| 1132 | { |
---|
| 1133 | gridId=enabledFields[j]->grid->getId() ; |
---|
| 1134 | if (gridMap.find(gridId)==gridMap.end()) |
---|
| 1135 | { |
---|
| 1136 | gridMap[gridId]=gridIndex ; |
---|
| 1137 | SDistGrid newGrid; |
---|
| 1138 | grids.push_back(newGrid) ; |
---|
| 1139 | gridIndex++ ; |
---|
| 1140 | } |
---|
| 1141 | files[i].assignedGrid_[j]=gridMap[gridId] ; |
---|
| 1142 | grids[files[i].assignedGrid_[j]].size_=enabledFields[j]->getGlobalWrittenSize() ; |
---|
| 1143 | dataSize += enabledFields[j]->getGlobalWrittenSize() ; // usefull |
---|
| 1144 | } |
---|
| 1145 | double outFreqSec = (Time)(calendar->getCurrentDate()+file->output_freq)-(Time)(calendar->getCurrentDate()) ; |
---|
| 1146 | files[i].bandwith_= dataSize/ outFreqSec ; |
---|
| 1147 | } |
---|
| 1148 | |
---|
| 1149 | double bandwith=0 ; |
---|
| 1150 | double memory=0 ; |
---|
| 1151 | |
---|
| 1152 | for(int i=0; i<nFiles; i++) bandwith+=files[i].bandwith_ ; |
---|
| 1153 | for(int i=0; i<nFiles; i++) files[i].bandwith_ = files[i].bandwith_/bandwith * ratio ; |
---|
| 1154 | |
---|
| 1155 | for(int i=0; i<grids.size(); i++) memory+=grids[i].size_ ; |
---|
| 1156 | for(int i=0; i<grids.size(); i++) grids[i].size_ = grids[i].size_ / memory * (1.0-ratio) ; |
---|
| 1157 | |
---|
| 1158 | distributeFileOverServer2(nbPools, grids.size(), &grids[0], nFiles, &files[0]) ; |
---|
| 1159 | |
---|
| 1160 | vector<double> memorySize(nbPools,0.) ; |
---|
| 1161 | vector< set<int> > serverGrids(nbPools) ; |
---|
| 1162 | vector<double> bandwithSize(nbPools,0.) ; |
---|
| 1163 | |
---|
| 1164 | for (size_t i = 0; i < nFiles; ++i) |
---|
| 1165 | { |
---|
| 1166 | bandwithSize[files[i].assignedServer_] += files[i].bandwith_* bandwith /ratio ; |
---|
| 1167 | for(int j=0 ; j<files[i].nbGrids_;j++) |
---|
| 1168 | { |
---|
| 1169 | if (serverGrids[files[i].assignedServer_].find(files[i].assignedGrid_[j]) == serverGrids[files[i].assignedServer_].end()) |
---|
| 1170 | { |
---|
| 1171 | memorySize[files[i].assignedServer_]+= grids[files[i].assignedGrid_[j]].size_ * memory / (1.0-ratio); |
---|
| 1172 | serverGrids[files[i].assignedServer_].insert(files[i].assignedGrid_[j]) ; |
---|
| 1173 | } |
---|
| 1174 | } |
---|
| 1175 | enabledWriteModeFiles[i]->setContextClient(clientPrimServer[files[i].assignedServer_]) ; |
---|
| 1176 | delete [] files[i].assignedGrid_ ; |
---|
| 1177 | } |
---|
| 1178 | |
---|
| 1179 | for (int i = 0; i < nbPools; ++i) info(100)<<"Pool server level2 "<<i<<" assigned file bandwith "<<bandwithSize[i]*86400.*4./1024/1024.<<" Mb / days"<<endl ; |
---|
| 1180 | for (int i = 0; i < nbPools; ++i) info(100)<<"Pool server level2 "<<i<<" assigned grid memory "<<memorySize[i]*100/1024./1024.<<" Mb"<<endl ; |
---|
| 1181 | |
---|
| 1182 | |
---|
| 1183 | for (int i = 0; i < this->enabledReadModeFiles.size(); ++i) |
---|
| 1184 | { |
---|
| 1185 | enabledReadModeFiles[i]->setContextClient(client); |
---|
| 1186 | } |
---|
| 1187 | |
---|
| 1188 | } |
---|
| 1189 | else |
---|
| 1190 | { |
---|
| 1191 | for (int i = 0; i < this->enabledFiles.size(); ++i) |
---|
| 1192 | enabledFiles[i]->setContextClient(client); |
---|
| 1193 | } |
---|
| 1194 | } |
---|
[1622] | 1195 | CATCH_DUMP_ATTR |
---|
[1349] | 1196 | |
---|
[1232] | 1197 | /*! |
---|
| 1198 | Find all files in write mode |
---|
| 1199 | */ |
---|
| 1200 | void CContext::findEnabledWriteModeFiles(void) |
---|
[1622] | 1201 | TRY |
---|
[1232] | 1202 | { |
---|
| 1203 | int size = this->enabledFiles.size(); |
---|
| 1204 | for (int i = 0; i < size; ++i) |
---|
| 1205 | { |
---|
| 1206 | if (enabledFiles[i]->mode.isEmpty() || |
---|
| 1207 | (!enabledFiles[i]->mode.isEmpty() && enabledFiles[i]->mode.getValue() == CFile::mode_attr::write )) |
---|
| 1208 | enabledWriteModeFiles.push_back(enabledFiles[i]); |
---|
| 1209 | } |
---|
| 1210 | } |
---|
[1622] | 1211 | CATCH_DUMP_ATTR |
---|
[1232] | 1212 | |
---|
| 1213 | /*! |
---|
| 1214 | Find all files in read mode |
---|
| 1215 | */ |
---|
[598] | 1216 | void CContext::findEnabledReadModeFiles(void) |
---|
[1622] | 1217 | TRY |
---|
[598] | 1218 | { |
---|
| 1219 | int size = this->enabledFiles.size(); |
---|
| 1220 | for (int i = 0; i < size; ++i) |
---|
| 1221 | { |
---|
| 1222 | if (!enabledFiles[i]->mode.isEmpty() && enabledFiles[i]->mode.getValue() == CFile::mode_attr::read) |
---|
| 1223 | enabledReadModeFiles.push_back(enabledFiles[i]); |
---|
| 1224 | } |
---|
| 1225 | } |
---|
[1622] | 1226 | CATCH_DUMP_ATTR |
---|
[598] | 1227 | |
---|
[300] | 1228 | void CContext::closeAllFile(void) |
---|
[1622] | 1229 | TRY |
---|
[300] | 1230 | { |
---|
[347] | 1231 | std::vector<CFile*>::const_iterator |
---|
[300] | 1232 | it = this->enabledFiles.begin(), end = this->enabledFiles.end(); |
---|
[509] | 1233 | |
---|
[300] | 1234 | for (; it != end; it++) |
---|
| 1235 | { |
---|
| 1236 | info(30)<<"Closing File : "<<(*it)->getId()<<endl; |
---|
| 1237 | (*it)->close(); |
---|
| 1238 | } |
---|
| 1239 | } |
---|
[1622] | 1240 | CATCH_DUMP_ATTR |
---|
[509] | 1241 | |
---|
| 1242 | /*! |
---|
| 1243 | \brief Dispatch event received from client |
---|
| 1244 | Whenever a message is received in buffer of server, it will be processed depending on |
---|
| 1245 | its event type. A new event type should be added in the switch list to make sure |
---|
| 1246 | it processed on server side. |
---|
| 1247 | \param [in] event: Received message |
---|
| 1248 | */ |
---|
[300] | 1249 | bool CContext::dispatchEvent(CEventServer& event) |
---|
[1622] | 1250 | TRY |
---|
[300] | 1251 | { |
---|
[509] | 1252 | |
---|
[549] | 1253 | if (SuperClass::dispatchEvent(event)) return true; |
---|
[300] | 1254 | else |
---|
| 1255 | { |
---|
| 1256 | switch(event.type) |
---|
| 1257 | { |
---|
| 1258 | case EVENT_ID_CLOSE_DEFINITION : |
---|
[549] | 1259 | recvCloseDefinition(event); |
---|
| 1260 | return true; |
---|
| 1261 | break; |
---|
[584] | 1262 | case EVENT_ID_UPDATE_CALENDAR: |
---|
[549] | 1263 | recvUpdateCalendar(event); |
---|
| 1264 | return true; |
---|
| 1265 | break; |
---|
[300] | 1266 | case EVENT_ID_CREATE_FILE_HEADER : |
---|
[549] | 1267 | recvCreateFileHeader(event); |
---|
| 1268 | return true; |
---|
| 1269 | break; |
---|
[509] | 1270 | case EVENT_ID_POST_PROCESS: |
---|
[549] | 1271 | recvPostProcessing(event); |
---|
| 1272 | return true; |
---|
[697] | 1273 | case EVENT_ID_SEND_REGISTRY: |
---|
| 1274 | recvRegistry(event); |
---|
| 1275 | return true; |
---|
[1025] | 1276 | break; |
---|
| 1277 | case EVENT_ID_POST_PROCESS_GLOBAL_ATTRIBUTES: |
---|
| 1278 | recvPostProcessingGlobalAttributes(event); |
---|
| 1279 | return true; |
---|
| 1280 | break; |
---|
| 1281 | case EVENT_ID_PROCESS_GRID_ENABLED_FIELDS: |
---|
| 1282 | recvProcessingGridOfEnabledFields(event); |
---|
| 1283 | return true; |
---|
| 1284 | break; |
---|
[300] | 1285 | default : |
---|
| 1286 | ERROR("bool CContext::dispatchEvent(CEventServer& event)", |
---|
[549] | 1287 | <<"Unknown Event"); |
---|
| 1288 | return false; |
---|
[300] | 1289 | } |
---|
| 1290 | } |
---|
| 1291 | } |
---|
[1622] | 1292 | CATCH |
---|
[509] | 1293 | |
---|
| 1294 | //! Client side: Send a message to server to make it close |
---|
[300] | 1295 | void CContext::sendCloseDefinition(void) |
---|
[1622] | 1296 | TRY |
---|
[300] | 1297 | { |
---|
[987] | 1298 | // Use correct context client to send message |
---|
[1030] | 1299 | int nbSrvPools = (this->hasServer) ? (this->hasClient ? this->clientPrimServer.size() : 0) : 1; |
---|
[1009] | 1300 | for (int i = 0; i < nbSrvPools; ++i) |
---|
[300] | 1301 | { |
---|
[1009] | 1302 | CContextClient* contextClientTmp = (hasServer) ? clientPrimServer[i] : client; |
---|
| 1303 | CEventClient event(getType(),EVENT_ID_CLOSE_DEFINITION); |
---|
| 1304 | if (contextClientTmp->isServerLeader()) |
---|
| 1305 | { |
---|
| 1306 | CMessage msg; |
---|
| 1307 | if (hasServer) |
---|
| 1308 | msg<<this->getIdServer(i); |
---|
| 1309 | else |
---|
| 1310 | msg<<this->getIdServer(); |
---|
| 1311 | const std::list<int>& ranks = contextClientTmp->getRanksServerLeader(); |
---|
| 1312 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 1313 | event.push(*itRank,1,msg); |
---|
| 1314 | contextClientTmp->sendEvent(event); |
---|
| 1315 | } |
---|
| 1316 | else contextClientTmp->sendEvent(event); |
---|
[300] | 1317 | } |
---|
| 1318 | } |
---|
[1622] | 1319 | CATCH_DUMP_ATTR |
---|
[509] | 1320 | |
---|
| 1321 | //! Server side: Receive a message of client announcing a context close |
---|
[300] | 1322 | void CContext::recvCloseDefinition(CEventServer& event) |
---|
[1622] | 1323 | TRY |
---|
[300] | 1324 | { |
---|
| 1325 | CBufferIn* buffer=event.subEvents.begin()->buffer; |
---|
| 1326 | string id; |
---|
[549] | 1327 | *buffer>>id; |
---|
[509] | 1328 | get(id)->closeDefinition(); |
---|
[300] | 1329 | } |
---|
[1622] | 1330 | CATCH |
---|
[509] | 1331 | |
---|
| 1332 | //! Client side: Send a message to update calendar in each time step |
---|
[300] | 1333 | void CContext::sendUpdateCalendar(int step) |
---|
[1622] | 1334 | TRY |
---|
[300] | 1335 | { |
---|
[987] | 1336 | // Use correct context client to send message |
---|
[1030] | 1337 | int nbSrvPools = (this->hasServer) ? (this->hasClient ? this->clientPrimServer.size() : 0) : 1; |
---|
[1009] | 1338 | for (int i = 0; i < nbSrvPools; ++i) |
---|
| 1339 | { |
---|
| 1340 | CContextClient* contextClientTmp = (hasServer) ? clientPrimServer[i] : client; |
---|
| 1341 | CEventClient event(getType(),EVENT_ID_UPDATE_CALENDAR); |
---|
[987] | 1342 | |
---|
[1009] | 1343 | if (contextClientTmp->isServerLeader()) |
---|
| 1344 | { |
---|
| 1345 | CMessage msg; |
---|
| 1346 | if (hasServer) |
---|
| 1347 | msg<<this->getIdServer(i)<<step; |
---|
| 1348 | else |
---|
| 1349 | msg<<this->getIdServer()<<step; |
---|
| 1350 | const std::list<int>& ranks = contextClientTmp->getRanksServerLeader(); |
---|
| 1351 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 1352 | event.push(*itRank,1,msg); |
---|
| 1353 | contextClientTmp->sendEvent(event); |
---|
| 1354 | } |
---|
| 1355 | else contextClientTmp->sendEvent(event); |
---|
| 1356 | } |
---|
[300] | 1357 | } |
---|
[1622] | 1358 | CATCH_DUMP_ATTR |
---|
[509] | 1359 | |
---|
| 1360 | //! Server side: Receive a message of client annoucing calendar update |
---|
[300] | 1361 | void CContext::recvUpdateCalendar(CEventServer& event) |
---|
[1622] | 1362 | TRY |
---|
[300] | 1363 | { |
---|
| 1364 | CBufferIn* buffer=event.subEvents.begin()->buffer; |
---|
| 1365 | string id; |
---|
[549] | 1366 | *buffer>>id; |
---|
| 1367 | get(id)->recvUpdateCalendar(*buffer); |
---|
[300] | 1368 | } |
---|
[1622] | 1369 | CATCH |
---|
[509] | 1370 | |
---|
| 1371 | //! Server side: Receive a message of client annoucing calendar update |
---|
[300] | 1372 | void CContext::recvUpdateCalendar(CBufferIn& buffer) |
---|
[1622] | 1373 | TRY |
---|
[300] | 1374 | { |
---|
[549] | 1375 | int step; |
---|
| 1376 | buffer>>step; |
---|
| 1377 | updateCalendar(step); |
---|
[987] | 1378 | if (hasClient && hasServer) |
---|
| 1379 | { |
---|
| 1380 | sendUpdateCalendar(step); |
---|
| 1381 | } |
---|
[300] | 1382 | } |
---|
[1622] | 1383 | CATCH_DUMP_ATTR |
---|
[509] | 1384 | |
---|
| 1385 | //! Client side: Send a message to create header part of netcdf file |
---|
[300] | 1386 | void CContext::sendCreateFileHeader(void) |
---|
[1622] | 1387 | TRY |
---|
[300] | 1388 | { |
---|
[987] | 1389 | // Use correct context client to send message |
---|
[1030] | 1390 | // int nbSrvPools = (hasServer) ? clientPrimServer.size() : 1; |
---|
| 1391 | int nbSrvPools = (this->hasServer) ? (this->hasClient ? this->clientPrimServer.size() : 0) : 1; |
---|
[1009] | 1392 | for (int i = 0; i < nbSrvPools; ++i) |
---|
| 1393 | { |
---|
| 1394 | CContextClient* contextClientTmp = (hasServer) ? clientPrimServer[i] : client; |
---|
| 1395 | CEventClient event(getType(),EVENT_ID_CREATE_FILE_HEADER); |
---|
[983] | 1396 | |
---|
[1009] | 1397 | if (contextClientTmp->isServerLeader()) |
---|
| 1398 | { |
---|
| 1399 | CMessage msg; |
---|
| 1400 | if (hasServer) |
---|
| 1401 | msg<<this->getIdServer(i); |
---|
| 1402 | else |
---|
| 1403 | msg<<this->getIdServer(); |
---|
| 1404 | const std::list<int>& ranks = contextClientTmp->getRanksServerLeader(); |
---|
| 1405 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 1406 | event.push(*itRank,1,msg) ; |
---|
| 1407 | contextClientTmp->sendEvent(event); |
---|
| 1408 | } |
---|
| 1409 | else contextClientTmp->sendEvent(event); |
---|
[300] | 1410 | } |
---|
| 1411 | } |
---|
[1622] | 1412 | CATCH_DUMP_ATTR |
---|
[509] | 1413 | |
---|
| 1414 | //! Server side: Receive a message of client annoucing the creation of header part of netcdf file |
---|
[300] | 1415 | void CContext::recvCreateFileHeader(CEventServer& event) |
---|
[1622] | 1416 | TRY |
---|
[300] | 1417 | { |
---|
| 1418 | CBufferIn* buffer=event.subEvents.begin()->buffer; |
---|
| 1419 | string id; |
---|
[549] | 1420 | *buffer>>id; |
---|
| 1421 | get(id)->recvCreateFileHeader(*buffer); |
---|
[300] | 1422 | } |
---|
[1622] | 1423 | CATCH |
---|
[509] | 1424 | |
---|
| 1425 | //! Server side: Receive a message of client annoucing the creation of header part of netcdf file |
---|
[300] | 1426 | void CContext::recvCreateFileHeader(CBufferIn& buffer) |
---|
[1622] | 1427 | TRY |
---|
[300] | 1428 | { |
---|
[2253] | 1429 | createFileHeader(); |
---|
[300] | 1430 | } |
---|
[1622] | 1431 | CATCH_DUMP_ATTR |
---|
[509] | 1432 | |
---|
| 1433 | //! Client side: Send a message to do some post processing on server |
---|
[1025] | 1434 | void CContext::sendProcessingGridOfEnabledFields() |
---|
[1622] | 1435 | TRY |
---|
[1025] | 1436 | { |
---|
| 1437 | // Use correct context client to send message |
---|
[1030] | 1438 | int nbSrvPools = (this->hasServer) ? (this->hasClient ? this->clientPrimServer.size() : 0) : 1; |
---|
[1027] | 1439 | for (int i = 0; i < nbSrvPools; ++i) |
---|
| 1440 | { |
---|
| 1441 | CContextClient* contextClientTmp = (0 != clientPrimServer.size()) ? clientPrimServer[i] : client; |
---|
| 1442 | CEventClient event(getType(),EVENT_ID_PROCESS_GRID_ENABLED_FIELDS); |
---|
[1025] | 1443 | |
---|
[1027] | 1444 | if (contextClientTmp->isServerLeader()) |
---|
| 1445 | { |
---|
| 1446 | CMessage msg; |
---|
[1099] | 1447 | if (hasServer) |
---|
| 1448 | msg<<this->getIdServer(i); |
---|
| 1449 | else |
---|
| 1450 | msg<<this->getIdServer(); |
---|
[1027] | 1451 | const std::list<int>& ranks = contextClientTmp->getRanksServerLeader(); |
---|
| 1452 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 1453 | event.push(*itRank,1,msg); |
---|
| 1454 | contextClientTmp->sendEvent(event); |
---|
| 1455 | } |
---|
| 1456 | else contextClientTmp->sendEvent(event); |
---|
[1025] | 1457 | } |
---|
| 1458 | } |
---|
[1622] | 1459 | CATCH_DUMP_ATTR |
---|
[1025] | 1460 | |
---|
| 1461 | //! Server side: Receive a message to do some post processing |
---|
| 1462 | void CContext::recvProcessingGridOfEnabledFields(CEventServer& event) |
---|
[1622] | 1463 | TRY |
---|
[1025] | 1464 | { |
---|
| 1465 | CBufferIn* buffer=event.subEvents.begin()->buffer; |
---|
| 1466 | string id; |
---|
[1144] | 1467 | *buffer>>id; |
---|
[1025] | 1468 | } |
---|
[1622] | 1469 | CATCH |
---|
[1025] | 1470 | |
---|
| 1471 | //! Client side: Send a message to do some post processing on server |
---|
[509] | 1472 | void CContext::sendPostProcessing() |
---|
[1622] | 1473 | TRY |
---|
[509] | 1474 | { |
---|
[987] | 1475 | // Use correct context client to send message |
---|
[1030] | 1476 | // int nbSrvPools = (hasServer) ? clientPrimServer.size() : 1; |
---|
| 1477 | int nbSrvPools = (this->hasServer) ? (this->hasClient ? this->clientPrimServer.size() : 0) : 1; |
---|
[1009] | 1478 | for (int i = 0; i < nbSrvPools; ++i) |
---|
[509] | 1479 | { |
---|
[1009] | 1480 | CContextClient* contextClientTmp = (hasServer) ? clientPrimServer[i] : client; |
---|
| 1481 | CEventClient event(getType(),EVENT_ID_POST_PROCESS); |
---|
| 1482 | if (contextClientTmp->isServerLeader()) |
---|
| 1483 | { |
---|
| 1484 | CMessage msg; |
---|
| 1485 | if (hasServer) |
---|
| 1486 | msg<<this->getIdServer(i); |
---|
| 1487 | else |
---|
| 1488 | msg<<this->getIdServer(); |
---|
| 1489 | const std::list<int>& ranks = contextClientTmp->getRanksServerLeader(); |
---|
| 1490 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
[987] | 1491 | event.push(*itRank,1,msg); |
---|
[1009] | 1492 | contextClientTmp->sendEvent(event); |
---|
| 1493 | } |
---|
| 1494 | else contextClientTmp->sendEvent(event); |
---|
[509] | 1495 | } |
---|
| 1496 | } |
---|
[1622] | 1497 | CATCH_DUMP_ATTR |
---|
[509] | 1498 | |
---|
| 1499 | //! Server side: Receive a message to do some post processing |
---|
| 1500 | void CContext::recvPostProcessing(CEventServer& event) |
---|
[1622] | 1501 | TRY |
---|
[509] | 1502 | { |
---|
| 1503 | CBufferIn* buffer=event.subEvents.begin()->buffer; |
---|
| 1504 | string id; |
---|
| 1505 | *buffer>>id; |
---|
| 1506 | get(id)->recvPostProcessing(*buffer); |
---|
| 1507 | } |
---|
[1622] | 1508 | CATCH |
---|
[509] | 1509 | |
---|
| 1510 | //! Server side: Receive a message to do some post processing |
---|
| 1511 | void CContext::recvPostProcessing(CBufferIn& buffer) |
---|
[1622] | 1512 | TRY |
---|
[509] | 1513 | { |
---|
[549] | 1514 | CCalendarWrapper::get(CCalendarWrapper::GetDefName())->createCalendar(); |
---|
[509] | 1515 | postProcessing(); |
---|
| 1516 | } |
---|
[1622] | 1517 | CATCH_DUMP_ATTR |
---|
[509] | 1518 | |
---|
[511] | 1519 | const StdString& CContext::getIdServer() |
---|
[1622] | 1520 | TRY |
---|
[511] | 1521 | { |
---|
| 1522 | if (hasClient) |
---|
| 1523 | { |
---|
| 1524 | idServer_ = this->getId(); |
---|
| 1525 | idServer_ += "_server"; |
---|
| 1526 | return idServer_; |
---|
| 1527 | } |
---|
| 1528 | if (hasServer) return (this->getId()); |
---|
| 1529 | } |
---|
[1622] | 1530 | CATCH_DUMP_ATTR |
---|
[511] | 1531 | |
---|
[1009] | 1532 | const StdString& CContext::getIdServer(const int i) |
---|
[1622] | 1533 | TRY |
---|
[1009] | 1534 | { |
---|
| 1535 | idServer_ = this->getId(); |
---|
| 1536 | idServer_ += "_server_"; |
---|
[1542] | 1537 | idServer_ += std::to_string(static_cast<unsigned long long>(i)); |
---|
[1009] | 1538 | return idServer_; |
---|
| 1539 | } |
---|
[1622] | 1540 | CATCH_DUMP_ATTR |
---|
[1009] | 1541 | |
---|
[509] | 1542 | /*! |
---|
| 1543 | \brief Do some simple post processings after parsing xml file |
---|
| 1544 | After the xml file (iodef.xml) is parsed, it is necessary to build all relations among |
---|
| 1545 | created object, e.g: inhertance among fields, domain, axis. After that, all fiels as well as their parents (reference fields), |
---|
| 1546 | which will be written out into netcdf files, are processed |
---|
| 1547 | */ |
---|
| 1548 | void CContext::postProcessing() |
---|
[1622] | 1549 | TRY |
---|
[509] | 1550 | { |
---|
| 1551 | if (isPostProcessed) return; |
---|
| 1552 | |
---|
[549] | 1553 | // Make sure the calendar was correctly created |
---|
| 1554 | if (!calendar) |
---|
| 1555 | ERROR("CContext::postProcessing()", << "A calendar must be defined for the context \"" << getId() << "!\"") |
---|
| 1556 | else if (calendar->getTimeStep() == NoneDu) |
---|
| 1557 | ERROR("CContext::postProcessing()", << "A timestep must be defined for the context \"" << getId() << "!\"") |
---|
[550] | 1558 | // Calendar first update to set the current date equals to the start date |
---|
| 1559 | calendar->update(0); |
---|
[509] | 1560 | |
---|
| 1561 | // Find all inheritance in xml structure |
---|
| 1562 | this->solveAllInheritance(); |
---|
| 1563 | |
---|
[992] | 1564 | // ShowTree(info(10)); |
---|
[983] | 1565 | |
---|
[676] | 1566 | // Check if some axis, domains or grids are eligible to for compressed indexed output. |
---|
| 1567 | // Warning: This must be done after solving the inheritance and before the rest of post-processing |
---|
[1025] | 1568 | checkAxisDomainsGridsEligibilityForCompressedOutput(); |
---|
[676] | 1569 | |
---|
[711] | 1570 | // Check if some automatic time series should be generated |
---|
[1144] | 1571 | // Warning: This must be done after solving the inheritance and before the rest of post-processing |
---|
[711] | 1572 | |
---|
[1025] | 1573 | // The timeseries should only be prepared in client |
---|
| 1574 | if (hasClient && !hasServer) prepareTimeseries(); |
---|
| 1575 | |
---|
[509] | 1576 | //Initialisation du vecteur 'enabledFiles' contenant la liste des fichiers à sortir. |
---|
[1232] | 1577 | findEnabledFiles(); |
---|
| 1578 | findEnabledWriteModeFiles(); |
---|
| 1579 | findEnabledReadModeFiles(); |
---|
| 1580 | |
---|
[1025] | 1581 | // For now, only read files with client and only one level server |
---|
[1232] | 1582 | // if (hasClient && !hasServer) findEnabledReadModeFiles(); |
---|
[509] | 1583 | |
---|
[1232] | 1584 | // Find all enabled fields of each file |
---|
| 1585 | findAllEnabledFieldsInFiles(this->enabledWriteModeFiles); |
---|
| 1586 | findAllEnabledFieldsInFiles(this->enabledReadModeFiles); |
---|
| 1587 | |
---|
[1025] | 1588 | // For now, only read files with client and only one level server |
---|
[1232] | 1589 | // if (hasClient && !hasServer) |
---|
| 1590 | // findAllEnabledFieldsInFiles(this->enabledReadModeFiles); |
---|
[509] | 1591 | |
---|
[1144] | 1592 | if (hasClient && !hasServer) |
---|
| 1593 | { |
---|
[1232] | 1594 | initReadFiles(); |
---|
| 1595 | // Try to read attributes of fields in file then fill in corresponding grid (or domain, axis) |
---|
| 1596 | this->readAttributesOfEnabledFieldsInReadModeFiles(); |
---|
[1144] | 1597 | } |
---|
| 1598 | |
---|
[823] | 1599 | // Only search and rebuild all reference objects of enable fields, don't transform |
---|
[1099] | 1600 | this->solveOnlyRefOfEnabledFields(false); |
---|
[823] | 1601 | |
---|
[1099] | 1602 | // Search and rebuild all reference object of enabled fields, and transform |
---|
[1129] | 1603 | this->solveAllRefOfEnabledFieldsAndTransform(false); |
---|
[1099] | 1604 | |
---|
[593] | 1605 | // Find all fields with read access from the public API |
---|
[1025] | 1606 | if (hasClient && !hasServer) findFieldsWithReadAccess(); |
---|
[593] | 1607 | // and solve the all reference for them |
---|
[1025] | 1608 | if (hasClient && !hasServer) solveAllRefOfFieldsWithReadAccess(); |
---|
[593] | 1609 | |
---|
[509] | 1610 | isPostProcessed = true; |
---|
| 1611 | } |
---|
[1622] | 1612 | CATCH_DUMP_ATTR |
---|
[509] | 1613 | |
---|
[917] | 1614 | /*! |
---|
| 1615 | * Compute the required buffer size to send the attributes (mostly those grid related). |
---|
| 1616 | * \param maxEventSize [in/out] the size of the bigger event for each connected server |
---|
[1330] | 1617 | * \param [in] contextClient |
---|
| 1618 | * \param [in] bufferForWriting True if buffers are used for sending data for writing |
---|
| 1619 | This flag is only true for client and server-1 for communication with server-2 |
---|
[917] | 1620 | */ |
---|
[1330] | 1621 | std::map<int, StdSize> CContext::getAttributesBufferSize(std::map<int, StdSize>& maxEventSize, |
---|
| 1622 | CContextClient* contextClient, bool bufferForWriting /*= "false"*/) |
---|
[1622] | 1623 | TRY |
---|
[509] | 1624 | { |
---|
[1372] | 1625 | // As calendar attributes are sent even if there are no active files or fields, maps are initialized according the size of calendar attributes |
---|
| 1626 | std::map<int, StdSize> attributesSize = CCalendarWrapper::get(CCalendarWrapper::GetDefName())->getMinimumBufferSizeForAttributes(contextClient); |
---|
| 1627 | maxEventSize = CCalendarWrapper::get(CCalendarWrapper::GetDefName())->getMinimumBufferSizeForAttributes(contextClient); |
---|
[731] | 1628 | |
---|
[1370] | 1629 | std::vector<CFile*>& fileList = this->enabledFiles; |
---|
| 1630 | size_t numEnabledFiles = fileList.size(); |
---|
| 1631 | for (size_t i = 0; i < numEnabledFiles; ++i) |
---|
[731] | 1632 | { |
---|
[1370] | 1633 | // CFile* file = this->enabledWriteModeFiles[i]; |
---|
| 1634 | CFile* file = fileList[i]; |
---|
| 1635 | std::vector<CField*> enabledFields = file->getEnabledFields(); |
---|
| 1636 | size_t numEnabledFields = enabledFields.size(); |
---|
| 1637 | for (size_t j = 0; j < numEnabledFields; ++j) |
---|
| 1638 | { |
---|
| 1639 | const std::map<int, StdSize> mapSize = enabledFields[j]->getGridAttributesBufferSize(contextClient, bufferForWriting); |
---|
| 1640 | std::map<int, StdSize>::const_iterator it = mapSize.begin(), itE = mapSize.end(); |
---|
| 1641 | for (; it != itE; ++it) |
---|
| 1642 | { |
---|
| 1643 | // If attributesSize[it->first] does not exist, it will be zero-initialized |
---|
| 1644 | // so we can use it safely without checking for its existence |
---|
| 1645 | if (attributesSize[it->first] < it->second) |
---|
| 1646 | attributesSize[it->first] = it->second; |
---|
[917] | 1647 | |
---|
[1370] | 1648 | if (maxEventSize[it->first] < it->second) |
---|
| 1649 | maxEventSize[it->first] = it->second; |
---|
| 1650 | } |
---|
| 1651 | } |
---|
[731] | 1652 | } |
---|
| 1653 | return attributesSize; |
---|
| 1654 | } |
---|
[1622] | 1655 | CATCH_DUMP_ATTR |
---|
[731] | 1656 | |
---|
[917] | 1657 | /*! |
---|
| 1658 | * Compute the required buffer size to send the fields data. |
---|
| 1659 | * \param maxEventSize [in/out] the size of the bigger event for each connected server |
---|
[1330] | 1660 | * \param [in] contextClient |
---|
| 1661 | * \param [in] bufferForWriting True if buffers are used for sending data for writing |
---|
| 1662 | This flag is only true for client and server-1 for communication with server-2 |
---|
[917] | 1663 | */ |
---|
[1330] | 1664 | std::map<int, StdSize> CContext::getDataBufferSize(std::map<int, StdSize>& maxEventSize, |
---|
| 1665 | CContextClient* contextClient, bool bufferForWriting /*= "false"*/) |
---|
[1622] | 1666 | TRY |
---|
[731] | 1667 | { |
---|
[730] | 1668 | std::map<int, StdSize> dataSize; |
---|
[509] | 1669 | |
---|
| 1670 | // Find all reference domain and axis of all active fields |
---|
[1330] | 1671 | std::vector<CFile*>& fileList = bufferForWriting ? this->enabledWriteModeFiles : this->enabledReadModeFiles; |
---|
| 1672 | size_t numEnabledFiles = fileList.size(); |
---|
[730] | 1673 | for (size_t i = 0; i < numEnabledFiles; ++i) |
---|
[509] | 1674 | { |
---|
[1330] | 1675 | CFile* file = fileList[i]; |
---|
[1193] | 1676 | if (file->getContextClient() == contextClient) |
---|
[1184] | 1677 | { |
---|
[1370] | 1678 | std::vector<CField*> enabledFields = file->getEnabledFields(); |
---|
| 1679 | size_t numEnabledFields = enabledFields.size(); |
---|
| 1680 | for (size_t j = 0; j < numEnabledFields; ++j) |
---|
[509] | 1681 | { |
---|
[1370] | 1682 | // const std::vector<std::map<int, StdSize> > mapSize = enabledFields[j]->getGridDataBufferSize(contextClient); |
---|
| 1683 | const std::map<int, StdSize> mapSize = enabledFields[j]->getGridDataBufferSize(contextClient,bufferForWriting); |
---|
| 1684 | std::map<int, StdSize>::const_iterator it = mapSize.begin(), itE = mapSize.end(); |
---|
| 1685 | for (; it != itE; ++it) |
---|
[509] | 1686 | { |
---|
[1370] | 1687 | // If dataSize[it->first] does not exist, it will be zero-initialized |
---|
| 1688 | // so we can use it safely without checking for its existance |
---|
| 1689 | if (CXios::isOptPerformance) |
---|
| 1690 | dataSize[it->first] += it->second; |
---|
| 1691 | else if (dataSize[it->first] < it->second) |
---|
| 1692 | dataSize[it->first] = it->second; |
---|
[917] | 1693 | |
---|
[1370] | 1694 | if (maxEventSize[it->first] < it->second) |
---|
| 1695 | maxEventSize[it->first] = it->second; |
---|
[598] | 1696 | } |
---|
[509] | 1697 | } |
---|
| 1698 | } |
---|
| 1699 | } |
---|
[730] | 1700 | return dataSize; |
---|
[509] | 1701 | } |
---|
[1622] | 1702 | CATCH_DUMP_ATTR |
---|
[509] | 1703 | |
---|
| 1704 | //! Client side: Send infomation of active files (files are enabled to write out) |
---|
[1232] | 1705 | void CContext::sendEnabledFiles(const std::vector<CFile*>& activeFiles) |
---|
[1622] | 1706 | TRY |
---|
[509] | 1707 | { |
---|
[1232] | 1708 | int size = activeFiles.size(); |
---|
[509] | 1709 | |
---|
| 1710 | // In a context, each type has a root definition, e.g: axis, domain, field. |
---|
| 1711 | // Every object must be a child of one of these root definition. In this case |
---|
| 1712 | // all new file objects created on server must be children of the root "file_definition" |
---|
| 1713 | StdString fileDefRoot("file_definition"); |
---|
| 1714 | CFileGroup* cfgrpPtr = CFileGroup::get(fileDefRoot); |
---|
[1158] | 1715 | |
---|
[509] | 1716 | for (int i = 0; i < size; ++i) |
---|
| 1717 | { |
---|
[1232] | 1718 | CFile* f = activeFiles[i]; |
---|
| 1719 | cfgrpPtr->sendCreateChild(f->getId(),f->getContextClient()); |
---|
| 1720 | f->sendAllAttributesToServer(f->getContextClient()); |
---|
| 1721 | f->sendAddAllVariables(f->getContextClient()); |
---|
[509] | 1722 | } |
---|
| 1723 | } |
---|
[1622] | 1724 | CATCH_DUMP_ATTR |
---|
[509] | 1725 | |
---|
| 1726 | //! Client side: Send information of active fields (ones are written onto files) |
---|
[1232] | 1727 | void CContext::sendEnabledFieldsInFiles(const std::vector<CFile*>& activeFiles) |
---|
[1622] | 1728 | TRY |
---|
[509] | 1729 | { |
---|
[1232] | 1730 | int size = activeFiles.size(); |
---|
[509] | 1731 | for (int i = 0; i < size; ++i) |
---|
| 1732 | { |
---|
[1232] | 1733 | activeFiles[i]->sendEnabledFields(activeFiles[i]->getContextClient()); |
---|
[509] | 1734 | } |
---|
| 1735 | } |
---|
[1622] | 1736 | CATCH_DUMP_ATTR |
---|
[509] | 1737 | |
---|
[676] | 1738 | //! Client side: Check if the defined axis, domains and grids are eligible for compressed indexed output |
---|
| 1739 | void CContext::checkAxisDomainsGridsEligibilityForCompressedOutput() |
---|
[1622] | 1740 | TRY |
---|
[676] | 1741 | { |
---|
| 1742 | if (!hasClient) return; |
---|
| 1743 | |
---|
| 1744 | const vector<CAxis*> allAxis = CAxis::getAll(); |
---|
| 1745 | for (vector<CAxis*>::const_iterator it = allAxis.begin(); it != allAxis.end(); it++) |
---|
| 1746 | (*it)->checkEligibilityForCompressedOutput(); |
---|
| 1747 | |
---|
| 1748 | const vector<CDomain*> allDomains = CDomain::getAll(); |
---|
| 1749 | for (vector<CDomain*>::const_iterator it = allDomains.begin(); it != allDomains.end(); it++) |
---|
| 1750 | (*it)->checkEligibilityForCompressedOutput(); |
---|
| 1751 | |
---|
| 1752 | const vector<CGrid*> allGrids = CGrid::getAll(); |
---|
| 1753 | for (vector<CGrid*>::const_iterator it = allGrids.begin(); it != allGrids.end(); it++) |
---|
| 1754 | (*it)->checkEligibilityForCompressedOutput(); |
---|
| 1755 | } |
---|
[1622] | 1756 | CATCH_DUMP_ATTR |
---|
[676] | 1757 | |
---|
[711] | 1758 | //! Client side: Prepare the timeseries by adding the necessary files |
---|
| 1759 | void CContext::prepareTimeseries() |
---|
[1622] | 1760 | TRY |
---|
[711] | 1761 | { |
---|
| 1762 | if (!hasClient) return; |
---|
| 1763 | |
---|
| 1764 | const std::vector<CFile*> allFiles = CFile::getAll(); |
---|
| 1765 | for (size_t i = 0; i < allFiles.size(); i++) |
---|
| 1766 | { |
---|
| 1767 | CFile* file = allFiles[i]; |
---|
| 1768 | |
---|
[1158] | 1769 | std::vector<CVariable*> fileVars, fieldVars, vars = file->getAllVariables(); |
---|
| 1770 | for (size_t k = 0; k < vars.size(); k++) |
---|
| 1771 | { |
---|
| 1772 | CVariable* var = vars[k]; |
---|
| 1773 | |
---|
| 1774 | if (var->ts_target.isEmpty() |
---|
| 1775 | || var->ts_target == CVariable::ts_target_attr::file || var->ts_target == CVariable::ts_target_attr::both) |
---|
| 1776 | fileVars.push_back(var); |
---|
| 1777 | |
---|
| 1778 | if (!var->ts_target.isEmpty() |
---|
| 1779 | && (var->ts_target == CVariable::ts_target_attr::field || var->ts_target == CVariable::ts_target_attr::both)) |
---|
| 1780 | fieldVars.push_back(var); |
---|
| 1781 | } |
---|
| 1782 | |
---|
[711] | 1783 | if (!file->timeseries.isEmpty() && file->timeseries != CFile::timeseries_attr::none) |
---|
| 1784 | { |
---|
[1158] | 1785 | StdString fileNameStr("%file_name%") ; |
---|
| 1786 | StdString tsPrefix = !file->ts_prefix.isEmpty() ? file->ts_prefix : fileNameStr ; |
---|
| 1787 | |
---|
| 1788 | StdString fileName=file->getFileOutputName(); |
---|
| 1789 | size_t pos=tsPrefix.find(fileNameStr) ; |
---|
| 1790 | while (pos!=std::string::npos) |
---|
| 1791 | { |
---|
| 1792 | tsPrefix=tsPrefix.replace(pos,fileNameStr.size(),fileName) ; |
---|
| 1793 | pos=tsPrefix.find(fileNameStr) ; |
---|
| 1794 | } |
---|
| 1795 | |
---|
[711] | 1796 | const std::vector<CField*> allFields = file->getAllFields(); |
---|
| 1797 | for (size_t j = 0; j < allFields.size(); j++) |
---|
| 1798 | { |
---|
| 1799 | CField* field = allFields[j]; |
---|
| 1800 | |
---|
| 1801 | if (!field->ts_enabled.isEmpty() && field->ts_enabled) |
---|
| 1802 | { |
---|
| 1803 | CFile* tsFile = CFile::create(); |
---|
| 1804 | tsFile->duplicateAttributes(file); |
---|
| 1805 | |
---|
[1158] | 1806 | // Add variables originating from file and targeted to timeserie file |
---|
| 1807 | for (size_t k = 0; k < fileVars.size(); k++) |
---|
| 1808 | tsFile->getVirtualVariableGroup()->addChild(fileVars[k]); |
---|
| 1809 | |
---|
| 1810 | |
---|
[711] | 1811 | tsFile->name = tsPrefix + "_"; |
---|
| 1812 | if (!field->name.isEmpty()) |
---|
| 1813 | tsFile->name.get() += field->name; |
---|
| 1814 | else if (field->hasDirectFieldReference()) // We cannot use getBaseFieldReference() just yet |
---|
| 1815 | tsFile->name.get() += field->field_ref; |
---|
| 1816 | else |
---|
| 1817 | tsFile->name.get() += field->getId(); |
---|
| 1818 | |
---|
| 1819 | if (!field->ts_split_freq.isEmpty()) |
---|
| 1820 | tsFile->split_freq = field->ts_split_freq; |
---|
| 1821 | |
---|
| 1822 | CField* tsField = tsFile->addField(); |
---|
| 1823 | tsField->field_ref = field->getId(); |
---|
| 1824 | |
---|
[1158] | 1825 | // Add variables originating from file and targeted to timeserie field |
---|
| 1826 | for (size_t k = 0; k < fieldVars.size(); k++) |
---|
| 1827 | tsField->getVirtualVariableGroup()->addChild(fieldVars[k]); |
---|
| 1828 | |
---|
| 1829 | vars = field->getAllVariables(); |
---|
| 1830 | for (size_t k = 0; k < vars.size(); k++) |
---|
| 1831 | { |
---|
| 1832 | CVariable* var = vars[k]; |
---|
| 1833 | |
---|
| 1834 | // Add variables originating from field and targeted to timeserie field |
---|
| 1835 | if (var->ts_target.isEmpty() |
---|
| 1836 | || var->ts_target == CVariable::ts_target_attr::field || var->ts_target == CVariable::ts_target_attr::both) |
---|
| 1837 | tsField->getVirtualVariableGroup()->addChild(var); |
---|
| 1838 | |
---|
| 1839 | // Add variables originating from field and targeted to timeserie file |
---|
| 1840 | if (!var->ts_target.isEmpty() |
---|
| 1841 | && (var->ts_target == CVariable::ts_target_attr::file || var->ts_target == CVariable::ts_target_attr::both)) |
---|
| 1842 | tsFile->getVirtualVariableGroup()->addChild(var); |
---|
| 1843 | } |
---|
| 1844 | |
---|
[711] | 1845 | tsFile->solveFieldRefInheritance(true); |
---|
| 1846 | |
---|
| 1847 | if (file->timeseries == CFile::timeseries_attr::exclusive) |
---|
| 1848 | field->enabled = false; |
---|
| 1849 | } |
---|
| 1850 | } |
---|
| 1851 | |
---|
| 1852 | // Finally disable the original file is need be |
---|
| 1853 | if (file->timeseries == CFile::timeseries_attr::only) |
---|
| 1854 | file->enabled = false; |
---|
| 1855 | } |
---|
| 1856 | } |
---|
| 1857 | } |
---|
[1622] | 1858 | CATCH_DUMP_ATTR |
---|
[711] | 1859 | |
---|
[509] | 1860 | //! Client side: Send information of reference grid of active fields |
---|
[1232] | 1861 | void CContext::sendRefGrid(const std::vector<CFile*>& activeFiles) |
---|
[1622] | 1862 | TRY |
---|
[509] | 1863 | { |
---|
| 1864 | std::set<StdString> gridIds; |
---|
[1232] | 1865 | int sizeFile = activeFiles.size(); |
---|
[509] | 1866 | CFile* filePtr(NULL); |
---|
| 1867 | |
---|
| 1868 | // Firstly, find all reference grids of all active fields |
---|
| 1869 | for (int i = 0; i < sizeFile; ++i) |
---|
| 1870 | { |
---|
[1232] | 1871 | filePtr = activeFiles[i]; |
---|
[509] | 1872 | std::vector<CField*> enabledFields = filePtr->getEnabledFields(); |
---|
| 1873 | int sizeField = enabledFields.size(); |
---|
| 1874 | for (int numField = 0; numField < sizeField; ++numField) |
---|
| 1875 | { |
---|
| 1876 | if (0 != enabledFields[numField]->getRelGrid()) |
---|
| 1877 | gridIds.insert(CGrid::get(enabledFields[numField]->getRelGrid())->getId()); |
---|
| 1878 | } |
---|
| 1879 | } |
---|
| 1880 | |
---|
| 1881 | // Create all reference grids on server side |
---|
| 1882 | StdString gridDefRoot("grid_definition"); |
---|
| 1883 | CGridGroup* gridPtr = CGridGroup::get(gridDefRoot); |
---|
| 1884 | std::set<StdString>::const_iterator it, itE = gridIds.end(); |
---|
| 1885 | for (it = gridIds.begin(); it != itE; ++it) |
---|
| 1886 | { |
---|
| 1887 | gridPtr->sendCreateChild(*it); |
---|
[1927] | 1888 | CGrid::get(*it)->sendGrid() ; |
---|
[509] | 1889 | } |
---|
| 1890 | } |
---|
[1622] | 1891 | CATCH_DUMP_ATTR |
---|
[509] | 1892 | |
---|
[1232] | 1893 | //! Client side: Send information of reference domain, axis and scalar of active fields |
---|
| 1894 | void CContext::sendRefDomainsAxisScalars(const std::vector<CFile*>& activeFiles) |
---|
[1622] | 1895 | TRY |
---|
[569] | 1896 | { |
---|
[887] | 1897 | std::set<StdString> domainIds, axisIds, scalarIds; |
---|
[509] | 1898 | |
---|
[569] | 1899 | // Find all reference domain and axis of all active fields |
---|
[1232] | 1900 | int numEnabledFiles = activeFiles.size(); |
---|
[569] | 1901 | for (int i = 0; i < numEnabledFiles; ++i) |
---|
| 1902 | { |
---|
[1232] | 1903 | std::vector<CField*> enabledFields = activeFiles[i]->getEnabledFields(); |
---|
[569] | 1904 | int numEnabledFields = enabledFields.size(); |
---|
| 1905 | for (int j = 0; j < numEnabledFields; ++j) |
---|
| 1906 | { |
---|
[887] | 1907 | const std::vector<StdString>& prDomAxisScalarId = enabledFields[j]->getRefDomainAxisIds(); |
---|
| 1908 | if ("" != prDomAxisScalarId[0]) domainIds.insert(prDomAxisScalarId[0]); |
---|
| 1909 | if ("" != prDomAxisScalarId[1]) axisIds.insert(prDomAxisScalarId[1]); |
---|
| 1910 | if ("" != prDomAxisScalarId[2]) scalarIds.insert(prDomAxisScalarId[2]); |
---|
[569] | 1911 | } |
---|
| 1912 | } |
---|
| 1913 | |
---|
| 1914 | // Create all reference axis on server side |
---|
[887] | 1915 | std::set<StdString>::iterator itDom, itAxis, itScalar; |
---|
[569] | 1916 | std::set<StdString>::const_iterator itE; |
---|
| 1917 | |
---|
[887] | 1918 | StdString scalarDefRoot("scalar_definition"); |
---|
| 1919 | CScalarGroup* scalarPtr = CScalarGroup::get(scalarDefRoot); |
---|
| 1920 | itE = scalarIds.end(); |
---|
| 1921 | for (itScalar = scalarIds.begin(); itScalar != itE; ++itScalar) |
---|
| 1922 | { |
---|
| 1923 | if (!itScalar->empty()) |
---|
| 1924 | { |
---|
| 1925 | scalarPtr->sendCreateChild(*itScalar); |
---|
| 1926 | CScalar::get(*itScalar)->sendAllAttributesToServer(); |
---|
| 1927 | } |
---|
| 1928 | } |
---|
| 1929 | |
---|
[569] | 1930 | StdString axiDefRoot("axis_definition"); |
---|
| 1931 | CAxisGroup* axisPtr = CAxisGroup::get(axiDefRoot); |
---|
| 1932 | itE = axisIds.end(); |
---|
| 1933 | for (itAxis = axisIds.begin(); itAxis != itE; ++itAxis) |
---|
| 1934 | { |
---|
| 1935 | if (!itAxis->empty()) |
---|
| 1936 | { |
---|
| 1937 | axisPtr->sendCreateChild(*itAxis); |
---|
| 1938 | CAxis::get(*itAxis)->sendAllAttributesToServer(); |
---|
| 1939 | } |
---|
| 1940 | } |
---|
| 1941 | |
---|
| 1942 | // Create all reference domains on server side |
---|
| 1943 | StdString domDefRoot("domain_definition"); |
---|
| 1944 | CDomainGroup* domPtr = CDomainGroup::get(domDefRoot); |
---|
| 1945 | itE = domainIds.end(); |
---|
| 1946 | for (itDom = domainIds.begin(); itDom != itE; ++itDom) |
---|
| 1947 | { |
---|
| 1948 | if (!itDom->empty()) { |
---|
| 1949 | domPtr->sendCreateChild(*itDom); |
---|
| 1950 | CDomain::get(*itDom)->sendAllAttributesToServer(); |
---|
| 1951 | } |
---|
| 1952 | } |
---|
| 1953 | } |
---|
[1622] | 1954 | CATCH_DUMP_ATTR |
---|
[569] | 1955 | |
---|
[509] | 1956 | //! Update calendar in each time step |
---|
[300] | 1957 | void CContext::updateCalendar(int step) |
---|
[1622] | 1958 | TRY |
---|
[300] | 1959 | { |
---|
[1357] | 1960 | int prevStep = calendar->getStep(); |
---|
| 1961 | |
---|
| 1962 | if (prevStep < step) |
---|
[639] | 1963 | { |
---|
[1358] | 1964 | if (hasClient && !hasServer) // For now we only use server level 1 to read data |
---|
| 1965 | { |
---|
| 1966 | doPreTimestepOperationsForEnabledReadModeFiles(); |
---|
| 1967 | } |
---|
| 1968 | |
---|
[1357] | 1969 | info(50) << "updateCalendar : before : " << calendar->getCurrentDate() << endl; |
---|
| 1970 | calendar->update(step); |
---|
| 1971 | info(50) << "updateCalendar : after : " << calendar->getCurrentDate() << endl; |
---|
| 1972 | #ifdef XIOS_MEMTRACK_LIGHT |
---|
| 1973 | info(50) << " Current memory used by XIOS : "<< MemTrack::getCurrentMemorySize()*1.0/(1024*1024)<<" Mbyte, at timestep "<<step<<" of context "<<this->getId()<<endl ; |
---|
| 1974 | #endif |
---|
| 1975 | |
---|
| 1976 | if (hasClient && !hasServer) // For now we only use server level 1 to read data |
---|
| 1977 | { |
---|
| 1978 | doPostTimestepOperationsForEnabledReadModeFiles(); |
---|
| 1979 | garbageCollector.invalidate(calendar->getCurrentDate()); |
---|
| 1980 | } |
---|
[2428] | 1981 | CMemChecker::logMem( "CContext::updateCalendar_"+std::to_string(step) ); |
---|
[639] | 1982 | } |
---|
[1357] | 1983 | else if (prevStep == step) |
---|
| 1984 | info(50) << "updateCalendar: already at step " << step << ", no operation done." << endl; |
---|
| 1985 | else // if (prevStep > step) |
---|
| 1986 | ERROR("void CContext::updateCalendar(int step)", |
---|
| 1987 | << "Illegal calendar update: previous step was " << prevStep << ", new step " << step << "is in the past!") |
---|
[300] | 1988 | } |
---|
[1622] | 1989 | CATCH_DUMP_ATTR |
---|
[509] | 1990 | |
---|
[1232] | 1991 | void CContext::initReadFiles(void) |
---|
[1622] | 1992 | TRY |
---|
[1232] | 1993 | { |
---|
| 1994 | vector<CFile*>::const_iterator it; |
---|
| 1995 | |
---|
| 1996 | for (it=enabledReadModeFiles.begin(); it != enabledReadModeFiles.end(); it++) |
---|
| 1997 | { |
---|
| 1998 | (*it)->initRead(); |
---|
| 1999 | } |
---|
| 2000 | } |
---|
[1622] | 2001 | CATCH_DUMP_ATTR |
---|
[1232] | 2002 | |
---|
[509] | 2003 | //! Server side: Create header of netcdf file |
---|
[1232] | 2004 | void CContext::createFileHeader(void) |
---|
[1622] | 2005 | TRY |
---|
[300] | 2006 | { |
---|
[549] | 2007 | vector<CFile*>::const_iterator it; |
---|
[2253] | 2008 | if (!hasClient && hasServer) |
---|
| 2009 | for (it=enabledFiles.begin(); it != enabledFiles.end(); it++) (*it)->initWrite(); |
---|
| 2010 | else if (hasClient && hasServer) |
---|
| 2011 | for (it=enabledReadModeFiles.begin(); it != enabledReadModeFiles.end(); it++) (*it)->initWrite(); |
---|
[509] | 2012 | } |
---|
[1622] | 2013 | CATCH_DUMP_ATTR |
---|
[509] | 2014 | |
---|
| 2015 | //! Get current context |
---|
[347] | 2016 | CContext* CContext::getCurrent(void) |
---|
[1622] | 2017 | TRY |
---|
[300] | 2018 | { |
---|
[549] | 2019 | return CObjectFactory::GetObject<CContext>(CObjectFactory::GetCurrentContextId()).get(); |
---|
[300] | 2020 | } |
---|
[1622] | 2021 | CATCH |
---|
[509] | 2022 | |
---|
| 2023 | /*! |
---|
| 2024 | \brief Set context with an id be the current context |
---|
| 2025 | \param [in] id identity of context to be set to current |
---|
| 2026 | */ |
---|
[346] | 2027 | void CContext::setCurrent(const string& id) |
---|
[1622] | 2028 | TRY |
---|
[346] | 2029 | { |
---|
| 2030 | CObjectFactory::SetCurrentContextId(id); |
---|
| 2031 | CGroupFactory::SetCurrentContextId(id); |
---|
| 2032 | } |
---|
[1622] | 2033 | CATCH |
---|
[509] | 2034 | |
---|
| 2035 | /*! |
---|
| 2036 | \brief Create a context with specific id |
---|
| 2037 | \param [in] id identity of new context |
---|
| 2038 | \return pointer to the new context or already-existed one with identity id |
---|
| 2039 | */ |
---|
[347] | 2040 | CContext* CContext::create(const StdString& id) |
---|
[1622] | 2041 | TRY |
---|
[346] | 2042 | { |
---|
[549] | 2043 | CContext::setCurrent(id); |
---|
[509] | 2044 | |
---|
[346] | 2045 | bool hasctxt = CContext::has(id); |
---|
[347] | 2046 | CContext* context = CObjectFactory::CreateObject<CContext>(id).get(); |
---|
[549] | 2047 | getRoot(); |
---|
[347] | 2048 | if (!hasctxt) CGroupFactory::AddChild(root, context->getShared()); |
---|
[346] | 2049 | |
---|
| 2050 | #define DECLARE_NODE(Name_, name_) \ |
---|
| 2051 | C##Name_##Definition::create(C##Name_##Definition::GetDefName()); |
---|
| 2052 | #define DECLARE_NODE_PAR(Name_, name_) |
---|
| 2053 | #include "node_type.conf" |
---|
| 2054 | |
---|
| 2055 | return (context); |
---|
| 2056 | } |
---|
[1622] | 2057 | CATCH |
---|
[697] | 2058 | |
---|
| 2059 | //! Server side: Receive a message to do some post processing |
---|
| 2060 | void CContext::recvRegistry(CEventServer& event) |
---|
[1622] | 2061 | TRY |
---|
[697] | 2062 | { |
---|
| 2063 | CBufferIn* buffer=event.subEvents.begin()->buffer; |
---|
| 2064 | string id; |
---|
| 2065 | *buffer>>id; |
---|
| 2066 | get(id)->recvRegistry(*buffer); |
---|
| 2067 | } |
---|
[1622] | 2068 | CATCH |
---|
[697] | 2069 | |
---|
| 2070 | void CContext::recvRegistry(CBufferIn& buffer) |
---|
[1622] | 2071 | TRY |
---|
[697] | 2072 | { |
---|
| 2073 | if (server->intraCommRank==0) |
---|
| 2074 | { |
---|
| 2075 | CRegistry registry(server->intraComm) ; |
---|
| 2076 | registry.fromBuffer(buffer) ; |
---|
| 2077 | registryOut->mergeRegistry(registry) ; |
---|
| 2078 | } |
---|
| 2079 | } |
---|
[1622] | 2080 | CATCH_DUMP_ATTR |
---|
[697] | 2081 | |
---|
| 2082 | void CContext::sendRegistry(void) |
---|
[1622] | 2083 | TRY |
---|
[1158] | 2084 | { |
---|
[697] | 2085 | registryOut->hierarchicalGatherRegistry() ; |
---|
| 2086 | |
---|
[1009] | 2087 | // Use correct context client to send message |
---|
[1030] | 2088 | int nbSrvPools = (this->hasServer) ? (this->hasClient ? this->clientPrimServer.size() : 0) : 1; |
---|
[1009] | 2089 | for (int i = 0; i < nbSrvPools; ++i) |
---|
| 2090 | { |
---|
| 2091 | CContextClient* contextClientTmp = (hasServer) ? clientPrimServer[i] : client; |
---|
| 2092 | CEventClient event(CContext::GetType(), CContext::EVENT_ID_SEND_REGISTRY); |
---|
[1021] | 2093 | if (contextClientTmp->isServerLeader()) |
---|
[1009] | 2094 | { |
---|
| 2095 | CMessage msg ; |
---|
| 2096 | if (hasServer) |
---|
| 2097 | msg<<this->getIdServer(i); |
---|
| 2098 | else |
---|
| 2099 | msg<<this->getIdServer(); |
---|
| 2100 | if (contextClientTmp->clientRank==0) msg<<*registryOut ; |
---|
[1021] | 2101 | const std::list<int>& ranks = contextClientTmp->getRanksServerLeader(); |
---|
[1009] | 2102 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 2103 | event.push(*itRank,1,msg); |
---|
| 2104 | contextClientTmp->sendEvent(event); |
---|
| 2105 | } |
---|
| 2106 | else contextClientTmp->sendEvent(event); |
---|
| 2107 | } |
---|
[697] | 2108 | } |
---|
[1622] | 2109 | CATCH_DUMP_ATTR |
---|
[697] | 2110 | |
---|
[1130] | 2111 | /*! |
---|
| 2112 | * \fn bool CContext::isFinalized(void) |
---|
[1139] | 2113 | * Context is finalized if it received context post finalize event. |
---|
[1130] | 2114 | */ |
---|
[1054] | 2115 | bool CContext::isFinalized(void) |
---|
[1622] | 2116 | TRY |
---|
[1054] | 2117 | { |
---|
[1139] | 2118 | return finalized; |
---|
[1054] | 2119 | } |
---|
[1622] | 2120 | CATCH_DUMP_ATTR |
---|
| 2121 | ///-------------------------------------------------------------- |
---|
| 2122 | StdString CContext::dumpClassAttributes(void) |
---|
| 2123 | { |
---|
| 2124 | StdString str; |
---|
| 2125 | str.append("enabled files=\""); |
---|
| 2126 | int size = this->enabledFiles.size(); |
---|
| 2127 | for (int i = 0; i < size; ++i) |
---|
| 2128 | { |
---|
| 2129 | str.append(enabledFiles[i]->getId()); |
---|
| 2130 | str.append(" "); |
---|
| 2131 | } |
---|
| 2132 | str.append("\""); |
---|
| 2133 | return str; |
---|
| 2134 | } |
---|
[1054] | 2135 | |
---|
[335] | 2136 | } // namespace xios |
---|