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