[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" |
---|
[1205] | 16 | #include "timer.hpp" |
---|
| 17 | #include "memtrack.hpp" |
---|
[219] | 18 | |
---|
[1205] | 19 | |
---|
[335] | 20 | namespace xios { |
---|
[509] | 21 | |
---|
[1134] | 22 | //shared_ptr<CContextGroup> CContext::root; |
---|
| 23 | shared_ptr<CContextGroup> * CContext::root_ptr = 0; |
---|
[509] | 24 | |
---|
[1146] | 25 | /// ////////////////////// Dfinitions ////////////////////// /// |
---|
[219] | 26 | |
---|
| 27 | CContext::CContext(void) |
---|
| 28 | : CObjectTemplate<CContext>(), CContextAttributes() |
---|
[597] | 29 | , calendar(), hasClient(false), hasServer(false), isPostProcessed(false), finalized(false) |
---|
[730] | 30 | , idServer_(), client(0), server(0) |
---|
[219] | 31 | { /* Ne rien faire de plus */ } |
---|
| 32 | |
---|
| 33 | CContext::CContext(const StdString & id) |
---|
| 34 | : CObjectTemplate<CContext>(id), CContextAttributes() |
---|
[597] | 35 | , calendar(), hasClient(false), hasServer(false), isPostProcessed(false), finalized(false) |
---|
[730] | 36 | , idServer_(), client(0), server(0) |
---|
[219] | 37 | { /* Ne rien faire de plus */ } |
---|
| 38 | |
---|
| 39 | CContext::~CContext(void) |
---|
[509] | 40 | { |
---|
[597] | 41 | delete client; |
---|
| 42 | delete server; |
---|
[300] | 43 | } |
---|
[219] | 44 | |
---|
| 45 | //---------------------------------------------------------------- |
---|
[509] | 46 | //! Get name of context |
---|
[219] | 47 | StdString CContext::GetName(void) { return (StdString("context")); } |
---|
| 48 | StdString CContext::GetDefName(void){ return (CContext::GetName()); } |
---|
| 49 | ENodeType CContext::GetType(void) { return (eContext); } |
---|
| 50 | |
---|
| 51 | //---------------------------------------------------------------- |
---|
[640] | 52 | |
---|
[509] | 53 | /*! |
---|
| 54 | \brief Get context group (context root) |
---|
| 55 | \return Context root |
---|
| 56 | */ |
---|
[347] | 57 | CContextGroup* CContext::getRoot(void) |
---|
[509] | 58 | { |
---|
[1134] | 59 | //if (root.get()==NULL) root=shared_ptr<CContextGroup>(new CContextGroup(xml::CXMLNode::GetRootName())); |
---|
| 60 | //return root.get(); |
---|
| 61 | |
---|
| 62 | //static shared_ptr<CContextGroup> *root_ptr; |
---|
| 63 | if(root_ptr == 0) //root_ptr = new shared_ptr<CContextGroup>; |
---|
| 64 | // if (root_ptr->get()==NULL) |
---|
| 65 | root_ptr = new shared_ptr<CContextGroup>(new CContextGroup(xml::CXMLNode::GetRootName())); |
---|
| 66 | return root_ptr->get(); |
---|
[219] | 67 | } |
---|
| 68 | |
---|
[640] | 69 | //---------------------------------------------------------------- |
---|
[509] | 70 | |
---|
| 71 | /*! |
---|
| 72 | \brief Get calendar of a context |
---|
| 73 | \return Calendar |
---|
| 74 | */ |
---|
[343] | 75 | boost::shared_ptr<CCalendar> CContext::getCalendar(void) const |
---|
[219] | 76 | { |
---|
| 77 | return (this->calendar); |
---|
| 78 | } |
---|
[509] | 79 | |
---|
[219] | 80 | //---------------------------------------------------------------- |
---|
[640] | 81 | |
---|
[509] | 82 | /*! |
---|
| 83 | \brief Set a context with a calendar |
---|
| 84 | \param[in] newCalendar new calendar |
---|
| 85 | */ |
---|
[343] | 86 | void CContext::setCalendar(boost::shared_ptr<CCalendar> newCalendar) |
---|
[219] | 87 | { |
---|
| 88 | this->calendar = newCalendar; |
---|
| 89 | } |
---|
[509] | 90 | |
---|
[219] | 91 | //---------------------------------------------------------------- |
---|
[509] | 92 | /*! |
---|
| 93 | \brief Parse xml file and write information into context object |
---|
| 94 | \param [in] node xmld node corresponding in xml file |
---|
| 95 | */ |
---|
[219] | 96 | void CContext::parse(xml::CXMLNode & node) |
---|
| 97 | { |
---|
| 98 | CContext::SuperClass::parse(node); |
---|
| 99 | |
---|
| 100 | // PARSING POUR GESTION DES ENFANTS |
---|
[278] | 101 | xml::THashAttributes attributes = node.getAttributes(); |
---|
[219] | 102 | |
---|
[278] | 103 | if (attributes.end() != attributes.find("src")) |
---|
| 104 | { |
---|
| 105 | StdIFStream ifs ( attributes["src"].c_str() , StdIFStream::in ); |
---|
[462] | 106 | if ( (ifs.rdstate() & std::ifstream::failbit ) != 0 ) |
---|
| 107 | ERROR("void CContext::parse(xml::CXMLNode & node)", |
---|
| 108 | <<endl<< "Can not open <"<<attributes["src"].c_str()<<"> file" ); |
---|
[278] | 109 | if (!ifs.good()) |
---|
| 110 | ERROR("CContext::parse(xml::CXMLNode & node)", |
---|
| 111 | << "[ filename = " << attributes["src"] << " ] Bad xml stream !"); |
---|
[462] | 112 | xml::CXMLParser::ParseInclude(ifs, attributes["src"], *this); |
---|
[278] | 113 | } |
---|
| 114 | |
---|
[219] | 115 | if (node.getElementName().compare(CContext::GetName())) |
---|
[421] | 116 | DEBUG("Le noeud is wrong defined but will be considered as a context !"); |
---|
[219] | 117 | |
---|
| 118 | if (!(node.goToChildElement())) |
---|
| 119 | { |
---|
| 120 | DEBUG("Le context ne contient pas d'enfant !"); |
---|
| 121 | } |
---|
| 122 | else |
---|
| 123 | { |
---|
| 124 | do { // Parcours des contextes pour traitement. |
---|
| 125 | |
---|
| 126 | StdString name = node.getElementName(); |
---|
| 127 | attributes.clear(); |
---|
| 128 | attributes = node.getAttributes(); |
---|
| 129 | |
---|
| 130 | if (attributes.end() != attributes.find("id")) |
---|
[509] | 131 | { |
---|
| 132 | DEBUG(<< "Definition node has an id," |
---|
| 133 | << "it will not be taking account !"); |
---|
| 134 | } |
---|
[219] | 135 | |
---|
| 136 | #define DECLARE_NODE(Name_, name_) \ |
---|
| 137 | if (name.compare(C##Name_##Definition::GetDefName()) == 0) \ |
---|
[549] | 138 | { C##Name_##Definition::create(C##Name_##Definition::GetDefName()) -> parse(node); continue; } |
---|
[219] | 139 | #define DECLARE_NODE_PAR(Name_, name_) |
---|
| 140 | #include "node_type.conf" |
---|
[286] | 141 | |
---|
[421] | 142 | DEBUG(<< "The element \'" << name |
---|
| 143 | << "\' in the context \'" << CContext::getCurrent()->getId() |
---|
| 144 | << "\' is not a definition !"); |
---|
[219] | 145 | |
---|
| 146 | } while (node.goToNextElement()); |
---|
| 147 | |
---|
| 148 | node.goToParentElement(); // Retour au parent |
---|
| 149 | } |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | //---------------------------------------------------------------- |
---|
[509] | 153 | //! Show tree structure of context |
---|
[219] | 154 | void CContext::ShowTree(StdOStream & out) |
---|
| 155 | { |
---|
[549] | 156 | StdString currentContextId = CContext::getCurrent() -> getId(); |
---|
[347] | 157 | std::vector<CContext*> def_vector = |
---|
[346] | 158 | CContext::getRoot()->getChildList(); |
---|
[347] | 159 | std::vector<CContext*>::iterator |
---|
[219] | 160 | it = def_vector.begin(), end = def_vector.end(); |
---|
| 161 | |
---|
| 162 | out << "<? xml version=\"1.0\" ?>" << std::endl; |
---|
| 163 | out << "<" << xml::CXMLNode::GetRootName() << " >" << std::endl; |
---|
[509] | 164 | |
---|
[219] | 165 | for (; it != end; it++) |
---|
| 166 | { |
---|
[509] | 167 | CContext* context = *it; |
---|
| 168 | CContext::setCurrent(context->getId()); |
---|
[219] | 169 | out << *context << std::endl; |
---|
| 170 | } |
---|
[509] | 171 | |
---|
[219] | 172 | out << "</" << xml::CXMLNode::GetRootName() << " >" << std::endl; |
---|
[509] | 173 | CContext::setCurrent(currentContextId); |
---|
[219] | 174 | } |
---|
[346] | 175 | |
---|
[509] | 176 | |
---|
[219] | 177 | //---------------------------------------------------------------- |
---|
| 178 | |
---|
[509] | 179 | //! Convert context object into string (to print) |
---|
[219] | 180 | StdString CContext::toString(void) const |
---|
| 181 | { |
---|
| 182 | StdOStringStream oss; |
---|
| 183 | oss << "<" << CContext::GetName() |
---|
| 184 | << " id=\"" << this->getId() << "\" " |
---|
| 185 | << SuperClassAttribute::toString() << ">" << std::endl; |
---|
| 186 | if (!this->hasChild()) |
---|
| 187 | { |
---|
[1146] | 188 | //oss << "<!-- No definition -->" << std::endl; // fait planter l'incrmentation |
---|
[219] | 189 | } |
---|
| 190 | else |
---|
| 191 | { |
---|
| 192 | |
---|
| 193 | #define DECLARE_NODE(Name_, name_) \ |
---|
[346] | 194 | if (C##Name_##Definition::has(C##Name_##Definition::GetDefName())) \ |
---|
| 195 | oss << * C##Name_##Definition::get(C##Name_##Definition::GetDefName()) << std::endl; |
---|
[219] | 196 | #define DECLARE_NODE_PAR(Name_, name_) |
---|
| 197 | #include "node_type.conf" |
---|
| 198 | |
---|
| 199 | } |
---|
| 200 | |
---|
| 201 | oss << "</" << CContext::GetName() << " >"; |
---|
| 202 | |
---|
| 203 | return (oss.str()); |
---|
| 204 | } |
---|
| 205 | |
---|
| 206 | //---------------------------------------------------------------- |
---|
| 207 | |
---|
[509] | 208 | /*! |
---|
| 209 | \brief Find all inheritace among objects in a context. |
---|
| 210 | \param [in] apply (true) write attributes of parent into ones of child if they are empty |
---|
| 211 | (false) write attributes of parent into a new container of child |
---|
| 212 | \param [in] parent unused |
---|
| 213 | */ |
---|
[445] | 214 | void CContext::solveDescInheritance(bool apply, const CAttributeMap * const UNUSED(parent)) |
---|
[219] | 215 | { |
---|
| 216 | #define DECLARE_NODE(Name_, name_) \ |
---|
[354] | 217 | if (C##Name_##Definition::has(C##Name_##Definition::GetDefName())) \ |
---|
[445] | 218 | C##Name_##Definition::get(C##Name_##Definition::GetDefName())->solveDescInheritance(apply); |
---|
[219] | 219 | #define DECLARE_NODE_PAR(Name_, name_) |
---|
| 220 | #include "node_type.conf" |
---|
| 221 | } |
---|
| 222 | |
---|
| 223 | //---------------------------------------------------------------- |
---|
| 224 | |
---|
[509] | 225 | //! Verify if all root definition in the context have child. |
---|
[219] | 226 | bool CContext::hasChild(void) const |
---|
| 227 | { |
---|
| 228 | return ( |
---|
| 229 | #define DECLARE_NODE(Name_, name_) \ |
---|
[346] | 230 | C##Name_##Definition::has(C##Name_##Definition::GetDefName()) || |
---|
[219] | 231 | #define DECLARE_NODE_PAR(Name_, name_) |
---|
| 232 | #include "node_type.conf" |
---|
| 233 | false); |
---|
| 234 | } |
---|
| 235 | |
---|
| 236 | //---------------------------------------------------------------- |
---|
| 237 | |
---|
| 238 | void CContext::CleanTree(void) |
---|
| 239 | { |
---|
[549] | 240 | #define DECLARE_NODE(Name_, name_) C##Name_##Definition::ClearAllAttributes(); |
---|
[219] | 241 | #define DECLARE_NODE_PAR(Name_, name_) |
---|
| 242 | #include "node_type.conf" |
---|
| 243 | } |
---|
| 244 | ///--------------------------------------------------------------- |
---|
[509] | 245 | |
---|
| 246 | //! Initialize client side |
---|
[1134] | 247 | void CContext::initClient(ep_lib::MPI_Comm intraComm, ep_lib::MPI_Comm interComm, CContext* cxtServer /*= 0*/) |
---|
[300] | 248 | { |
---|
[549] | 249 | hasClient=true; |
---|
[1134] | 250 | client = new CContextClient(this, intraComm, interComm, cxtServer); |
---|
| 251 | |
---|
| 252 | int tmp_rank; |
---|
| 253 | MPI_Comm_rank(intraComm, &tmp_rank); |
---|
| 254 | MPI_Barrier(intraComm); |
---|
| 255 | |
---|
| 256 | |
---|
[697] | 257 | registryIn=new CRegistry(intraComm); |
---|
| 258 | registryIn->setPath(getId()) ; |
---|
| 259 | if (client->clientRank==0) registryIn->fromFile("xios_registry.bin") ; |
---|
| 260 | registryIn->bcastRegistry() ; |
---|
| 261 | |
---|
| 262 | registryOut=new CRegistry(intraComm) ; |
---|
| 263 | registryOut->setPath(getId()) ; |
---|
| 264 | |
---|
[1134] | 265 | ep_lib::MPI_Comm intraCommServer, interCommServer; |
---|
[597] | 266 | if (cxtServer) // Attached mode |
---|
| 267 | { |
---|
| 268 | intraCommServer = intraComm; |
---|
| 269 | interCommServer = interComm; |
---|
| 270 | } |
---|
| 271 | else |
---|
| 272 | { |
---|
| 273 | MPI_Comm_dup(intraComm, &intraCommServer); |
---|
[655] | 274 | comms.push_back(intraCommServer); |
---|
[597] | 275 | MPI_Comm_dup(interComm, &interCommServer); |
---|
[655] | 276 | comms.push_back(interCommServer); |
---|
[597] | 277 | } |
---|
| 278 | server = new CContextServer(this,intraCommServer,interCommServer); |
---|
[509] | 279 | } |
---|
[219] | 280 | |
---|
[509] | 281 | void CContext::setClientServerBuffer() |
---|
| 282 | { |
---|
[1205] | 283 | // Estimated minimum event size for small events (10 is an arbitrary constant just for safety) |
---|
| 284 | const size_t minEventSize = CEventClient::headerSize + getIdServer().size() + 10 * sizeof(int); |
---|
| 285 | // Ensure there is at least some room for 20 of such events in the buffers |
---|
| 286 | size_t minBufferSize = std::max(CXios::minBufferSize, 20 * minEventSize); |
---|
[583] | 287 | #define DECLARE_NODE(Name_, name_) \ |
---|
[731] | 288 | if (minBufferSize < sizeof(C##Name_##Definition)) minBufferSize = sizeof(C##Name_##Definition); |
---|
[583] | 289 | #define DECLARE_NODE_PAR(Name_, name_) |
---|
| 290 | #include "node_type.conf" |
---|
[719] | 291 | #undef DECLARE_NODE |
---|
| 292 | #undef DECLARE_NODE_PAR |
---|
| 293 | |
---|
[1205] | 294 | // Compute the buffer sizes needed to send the attributes and data corresponding to fields |
---|
[917] | 295 | std::map<int, StdSize> maxEventSize; |
---|
| 296 | std::map<int, StdSize> bufferSize = getAttributesBufferSize(maxEventSize); |
---|
| 297 | std::map<int, StdSize> dataBufferSize = getDataBufferSize(maxEventSize); |
---|
[729] | 298 | |
---|
[909] | 299 | std::map<int, StdSize>::iterator it, ite = dataBufferSize.end(); |
---|
[731] | 300 | for (it = dataBufferSize.begin(); it != ite; ++it) |
---|
| 301 | if (it->second > bufferSize[it->first]) bufferSize[it->first] = it->second; |
---|
| 302 | |
---|
[1205] | 303 | // Apply the buffer size factor and check that we are above the minimum buffer size |
---|
[909] | 304 | ite = bufferSize.end(); |
---|
| 305 | for (it = bufferSize.begin(); it != ite; ++it) |
---|
| 306 | { |
---|
| 307 | it->second *= CXios::bufferSizeFactor; |
---|
| 308 | if (it->second < minBufferSize) it->second = minBufferSize; |
---|
| 309 | } |
---|
| 310 | |
---|
[1205] | 311 | // Leaders will have to send some control events so ensure there is some room for those in the buffers |
---|
[729] | 312 | if (client->isServerLeader()) |
---|
[598] | 313 | { |
---|
[729] | 314 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
| 315 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
[1205] | 316 | { |
---|
| 317 | if (!bufferSize.count(*itRank)) |
---|
| 318 | { |
---|
| 319 | bufferSize[*itRank] = minBufferSize; |
---|
| 320 | maxEventSize[*itRank] = minEventSize; |
---|
| 321 | } |
---|
| 322 | } |
---|
[598] | 323 | } |
---|
[584] | 324 | |
---|
[917] | 325 | client->setBufferSize(bufferSize, maxEventSize); |
---|
[509] | 326 | } |
---|
| 327 | |
---|
| 328 | //! Verify whether a context is initialized |
---|
[461] | 329 | bool CContext::isInitialized(void) |
---|
| 330 | { |
---|
[549] | 331 | return hasClient; |
---|
[461] | 332 | } |
---|
[509] | 333 | |
---|
| 334 | //! Initialize server |
---|
[1134] | 335 | void CContext::initServer(ep_lib::MPI_Comm intraComm, ep_lib::MPI_Comm interComm, CContext* cxtClient /*= 0*/) |
---|
[300] | 336 | { |
---|
[549] | 337 | hasServer=true; |
---|
| 338 | server = new CContextServer(this,intraComm,interComm); |
---|
[697] | 339 | |
---|
| 340 | registryIn=new CRegistry(intraComm); |
---|
| 341 | registryIn->setPath(getId()) ; |
---|
| 342 | if (server->intraCommRank==0) registryIn->fromFile("xios_registry.bin") ; |
---|
| 343 | registryIn->bcastRegistry() ; |
---|
| 344 | registryOut=new CRegistry(intraComm) ; |
---|
| 345 | registryOut->setPath(getId()) ; |
---|
[775] | 346 | |
---|
[1134] | 347 | ep_lib::MPI_Comm intraCommClient, interCommClient; |
---|
[597] | 348 | if (cxtClient) // Attached mode |
---|
| 349 | { |
---|
| 350 | intraCommClient = intraComm; |
---|
| 351 | interCommClient = interComm; |
---|
| 352 | } |
---|
| 353 | else |
---|
| 354 | { |
---|
| 355 | MPI_Comm_dup(intraComm, &intraCommClient); |
---|
[655] | 356 | comms.push_back(intraCommClient); |
---|
[597] | 357 | MPI_Comm_dup(interComm, &interCommClient); |
---|
[655] | 358 | comms.push_back(interCommClient); |
---|
[597] | 359 | } |
---|
| 360 | client = new CContextClient(this,intraCommClient,interCommClient, cxtClient); |
---|
[509] | 361 | } |
---|
[300] | 362 | |
---|
[597] | 363 | //! Try to send the buffers and receive possible answers |
---|
| 364 | bool CContext::checkBuffersAndListen(void) |
---|
| 365 | { |
---|
| 366 | client->checkBuffers(); |
---|
[1033] | 367 | |
---|
| 368 | bool hasTmpBufferedEvent = client->hasTemporarilyBufferedEvent(); |
---|
| 369 | if (hasTmpBufferedEvent) |
---|
| 370 | hasTmpBufferedEvent = !client->sendTemporarilyBufferedEvent(); |
---|
| 371 | |
---|
| 372 | // Don't process events if there is a temporarily buffered event |
---|
| 373 | return server->eventLoop(!hasTmpBufferedEvent); |
---|
[597] | 374 | } |
---|
| 375 | |
---|
[509] | 376 | //! Terminate a context |
---|
[300] | 377 | void CContext::finalize(void) |
---|
| 378 | { |
---|
[597] | 379 | if (!finalized) |
---|
[300] | 380 | { |
---|
[597] | 381 | finalized = true; |
---|
[697] | 382 | if (hasClient) sendRegistry() ; |
---|
[597] | 383 | client->finalize(); |
---|
| 384 | while (!server->hasFinished()) |
---|
| 385 | { |
---|
| 386 | server->eventLoop(); |
---|
| 387 | } |
---|
| 388 | |
---|
| 389 | if (hasServer) |
---|
| 390 | { |
---|
| 391 | closeAllFile(); |
---|
[697] | 392 | registryOut->hierarchicalGatherRegistry() ; |
---|
| 393 | if (server->intraCommRank==0) CXios::globalRegistry->mergeRegistry(*registryOut) ; |
---|
[597] | 394 | } |
---|
[775] | 395 | |
---|
[1134] | 396 | for (std::list<ep_lib::MPI_Comm>::iterator it = comms.begin(); it != comms.end(); ++it) |
---|
[655] | 397 | MPI_Comm_free(&(*it)); |
---|
| 398 | comms.clear(); |
---|
[300] | 399 | } |
---|
| 400 | } |
---|
[509] | 401 | |
---|
| 402 | /*! |
---|
| 403 | \brief Close all the context defintion and do processing data |
---|
| 404 | After everything is well defined on client side, they will be processed and sent to server |
---|
| 405 | From the version 2.0, sever and client work no more on the same database. Moreover, client(s) will send |
---|
| 406 | all necessary information to server, from which each server can build its own database. |
---|
| 407 | Because the role of server is to write out field data on a specific netcdf file, |
---|
| 408 | the only information that it needs is the enabled files |
---|
| 409 | and the active fields (fields will be written onto active files) |
---|
| 410 | */ |
---|
[300] | 411 | void CContext::closeDefinition(void) |
---|
| 412 | { |
---|
[1205] | 413 | CTimer::get("Context : close definition").resume() ; |
---|
[584] | 414 | // There is nothing client need to send to server |
---|
[510] | 415 | if (hasClient) |
---|
[509] | 416 | { |
---|
| 417 | // After xml is parsed, there are some more works with post processing |
---|
| 418 | postProcessing(); |
---|
[510] | 419 | } |
---|
[598] | 420 | setClientServerBuffer(); |
---|
[300] | 421 | |
---|
[510] | 422 | if (hasClient && !hasServer) |
---|
| 423 | { |
---|
[509] | 424 | // Send all attributes of current context to server |
---|
| 425 | this->sendAllAttributesToServer(); |
---|
[459] | 426 | |
---|
[549] | 427 | // Send all attributes of current calendar |
---|
| 428 | CCalendarWrapper::get(CCalendarWrapper::GetDefName())->sendAllAttributesToServer(); |
---|
| 429 | |
---|
[509] | 430 | // We have enough information to send to server |
---|
| 431 | // First of all, send all enabled files |
---|
| 432 | sendEnabledFiles(); |
---|
| 433 | |
---|
| 434 | // Then, send all enabled fields |
---|
| 435 | sendEnabledFields(); |
---|
| 436 | |
---|
[540] | 437 | // At last, we have all info of domain and axis, then send them |
---|
[569] | 438 | sendRefDomainsAxis(); |
---|
[540] | 439 | |
---|
[509] | 440 | // After that, send all grid (if any) |
---|
| 441 | sendRefGrid(); |
---|
| 442 | } |
---|
| 443 | |
---|
| 444 | // We have a xml tree on the server side and now, it should be also processed |
---|
| 445 | if (hasClient && !hasServer) sendPostProcessing(); |
---|
| 446 | |
---|
| 447 | // There are some processings that should be done after all of above. For example: check mask or index |
---|
[510] | 448 | if (hasClient) |
---|
[509] | 449 | { |
---|
[640] | 450 | this->buildFilterGraphOfEnabledFields(); |
---|
| 451 | buildFilterGraphOfFieldsWithReadAccess(); |
---|
[509] | 452 | this->solveAllRefOfEnabledFields(true); |
---|
| 453 | } |
---|
| 454 | |
---|
[598] | 455 | // Now tell server that it can process all messages from client |
---|
| 456 | if (hasClient && !hasServer) this->sendCloseDefinition(); |
---|
[510] | 457 | |
---|
[584] | 458 | // Nettoyage de l'arborescence |
---|
| 459 | if (hasClient && !hasServer) CleanTree(); // Only on client side?? |
---|
[510] | 460 | |
---|
[598] | 461 | if (hasClient) |
---|
| 462 | { |
---|
| 463 | sendCreateFileHeader(); |
---|
| 464 | |
---|
| 465 | startPrefetchingOfEnabledReadModeFiles(); |
---|
| 466 | } |
---|
[1205] | 467 | CTimer::get("Context : close definition").suspend() ; |
---|
[300] | 468 | } |
---|
[509] | 469 | |
---|
[300] | 470 | void CContext::findAllEnabledFields(void) |
---|
| 471 | { |
---|
| 472 | for (unsigned int i = 0; i < this->enabledFiles.size(); i++) |
---|
| 473 | (void)this->enabledFiles[i]->getEnabledFields(); |
---|
| 474 | } |
---|
| 475 | |
---|
[775] | 476 | void CContext::findAllEnabledFieldsInReadModeFiles(void) |
---|
| 477 | { |
---|
| 478 | for (unsigned int i = 0; i < this->enabledReadModeFiles.size(); ++i) |
---|
| 479 | (void)this->enabledReadModeFiles[i]->getEnabledFields(); |
---|
| 480 | } |
---|
| 481 | |
---|
| 482 | void CContext::readAttributesOfEnabledFieldsInReadModeFiles() |
---|
| 483 | { |
---|
| 484 | for (unsigned int i = 0; i < this->enabledReadModeFiles.size(); ++i) |
---|
| 485 | (void)this->enabledReadModeFiles[i]->readAttributesOfEnabledFieldsInReadMode(); |
---|
| 486 | } |
---|
| 487 | |
---|
[823] | 488 | void CContext::solveOnlyRefOfEnabledFields(bool sendToServer) |
---|
| 489 | { |
---|
| 490 | int size = this->enabledFiles.size(); |
---|
| 491 | for (int i = 0; i < size; ++i) |
---|
| 492 | { |
---|
| 493 | this->enabledFiles[i]->solveOnlyRefOfEnabledFields(sendToServer); |
---|
| 494 | } |
---|
| 495 | |
---|
| 496 | for (int i = 0; i < size; ++i) |
---|
| 497 | { |
---|
| 498 | this->enabledFiles[i]->generateNewTransformationGridDest(); |
---|
| 499 | } |
---|
| 500 | } |
---|
| 501 | |
---|
[509] | 502 | void CContext::solveAllRefOfEnabledFields(bool sendToServer) |
---|
[300] | 503 | { |
---|
[509] | 504 | int size = this->enabledFiles.size(); |
---|
| 505 | for (int i = 0; i < size; ++i) |
---|
| 506 | { |
---|
| 507 | this->enabledFiles[i]->solveAllRefOfEnabledFields(sendToServer); |
---|
| 508 | } |
---|
[300] | 509 | } |
---|
| 510 | |
---|
[640] | 511 | void CContext::buildFilterGraphOfEnabledFields() |
---|
| 512 | { |
---|
| 513 | int size = this->enabledFiles.size(); |
---|
| 514 | for (int i = 0; i < size; ++i) |
---|
| 515 | { |
---|
| 516 | this->enabledFiles[i]->buildFilterGraphOfEnabledFields(garbageCollector); |
---|
| 517 | } |
---|
| 518 | } |
---|
| 519 | |
---|
[598] | 520 | void CContext::startPrefetchingOfEnabledReadModeFiles() |
---|
| 521 | { |
---|
| 522 | int size = enabledReadModeFiles.size(); |
---|
| 523 | for (int i = 0; i < size; ++i) |
---|
| 524 | { |
---|
| 525 | enabledReadModeFiles[i]->prefetchEnabledReadModeFields(); |
---|
| 526 | } |
---|
| 527 | } |
---|
| 528 | |
---|
| 529 | void CContext::checkPrefetchingOfEnabledReadModeFiles() |
---|
| 530 | { |
---|
| 531 | int size = enabledReadModeFiles.size(); |
---|
| 532 | for (int i = 0; i < size; ++i) |
---|
| 533 | { |
---|
| 534 | enabledReadModeFiles[i]->prefetchEnabledReadModeFieldsIfNeeded(); |
---|
| 535 | } |
---|
| 536 | } |
---|
| 537 | |
---|
[593] | 538 | void CContext::findFieldsWithReadAccess(void) |
---|
| 539 | { |
---|
| 540 | fieldsWithReadAccess.clear(); |
---|
| 541 | const vector<CField*> allFields = CField::getAll(); |
---|
| 542 | for (size_t i = 0; i < allFields.size(); ++i) |
---|
| 543 | { |
---|
[740] | 544 | CField* field = allFields[i]; |
---|
| 545 | |
---|
| 546 | if (field->file && !field->file->mode.isEmpty() && field->file->mode == CFile::mode_attr::read) |
---|
| 547 | field->read_access = true; |
---|
| 548 | else if (!field->read_access.isEmpty() && field->read_access && (field->enabled.isEmpty() || field->enabled)) |
---|
| 549 | fieldsWithReadAccess.push_back(field); |
---|
[593] | 550 | } |
---|
| 551 | } |
---|
| 552 | |
---|
| 553 | void CContext::solveAllRefOfFieldsWithReadAccess() |
---|
| 554 | { |
---|
| 555 | for (size_t i = 0; i < fieldsWithReadAccess.size(); ++i) |
---|
| 556 | fieldsWithReadAccess[i]->solveAllReferenceEnabledField(false); |
---|
| 557 | } |
---|
| 558 | |
---|
[640] | 559 | void CContext::buildFilterGraphOfFieldsWithReadAccess() |
---|
| 560 | { |
---|
| 561 | for (size_t i = 0; i < fieldsWithReadAccess.size(); ++i) |
---|
| 562 | fieldsWithReadAccess[i]->buildFilterGraph(garbageCollector, true); |
---|
| 563 | } |
---|
| 564 | |
---|
[445] | 565 | void CContext::solveAllInheritance(bool apply) |
---|
[300] | 566 | { |
---|
[1146] | 567 | // Rsolution des hritages descendants (cd des hritages de groupes) |
---|
[300] | 568 | // pour chacun des contextes. |
---|
[445] | 569 | solveDescInheritance(apply); |
---|
[300] | 570 | |
---|
[1146] | 571 | // Rsolution des hritages par rfrence au niveau des fichiers. |
---|
[549] | 572 | const vector<CFile*> allFiles=CFile::getAll(); |
---|
[540] | 573 | const vector<CGrid*> allGrids= CGrid::getAll(); |
---|
[300] | 574 | |
---|
[510] | 575 | //if (hasClient && !hasServer) |
---|
| 576 | if (hasClient) |
---|
[540] | 577 | { |
---|
[510] | 578 | for (unsigned int i = 0; i < allFiles.size(); i++) |
---|
| 579 | allFiles[i]->solveFieldRefInheritance(apply); |
---|
[540] | 580 | } |
---|
| 581 | |
---|
| 582 | unsigned int vecSize = allGrids.size(); |
---|
| 583 | unsigned int i = 0; |
---|
| 584 | for (i = 0; i < vecSize; ++i) |
---|
| 585 | allGrids[i]->solveDomainAxisRefInheritance(apply); |
---|
| 586 | |
---|
[300] | 587 | } |
---|
| 588 | |
---|
| 589 | void CContext::findEnabledFiles(void) |
---|
| 590 | { |
---|
[347] | 591 | const std::vector<CFile*> allFiles = CFile::getAll(); |
---|
[1028] | 592 | const CDate& initDate = calendar->getInitDate(); |
---|
[300] | 593 | |
---|
| 594 | for (unsigned int i = 0; i < allFiles.size(); i++) |
---|
[1146] | 595 | if (!allFiles[i]->enabled.isEmpty()) // Si l'attribut 'enabled' est dfini. |
---|
[430] | 596 | { |
---|
[1146] | 597 | if (allFiles[i]->enabled.getValue()) // Si l'attribut 'enabled' est fix vrai. |
---|
[1015] | 598 | { |
---|
[1028] | 599 | if ((initDate + allFiles[i]->output_freq.getValue()) < (initDate + this->getCalendar()->getTimeStep())) |
---|
[1015] | 600 | { |
---|
| 601 | error(0)<<"WARNING: void CContext::findEnabledFiles()"<<endl |
---|
[1028] | 602 | << "Output frequency in file \""<<allFiles[i]->getFileOutputName() |
---|
| 603 | <<"\" is less than the time step. File will not be written."<<endl; |
---|
[1015] | 604 | } |
---|
| 605 | else |
---|
[300] | 606 | enabledFiles.push_back(allFiles[i]); |
---|
[1015] | 607 | } |
---|
[430] | 608 | } |
---|
[1015] | 609 | else |
---|
| 610 | { |
---|
[1028] | 611 | if ( (initDate + allFiles[i]->output_freq.getValue()) < (initDate + this->getCalendar()->getTimeStep())) |
---|
[1015] | 612 | { |
---|
| 613 | error(0)<<"WARNING: void CContext::findEnabledFiles()"<<endl |
---|
[1028] | 614 | << "Output frequency in file \""<<allFiles[i]->getFileOutputName() |
---|
| 615 | <<"\" is less than the time step. File will not be written."<<endl; |
---|
[1015] | 616 | } |
---|
| 617 | else |
---|
| 618 | enabledFiles.push_back(allFiles[i]); // otherwise true by default |
---|
| 619 | } |
---|
[300] | 620 | |
---|
| 621 | if (enabledFiles.size() == 0) |
---|
[1146] | 622 | DEBUG(<<"Aucun fichier ne va tre sorti dans le contexte nomm \"" |
---|
[300] | 623 | << getId() << "\" !"); |
---|
| 624 | } |
---|
| 625 | |
---|
[598] | 626 | void CContext::findEnabledReadModeFiles(void) |
---|
| 627 | { |
---|
| 628 | int size = this->enabledFiles.size(); |
---|
| 629 | for (int i = 0; i < size; ++i) |
---|
| 630 | { |
---|
| 631 | if (!enabledFiles[i]->mode.isEmpty() && enabledFiles[i]->mode.getValue() == CFile::mode_attr::read) |
---|
| 632 | enabledReadModeFiles.push_back(enabledFiles[i]); |
---|
| 633 | } |
---|
| 634 | } |
---|
| 635 | |
---|
[300] | 636 | void CContext::closeAllFile(void) |
---|
| 637 | { |
---|
[347] | 638 | std::vector<CFile*>::const_iterator |
---|
[300] | 639 | it = this->enabledFiles.begin(), end = this->enabledFiles.end(); |
---|
[509] | 640 | |
---|
[300] | 641 | for (; it != end; it++) |
---|
| 642 | { |
---|
| 643 | info(30)<<"Closing File : "<<(*it)->getId()<<endl; |
---|
| 644 | (*it)->close(); |
---|
| 645 | } |
---|
| 646 | } |
---|
[509] | 647 | |
---|
| 648 | /*! |
---|
| 649 | \brief Dispatch event received from client |
---|
| 650 | Whenever a message is received in buffer of server, it will be processed depending on |
---|
| 651 | its event type. A new event type should be added in the switch list to make sure |
---|
| 652 | it processed on server side. |
---|
| 653 | \param [in] event: Received message |
---|
| 654 | */ |
---|
[300] | 655 | bool CContext::dispatchEvent(CEventServer& event) |
---|
| 656 | { |
---|
[509] | 657 | |
---|
[549] | 658 | if (SuperClass::dispatchEvent(event)) return true; |
---|
[300] | 659 | else |
---|
| 660 | { |
---|
| 661 | switch(event.type) |
---|
| 662 | { |
---|
| 663 | case EVENT_ID_CLOSE_DEFINITION : |
---|
[549] | 664 | recvCloseDefinition(event); |
---|
| 665 | return true; |
---|
| 666 | break; |
---|
[584] | 667 | case EVENT_ID_UPDATE_CALENDAR: |
---|
[549] | 668 | recvUpdateCalendar(event); |
---|
| 669 | return true; |
---|
| 670 | break; |
---|
[300] | 671 | case EVENT_ID_CREATE_FILE_HEADER : |
---|
[549] | 672 | recvCreateFileHeader(event); |
---|
| 673 | return true; |
---|
| 674 | break; |
---|
[509] | 675 | case EVENT_ID_POST_PROCESS: |
---|
[549] | 676 | recvPostProcessing(event); |
---|
| 677 | return true; |
---|
[697] | 678 | case EVENT_ID_SEND_REGISTRY: |
---|
| 679 | recvRegistry(event); |
---|
| 680 | return true; |
---|
| 681 | break; |
---|
[584] | 682 | |
---|
[300] | 683 | default : |
---|
| 684 | ERROR("bool CContext::dispatchEvent(CEventServer& event)", |
---|
[549] | 685 | <<"Unknown Event"); |
---|
| 686 | return false; |
---|
[300] | 687 | } |
---|
| 688 | } |
---|
| 689 | } |
---|
[509] | 690 | |
---|
| 691 | //! Client side: Send a message to server to make it close |
---|
[300] | 692 | void CContext::sendCloseDefinition(void) |
---|
| 693 | { |
---|
[549] | 694 | CEventClient event(getType(),EVENT_ID_CLOSE_DEFINITION); |
---|
[300] | 695 | if (client->isServerLeader()) |
---|
| 696 | { |
---|
[549] | 697 | CMessage msg; |
---|
| 698 | msg<<this->getIdServer(); |
---|
[595] | 699 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
| 700 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 701 | event.push(*itRank,1,msg); |
---|
[549] | 702 | client->sendEvent(event); |
---|
[300] | 703 | } |
---|
[549] | 704 | else client->sendEvent(event); |
---|
[300] | 705 | } |
---|
[509] | 706 | |
---|
| 707 | //! Server side: Receive a message of client announcing a context close |
---|
[300] | 708 | void CContext::recvCloseDefinition(CEventServer& event) |
---|
| 709 | { |
---|
[509] | 710 | |
---|
[300] | 711 | CBufferIn* buffer=event.subEvents.begin()->buffer; |
---|
| 712 | string id; |
---|
[549] | 713 | *buffer>>id; |
---|
[509] | 714 | get(id)->closeDefinition(); |
---|
[300] | 715 | } |
---|
[509] | 716 | |
---|
| 717 | //! Client side: Send a message to update calendar in each time step |
---|
[300] | 718 | void CContext::sendUpdateCalendar(int step) |
---|
| 719 | { |
---|
| 720 | if (!hasServer) |
---|
| 721 | { |
---|
[549] | 722 | CEventClient event(getType(),EVENT_ID_UPDATE_CALENDAR); |
---|
[300] | 723 | if (client->isServerLeader()) |
---|
| 724 | { |
---|
[549] | 725 | CMessage msg; |
---|
| 726 | msg<<this->getIdServer()<<step; |
---|
[595] | 727 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
| 728 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 729 | event.push(*itRank,1,msg); |
---|
[549] | 730 | client->sendEvent(event); |
---|
[300] | 731 | } |
---|
[549] | 732 | else client->sendEvent(event); |
---|
[300] | 733 | } |
---|
| 734 | } |
---|
[509] | 735 | |
---|
| 736 | //! Server side: Receive a message of client annoucing calendar update |
---|
[300] | 737 | void CContext::recvUpdateCalendar(CEventServer& event) |
---|
| 738 | { |
---|
| 739 | CBufferIn* buffer=event.subEvents.begin()->buffer; |
---|
| 740 | string id; |
---|
[549] | 741 | *buffer>>id; |
---|
| 742 | get(id)->recvUpdateCalendar(*buffer); |
---|
[300] | 743 | } |
---|
[509] | 744 | |
---|
| 745 | //! Server side: Receive a message of client annoucing calendar update |
---|
[300] | 746 | void CContext::recvUpdateCalendar(CBufferIn& buffer) |
---|
| 747 | { |
---|
[549] | 748 | int step; |
---|
| 749 | buffer>>step; |
---|
| 750 | updateCalendar(step); |
---|
[300] | 751 | } |
---|
[509] | 752 | |
---|
| 753 | //! Client side: Send a message to create header part of netcdf file |
---|
[300] | 754 | void CContext::sendCreateFileHeader(void) |
---|
| 755 | { |
---|
[549] | 756 | CEventClient event(getType(),EVENT_ID_CREATE_FILE_HEADER); |
---|
[300] | 757 | if (client->isServerLeader()) |
---|
| 758 | { |
---|
[549] | 759 | CMessage msg; |
---|
| 760 | msg<<this->getIdServer(); |
---|
[595] | 761 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
| 762 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 763 | event.push(*itRank,1,msg) ; |
---|
[549] | 764 | client->sendEvent(event); |
---|
[300] | 765 | } |
---|
[549] | 766 | else client->sendEvent(event); |
---|
[300] | 767 | } |
---|
[509] | 768 | |
---|
| 769 | //! Server side: Receive a message of client annoucing the creation of header part of netcdf file |
---|
[300] | 770 | void CContext::recvCreateFileHeader(CEventServer& event) |
---|
| 771 | { |
---|
| 772 | CBufferIn* buffer=event.subEvents.begin()->buffer; |
---|
| 773 | string id; |
---|
[549] | 774 | *buffer>>id; |
---|
| 775 | get(id)->recvCreateFileHeader(*buffer); |
---|
[300] | 776 | } |
---|
[509] | 777 | |
---|
| 778 | //! Server side: Receive a message of client annoucing the creation of header part of netcdf file |
---|
[300] | 779 | void CContext::recvCreateFileHeader(CBufferIn& buffer) |
---|
| 780 | { |
---|
[549] | 781 | createFileHeader(); |
---|
[300] | 782 | } |
---|
[509] | 783 | |
---|
| 784 | //! Client side: Send a message to do some post processing on server |
---|
| 785 | void CContext::sendPostProcessing() |
---|
| 786 | { |
---|
| 787 | if (!hasServer) |
---|
| 788 | { |
---|
[549] | 789 | CEventClient event(getType(),EVENT_ID_POST_PROCESS); |
---|
[509] | 790 | if (client->isServerLeader()) |
---|
| 791 | { |
---|
[549] | 792 | CMessage msg; |
---|
[511] | 793 | msg<<this->getIdServer(); |
---|
[595] | 794 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
| 795 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 796 | event.push(*itRank,1,msg); |
---|
[549] | 797 | client->sendEvent(event); |
---|
[509] | 798 | } |
---|
[549] | 799 | else client->sendEvent(event); |
---|
[509] | 800 | } |
---|
| 801 | } |
---|
| 802 | |
---|
| 803 | //! Server side: Receive a message to do some post processing |
---|
| 804 | void CContext::recvPostProcessing(CEventServer& event) |
---|
| 805 | { |
---|
| 806 | CBufferIn* buffer=event.subEvents.begin()->buffer; |
---|
| 807 | string id; |
---|
| 808 | *buffer>>id; |
---|
| 809 | get(id)->recvPostProcessing(*buffer); |
---|
| 810 | } |
---|
| 811 | |
---|
| 812 | //! Server side: Receive a message to do some post processing |
---|
| 813 | void CContext::recvPostProcessing(CBufferIn& buffer) |
---|
| 814 | { |
---|
[549] | 815 | CCalendarWrapper::get(CCalendarWrapper::GetDefName())->createCalendar(); |
---|
[509] | 816 | postProcessing(); |
---|
| 817 | } |
---|
| 818 | |
---|
[511] | 819 | const StdString& CContext::getIdServer() |
---|
| 820 | { |
---|
| 821 | if (hasClient) |
---|
| 822 | { |
---|
| 823 | idServer_ = this->getId(); |
---|
| 824 | idServer_ += "_server"; |
---|
| 825 | return idServer_; |
---|
| 826 | } |
---|
| 827 | if (hasServer) return (this->getId()); |
---|
| 828 | } |
---|
| 829 | |
---|
[509] | 830 | /*! |
---|
| 831 | \brief Do some simple post processings after parsing xml file |
---|
| 832 | After the xml file (iodef.xml) is parsed, it is necessary to build all relations among |
---|
| 833 | created object, e.g: inhertance among fields, domain, axis. After that, all fiels as well as their parents (reference fields), |
---|
| 834 | which will be written out into netcdf files, are processed |
---|
| 835 | */ |
---|
| 836 | void CContext::postProcessing() |
---|
| 837 | { |
---|
[1134] | 838 | int myRank; |
---|
| 839 | MPI_Comm_rank(MPI_COMM_WORLD, &myRank); |
---|
| 840 | |
---|
[509] | 841 | if (isPostProcessed) return; |
---|
| 842 | |
---|
[549] | 843 | // Make sure the calendar was correctly created |
---|
| 844 | if (!calendar) |
---|
| 845 | ERROR("CContext::postProcessing()", << "A calendar must be defined for the context \"" << getId() << "!\"") |
---|
| 846 | else if (calendar->getTimeStep() == NoneDu) |
---|
| 847 | ERROR("CContext::postProcessing()", << "A timestep must be defined for the context \"" << getId() << "!\"") |
---|
[550] | 848 | // Calendar first update to set the current date equals to the start date |
---|
| 849 | calendar->update(0); |
---|
[509] | 850 | |
---|
| 851 | // Find all inheritance in xml structure |
---|
| 852 | this->solveAllInheritance(); |
---|
| 853 | |
---|
[676] | 854 | // Check if some axis, domains or grids are eligible to for compressed indexed output. |
---|
| 855 | // Warning: This must be done after solving the inheritance and before the rest of post-processing |
---|
| 856 | checkAxisDomainsGridsEligibilityForCompressedOutput(); |
---|
| 857 | |
---|
[711] | 858 | // Check if some automatic time series should be generated |
---|
| 859 | // Warning: This must be done after solving the inheritance and before the rest of post-processing |
---|
| 860 | prepareTimeseries(); |
---|
| 861 | |
---|
[1146] | 862 | //Initialisation du vecteur 'enabledFiles' contenant la liste des fichiers sortir. |
---|
[509] | 863 | this->findEnabledFiles(); |
---|
[598] | 864 | this->findEnabledReadModeFiles(); |
---|
[509] | 865 | |
---|
| 866 | // Find all enabled fields of each file |
---|
| 867 | this->findAllEnabledFields(); |
---|
[775] | 868 | this->findAllEnabledFieldsInReadModeFiles(); |
---|
[509] | 869 | |
---|
[775] | 870 | if (hasClient && !hasServer) |
---|
| 871 | { |
---|
| 872 | // Try to read attributes of fields in file then fill in corresponding grid (or domain, axis) |
---|
| 873 | this->readAttributesOfEnabledFieldsInReadModeFiles(); |
---|
| 874 | } |
---|
[823] | 875 | |
---|
| 876 | // Only search and rebuild all reference objects of enable fields, don't transform |
---|
| 877 | this->solveOnlyRefOfEnabledFields(false); |
---|
| 878 | |
---|
[509] | 879 | // Search and rebuild all reference object of enabled fields |
---|
| 880 | this->solveAllRefOfEnabledFields(false); |
---|
[593] | 881 | |
---|
| 882 | // Find all fields with read access from the public API |
---|
| 883 | findFieldsWithReadAccess(); |
---|
| 884 | // and solve the all reference for them |
---|
| 885 | solveAllRefOfFieldsWithReadAccess(); |
---|
| 886 | |
---|
[509] | 887 | isPostProcessed = true; |
---|
| 888 | } |
---|
| 889 | |
---|
[917] | 890 | /*! |
---|
| 891 | * Compute the required buffer size to send the attributes (mostly those grid related). |
---|
| 892 | * |
---|
| 893 | * \param maxEventSize [in/out] the size of the bigger event for each connected server |
---|
| 894 | */ |
---|
| 895 | std::map<int, StdSize> CContext::getAttributesBufferSize(std::map<int, StdSize>& maxEventSize) |
---|
[509] | 896 | { |
---|
[731] | 897 | std::map<int, StdSize> attributesSize; |
---|
| 898 | |
---|
[908] | 899 | if (hasClient) |
---|
[731] | 900 | { |
---|
[908] | 901 | size_t numEnabledFiles = this->enabledFiles.size(); |
---|
| 902 | for (size_t i = 0; i < numEnabledFiles; ++i) |
---|
| 903 | { |
---|
| 904 | CFile* file = this->enabledFiles[i]; |
---|
[731] | 905 | |
---|
[908] | 906 | std::vector<CField*> enabledFields = file->getEnabledFields(); |
---|
| 907 | size_t numEnabledFields = enabledFields.size(); |
---|
| 908 | for (size_t j = 0; j < numEnabledFields; ++j) |
---|
[731] | 909 | { |
---|
[908] | 910 | const std::map<int, StdSize> mapSize = enabledFields[j]->getGridAttributesBufferSize(); |
---|
| 911 | std::map<int, StdSize>::const_iterator it = mapSize.begin(), itE = mapSize.end(); |
---|
| 912 | for (; it != itE; ++it) |
---|
| 913 | { |
---|
| 914 | // If attributesSize[it->first] does not exist, it will be zero-initialized |
---|
| 915 | // so we can use it safely without checking for its existance |
---|
| 916 | if (attributesSize[it->first] < it->second) |
---|
| 917 | attributesSize[it->first] = it->second; |
---|
[917] | 918 | |
---|
| 919 | if (maxEventSize[it->first] < it->second) |
---|
| 920 | maxEventSize[it->first] = it->second; |
---|
[908] | 921 | } |
---|
[731] | 922 | } |
---|
| 923 | } |
---|
| 924 | } |
---|
| 925 | |
---|
| 926 | return attributesSize; |
---|
| 927 | } |
---|
| 928 | |
---|
[917] | 929 | /*! |
---|
| 930 | * Compute the required buffer size to send the fields data. |
---|
| 931 | * |
---|
| 932 | * \param maxEventSize [in/out] the size of the bigger event for each connected server |
---|
| 933 | */ |
---|
| 934 | std::map<int, StdSize> CContext::getDataBufferSize(std::map<int, StdSize>& maxEventSize) |
---|
[731] | 935 | { |
---|
[598] | 936 | CFile::mode_attr::t_enum mode = hasClient ? CFile::mode_attr::write : CFile::mode_attr::read; |
---|
| 937 | |
---|
[730] | 938 | std::map<int, StdSize> dataSize; |
---|
[509] | 939 | |
---|
| 940 | // Find all reference domain and axis of all active fields |
---|
[730] | 941 | size_t numEnabledFiles = this->enabledFiles.size(); |
---|
| 942 | for (size_t i = 0; i < numEnabledFiles; ++i) |
---|
[509] | 943 | { |
---|
[598] | 944 | CFile* file = this->enabledFiles[i]; |
---|
| 945 | CFile::mode_attr::t_enum fileMode = file->mode.isEmpty() ? CFile::mode_attr::write : file->mode.getValue(); |
---|
| 946 | |
---|
| 947 | if (fileMode == mode) |
---|
[509] | 948 | { |
---|
[598] | 949 | std::vector<CField*> enabledFields = file->getEnabledFields(); |
---|
[730] | 950 | size_t numEnabledFields = enabledFields.size(); |
---|
| 951 | for (size_t j = 0; j < numEnabledFields; ++j) |
---|
[509] | 952 | { |
---|
[731] | 953 | const std::map<int, StdSize> mapSize = enabledFields[j]->getGridDataBufferSize(); |
---|
[730] | 954 | std::map<int, StdSize>::const_iterator it = mapSize.begin(), itE = mapSize.end(); |
---|
| 955 | for (; it != itE; ++it) |
---|
[509] | 956 | { |
---|
[730] | 957 | // If dataSize[it->first] does not exist, it will be zero-initialized |
---|
| 958 | // so we can use it safely without checking for its existance |
---|
| 959 | if (CXios::isOptPerformance) |
---|
| 960 | dataSize[it->first] += it->second; |
---|
| 961 | else if (dataSize[it->first] < it->second) |
---|
| 962 | dataSize[it->first] = it->second; |
---|
[917] | 963 | |
---|
| 964 | if (maxEventSize[it->first] < it->second) |
---|
| 965 | maxEventSize[it->first] = it->second; |
---|
[598] | 966 | } |
---|
[509] | 967 | } |
---|
| 968 | } |
---|
| 969 | } |
---|
| 970 | |
---|
[730] | 971 | return dataSize; |
---|
[509] | 972 | } |
---|
| 973 | |
---|
| 974 | //! Client side: Send infomation of active files (files are enabled to write out) |
---|
| 975 | void CContext::sendEnabledFiles() |
---|
| 976 | { |
---|
| 977 | int size = this->enabledFiles.size(); |
---|
| 978 | |
---|
| 979 | // In a context, each type has a root definition, e.g: axis, domain, field. |
---|
| 980 | // Every object must be a child of one of these root definition. In this case |
---|
| 981 | // all new file objects created on server must be children of the root "file_definition" |
---|
| 982 | StdString fileDefRoot("file_definition"); |
---|
| 983 | CFileGroup* cfgrpPtr = CFileGroup::get(fileDefRoot); |
---|
| 984 | |
---|
| 985 | for (int i = 0; i < size; ++i) |
---|
| 986 | { |
---|
| 987 | cfgrpPtr->sendCreateChild(this->enabledFiles[i]->getId()); |
---|
| 988 | this->enabledFiles[i]->sendAllAttributesToServer(); |
---|
| 989 | this->enabledFiles[i]->sendAddAllVariables(); |
---|
| 990 | } |
---|
| 991 | } |
---|
| 992 | |
---|
| 993 | //! Client side: Send information of active fields (ones are written onto files) |
---|
| 994 | void CContext::sendEnabledFields() |
---|
| 995 | { |
---|
| 996 | int size = this->enabledFiles.size(); |
---|
| 997 | for (int i = 0; i < size; ++i) |
---|
| 998 | { |
---|
| 999 | this->enabledFiles[i]->sendEnabledFields(); |
---|
| 1000 | } |
---|
| 1001 | } |
---|
| 1002 | |
---|
[676] | 1003 | //! Client side: Check if the defined axis, domains and grids are eligible for compressed indexed output |
---|
| 1004 | void CContext::checkAxisDomainsGridsEligibilityForCompressedOutput() |
---|
| 1005 | { |
---|
| 1006 | if (!hasClient) return; |
---|
| 1007 | |
---|
| 1008 | const vector<CAxis*> allAxis = CAxis::getAll(); |
---|
| 1009 | for (vector<CAxis*>::const_iterator it = allAxis.begin(); it != allAxis.end(); it++) |
---|
| 1010 | (*it)->checkEligibilityForCompressedOutput(); |
---|
| 1011 | |
---|
| 1012 | const vector<CDomain*> allDomains = CDomain::getAll(); |
---|
| 1013 | for (vector<CDomain*>::const_iterator it = allDomains.begin(); it != allDomains.end(); it++) |
---|
| 1014 | (*it)->checkEligibilityForCompressedOutput(); |
---|
| 1015 | |
---|
| 1016 | const vector<CGrid*> allGrids = CGrid::getAll(); |
---|
| 1017 | for (vector<CGrid*>::const_iterator it = allGrids.begin(); it != allGrids.end(); it++) |
---|
| 1018 | (*it)->checkEligibilityForCompressedOutput(); |
---|
| 1019 | } |
---|
| 1020 | |
---|
[711] | 1021 | //! Client side: Prepare the timeseries by adding the necessary files |
---|
| 1022 | void CContext::prepareTimeseries() |
---|
| 1023 | { |
---|
| 1024 | if (!hasClient) return; |
---|
| 1025 | |
---|
| 1026 | const std::vector<CFile*> allFiles = CFile::getAll(); |
---|
| 1027 | for (size_t i = 0; i < allFiles.size(); i++) |
---|
| 1028 | { |
---|
| 1029 | CFile* file = allFiles[i]; |
---|
| 1030 | |
---|
[1041] | 1031 | std::vector<CVariable*> fileVars, fieldVars, vars = file->getAllVariables(); |
---|
| 1032 | for (size_t k = 0; k < vars.size(); k++) |
---|
| 1033 | { |
---|
| 1034 | CVariable* var = vars[k]; |
---|
| 1035 | |
---|
| 1036 | if (var->ts_target.isEmpty() |
---|
| 1037 | || var->ts_target == CVariable::ts_target_attr::file || var->ts_target == CVariable::ts_target_attr::both) |
---|
| 1038 | fileVars.push_back(var); |
---|
| 1039 | |
---|
| 1040 | if (!var->ts_target.isEmpty() |
---|
| 1041 | && (var->ts_target == CVariable::ts_target_attr::field || var->ts_target == CVariable::ts_target_attr::both)) |
---|
| 1042 | fieldVars.push_back(var); |
---|
| 1043 | } |
---|
| 1044 | |
---|
[711] | 1045 | if (!file->timeseries.isEmpty() && file->timeseries != CFile::timeseries_attr::none) |
---|
| 1046 | { |
---|
[1091] | 1047 | StdString fileNameStr("%file_name%") ; |
---|
| 1048 | StdString tsPrefix = !file->ts_prefix.isEmpty() ? file->ts_prefix : fileNameStr ; |
---|
| 1049 | |
---|
| 1050 | StdString fileName=file->getFileOutputName(); |
---|
| 1051 | size_t pos=tsPrefix.find(fileNameStr) ; |
---|
| 1052 | while (pos!=std::string::npos) |
---|
| 1053 | { |
---|
| 1054 | tsPrefix=tsPrefix.replace(pos,fileNameStr.size(),fileName) ; |
---|
| 1055 | pos=tsPrefix.find(fileNameStr) ; |
---|
| 1056 | } |
---|
| 1057 | |
---|
[711] | 1058 | const std::vector<CField*> allFields = file->getAllFields(); |
---|
| 1059 | for (size_t j = 0; j < allFields.size(); j++) |
---|
| 1060 | { |
---|
| 1061 | CField* field = allFields[j]; |
---|
| 1062 | |
---|
| 1063 | if (!field->ts_enabled.isEmpty() && field->ts_enabled) |
---|
| 1064 | { |
---|
| 1065 | CFile* tsFile = CFile::create(); |
---|
| 1066 | tsFile->duplicateAttributes(file); |
---|
| 1067 | |
---|
[1041] | 1068 | // Add variables originating from file and targeted to timeserie file |
---|
| 1069 | for (size_t k = 0; k < fileVars.size(); k++) |
---|
| 1070 | tsFile->getVirtualVariableGroup()->addChild(fileVars[k]); |
---|
| 1071 | |
---|
[1091] | 1072 | |
---|
[711] | 1073 | tsFile->name = tsPrefix + "_"; |
---|
| 1074 | if (!field->name.isEmpty()) |
---|
| 1075 | tsFile->name.get() += field->name; |
---|
| 1076 | else if (field->hasDirectFieldReference()) // We cannot use getBaseFieldReference() just yet |
---|
| 1077 | tsFile->name.get() += field->field_ref; |
---|
| 1078 | else |
---|
| 1079 | tsFile->name.get() += field->getId(); |
---|
| 1080 | |
---|
| 1081 | if (!field->ts_split_freq.isEmpty()) |
---|
| 1082 | tsFile->split_freq = field->ts_split_freq; |
---|
| 1083 | |
---|
| 1084 | CField* tsField = tsFile->addField(); |
---|
| 1085 | tsField->field_ref = field->getId(); |
---|
| 1086 | |
---|
[1041] | 1087 | // Add variables originating from file and targeted to timeserie field |
---|
| 1088 | for (size_t k = 0; k < fieldVars.size(); k++) |
---|
| 1089 | tsField->getVirtualVariableGroup()->addChild(fieldVars[k]); |
---|
| 1090 | |
---|
| 1091 | vars = field->getAllVariables(); |
---|
| 1092 | for (size_t k = 0; k < vars.size(); k++) |
---|
| 1093 | { |
---|
| 1094 | CVariable* var = vars[k]; |
---|
| 1095 | |
---|
| 1096 | // Add variables originating from field and targeted to timeserie field |
---|
| 1097 | if (var->ts_target.isEmpty() |
---|
| 1098 | || var->ts_target == CVariable::ts_target_attr::field || var->ts_target == CVariable::ts_target_attr::both) |
---|
| 1099 | tsField->getVirtualVariableGroup()->addChild(var); |
---|
| 1100 | |
---|
| 1101 | // Add variables originating from field and targeted to timeserie file |
---|
| 1102 | if (!var->ts_target.isEmpty() |
---|
| 1103 | && (var->ts_target == CVariable::ts_target_attr::file || var->ts_target == CVariable::ts_target_attr::both)) |
---|
| 1104 | tsFile->getVirtualVariableGroup()->addChild(var); |
---|
| 1105 | } |
---|
| 1106 | |
---|
[711] | 1107 | tsFile->solveFieldRefInheritance(true); |
---|
| 1108 | |
---|
| 1109 | if (file->timeseries == CFile::timeseries_attr::exclusive) |
---|
| 1110 | field->enabled = false; |
---|
| 1111 | } |
---|
| 1112 | } |
---|
| 1113 | |
---|
| 1114 | // Finally disable the original file is need be |
---|
| 1115 | if (file->timeseries == CFile::timeseries_attr::only) |
---|
| 1116 | file->enabled = false; |
---|
| 1117 | } |
---|
| 1118 | } |
---|
| 1119 | } |
---|
| 1120 | |
---|
[509] | 1121 | //! Client side: Send information of reference grid of active fields |
---|
| 1122 | void CContext::sendRefGrid() |
---|
| 1123 | { |
---|
| 1124 | std::set<StdString> gridIds; |
---|
| 1125 | int sizeFile = this->enabledFiles.size(); |
---|
| 1126 | CFile* filePtr(NULL); |
---|
| 1127 | |
---|
| 1128 | // Firstly, find all reference grids of all active fields |
---|
| 1129 | for (int i = 0; i < sizeFile; ++i) |
---|
| 1130 | { |
---|
| 1131 | filePtr = this->enabledFiles[i]; |
---|
| 1132 | std::vector<CField*> enabledFields = filePtr->getEnabledFields(); |
---|
| 1133 | int sizeField = enabledFields.size(); |
---|
| 1134 | for (int numField = 0; numField < sizeField; ++numField) |
---|
| 1135 | { |
---|
| 1136 | if (0 != enabledFields[numField]->getRelGrid()) |
---|
| 1137 | gridIds.insert(CGrid::get(enabledFields[numField]->getRelGrid())->getId()); |
---|
| 1138 | } |
---|
| 1139 | } |
---|
| 1140 | |
---|
| 1141 | // Create all reference grids on server side |
---|
| 1142 | StdString gridDefRoot("grid_definition"); |
---|
| 1143 | CGridGroup* gridPtr = CGridGroup::get(gridDefRoot); |
---|
| 1144 | std::set<StdString>::const_iterator it, itE = gridIds.end(); |
---|
| 1145 | for (it = gridIds.begin(); it != itE; ++it) |
---|
| 1146 | { |
---|
| 1147 | gridPtr->sendCreateChild(*it); |
---|
| 1148 | CGrid::get(*it)->sendAllAttributesToServer(); |
---|
[540] | 1149 | CGrid::get(*it)->sendAllDomains(); |
---|
| 1150 | CGrid::get(*it)->sendAllAxis(); |
---|
[887] | 1151 | CGrid::get(*it)->sendAllScalars(); |
---|
[509] | 1152 | } |
---|
| 1153 | } |
---|
| 1154 | |
---|
| 1155 | |
---|
| 1156 | //! Client side: Send information of reference domain and axis of active fields |
---|
[569] | 1157 | void CContext::sendRefDomainsAxis() |
---|
| 1158 | { |
---|
[887] | 1159 | std::set<StdString> domainIds, axisIds, scalarIds; |
---|
[509] | 1160 | |
---|
[569] | 1161 | // Find all reference domain and axis of all active fields |
---|
| 1162 | int numEnabledFiles = this->enabledFiles.size(); |
---|
| 1163 | for (int i = 0; i < numEnabledFiles; ++i) |
---|
| 1164 | { |
---|
| 1165 | std::vector<CField*> enabledFields = this->enabledFiles[i]->getEnabledFields(); |
---|
| 1166 | int numEnabledFields = enabledFields.size(); |
---|
| 1167 | for (int j = 0; j < numEnabledFields; ++j) |
---|
| 1168 | { |
---|
[887] | 1169 | const std::vector<StdString>& prDomAxisScalarId = enabledFields[j]->getRefDomainAxisIds(); |
---|
| 1170 | if ("" != prDomAxisScalarId[0]) domainIds.insert(prDomAxisScalarId[0]); |
---|
| 1171 | if ("" != prDomAxisScalarId[1]) axisIds.insert(prDomAxisScalarId[1]); |
---|
| 1172 | if ("" != prDomAxisScalarId[2]) scalarIds.insert(prDomAxisScalarId[2]); |
---|
[569] | 1173 | } |
---|
| 1174 | } |
---|
| 1175 | |
---|
| 1176 | // Create all reference axis on server side |
---|
[887] | 1177 | std::set<StdString>::iterator itDom, itAxis, itScalar; |
---|
[569] | 1178 | std::set<StdString>::const_iterator itE; |
---|
| 1179 | |
---|
[887] | 1180 | StdString scalarDefRoot("scalar_definition"); |
---|
| 1181 | CScalarGroup* scalarPtr = CScalarGroup::get(scalarDefRoot); |
---|
| 1182 | itE = scalarIds.end(); |
---|
| 1183 | for (itScalar = scalarIds.begin(); itScalar != itE; ++itScalar) |
---|
| 1184 | { |
---|
| 1185 | if (!itScalar->empty()) |
---|
| 1186 | { |
---|
| 1187 | scalarPtr->sendCreateChild(*itScalar); |
---|
| 1188 | CScalar::get(*itScalar)->sendAllAttributesToServer(); |
---|
| 1189 | } |
---|
| 1190 | } |
---|
| 1191 | |
---|
[569] | 1192 | StdString axiDefRoot("axis_definition"); |
---|
| 1193 | CAxisGroup* axisPtr = CAxisGroup::get(axiDefRoot); |
---|
| 1194 | itE = axisIds.end(); |
---|
| 1195 | for (itAxis = axisIds.begin(); itAxis != itE; ++itAxis) |
---|
| 1196 | { |
---|
| 1197 | if (!itAxis->empty()) |
---|
| 1198 | { |
---|
| 1199 | axisPtr->sendCreateChild(*itAxis); |
---|
| 1200 | CAxis::get(*itAxis)->sendAllAttributesToServer(); |
---|
| 1201 | } |
---|
| 1202 | } |
---|
| 1203 | |
---|
| 1204 | // Create all reference domains on server side |
---|
| 1205 | StdString domDefRoot("domain_definition"); |
---|
| 1206 | CDomainGroup* domPtr = CDomainGroup::get(domDefRoot); |
---|
| 1207 | itE = domainIds.end(); |
---|
| 1208 | for (itDom = domainIds.begin(); itDom != itE; ++itDom) |
---|
| 1209 | { |
---|
| 1210 | if (!itDom->empty()) { |
---|
| 1211 | domPtr->sendCreateChild(*itDom); |
---|
| 1212 | CDomain::get(*itDom)->sendAllAttributesToServer(); |
---|
| 1213 | } |
---|
| 1214 | } |
---|
| 1215 | } |
---|
| 1216 | |
---|
[509] | 1217 | //! Update calendar in each time step |
---|
[300] | 1218 | void CContext::updateCalendar(int step) |
---|
| 1219 | { |
---|
[1205] | 1220 | #pragma omp critical (_output) |
---|
| 1221 | {info(50) << "updateCalendar : before : " << calendar->getCurrentDate() << endl;} |
---|
[549] | 1222 | calendar->update(step); |
---|
[1205] | 1223 | #pragma omp critical (_output) |
---|
| 1224 | {info(50) << "updateCalendar : after : " << calendar->getCurrentDate() << endl;} |
---|
| 1225 | #ifdef XIOS_MEMTRACK_LIGHT |
---|
| 1226 | #pragma omp critical (_output) |
---|
| 1227 | {info(50) << " Current memory used by XIOS : "<< MemTrack::getCurrentMemorySize()*1.0/(1024*1024)<<" Mbyte, at timestep "<<step<<" of context "<<this->getId()<<endl ;} |
---|
| 1228 | #endif |
---|
[639] | 1229 | if (hasClient) |
---|
| 1230 | { |
---|
[806] | 1231 | checkPrefetchingOfEnabledReadModeFiles(); |
---|
[639] | 1232 | garbageCollector.invalidate(calendar->getCurrentDate()); |
---|
| 1233 | } |
---|
[300] | 1234 | } |
---|
[509] | 1235 | |
---|
| 1236 | //! Server side: Create header of netcdf file |
---|
[300] | 1237 | void CContext::createFileHeader(void ) |
---|
| 1238 | { |
---|
[549] | 1239 | vector<CFile*>::const_iterator it; |
---|
[509] | 1240 | |
---|
[300] | 1241 | for (it=enabledFiles.begin(); it != enabledFiles.end(); it++) |
---|
| 1242 | { |
---|
[321] | 1243 | (*it)->initFile(); |
---|
[300] | 1244 | } |
---|
[509] | 1245 | } |
---|
| 1246 | |
---|
| 1247 | //! Get current context |
---|
[347] | 1248 | CContext* CContext::getCurrent(void) |
---|
[300] | 1249 | { |
---|
[549] | 1250 | return CObjectFactory::GetObject<CContext>(CObjectFactory::GetCurrentContextId()).get(); |
---|
[300] | 1251 | } |
---|
[509] | 1252 | |
---|
| 1253 | /*! |
---|
| 1254 | \brief Set context with an id be the current context |
---|
| 1255 | \param [in] id identity of context to be set to current |
---|
| 1256 | */ |
---|
[346] | 1257 | void CContext::setCurrent(const string& id) |
---|
| 1258 | { |
---|
| 1259 | CObjectFactory::SetCurrentContextId(id); |
---|
| 1260 | CGroupFactory::SetCurrentContextId(id); |
---|
| 1261 | } |
---|
[509] | 1262 | |
---|
| 1263 | /*! |
---|
| 1264 | \brief Create a context with specific id |
---|
| 1265 | \param [in] id identity of new context |
---|
| 1266 | \return pointer to the new context or already-existed one with identity id |
---|
| 1267 | */ |
---|
[347] | 1268 | CContext* CContext::create(const StdString& id) |
---|
[346] | 1269 | { |
---|
[549] | 1270 | CContext::setCurrent(id); |
---|
[509] | 1271 | |
---|
[346] | 1272 | bool hasctxt = CContext::has(id); |
---|
[347] | 1273 | CContext* context = CObjectFactory::CreateObject<CContext>(id).get(); |
---|
[549] | 1274 | getRoot(); |
---|
[1134] | 1275 | if (!hasctxt) CGroupFactory::AddChild(*root_ptr, context->getShared()); |
---|
[346] | 1276 | |
---|
| 1277 | #define DECLARE_NODE(Name_, name_) \ |
---|
| 1278 | C##Name_##Definition::create(C##Name_##Definition::GetDefName()); |
---|
| 1279 | #define DECLARE_NODE_PAR(Name_, name_) |
---|
| 1280 | #include "node_type.conf" |
---|
| 1281 | |
---|
| 1282 | return (context); |
---|
| 1283 | } |
---|
[697] | 1284 | |
---|
| 1285 | |
---|
| 1286 | |
---|
| 1287 | //! Server side: Receive a message to do some post processing |
---|
| 1288 | void CContext::recvRegistry(CEventServer& event) |
---|
| 1289 | { |
---|
| 1290 | CBufferIn* buffer=event.subEvents.begin()->buffer; |
---|
| 1291 | string id; |
---|
| 1292 | *buffer>>id; |
---|
| 1293 | get(id)->recvRegistry(*buffer); |
---|
| 1294 | } |
---|
| 1295 | |
---|
| 1296 | void CContext::recvRegistry(CBufferIn& buffer) |
---|
| 1297 | { |
---|
| 1298 | if (server->intraCommRank==0) |
---|
| 1299 | { |
---|
| 1300 | CRegistry registry(server->intraComm) ; |
---|
| 1301 | registry.fromBuffer(buffer) ; |
---|
| 1302 | registryOut->mergeRegistry(registry) ; |
---|
| 1303 | } |
---|
| 1304 | } |
---|
| 1305 | |
---|
| 1306 | void CContext::sendRegistry(void) |
---|
| 1307 | { |
---|
| 1308 | registryOut->hierarchicalGatherRegistry() ; |
---|
| 1309 | |
---|
| 1310 | CEventClient event(CContext::GetType(), CContext::EVENT_ID_SEND_REGISTRY); |
---|
| 1311 | if (client->isServerLeader()) |
---|
| 1312 | { |
---|
| 1313 | CMessage msg ; |
---|
| 1314 | msg<<this->getIdServer(); |
---|
| 1315 | if (client->clientRank==0) msg<<*registryOut ; |
---|
| 1316 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
| 1317 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 1318 | event.push(*itRank,1,msg); |
---|
| 1319 | client->sendEvent(event); |
---|
| 1320 | } |
---|
| 1321 | else client->sendEvent(event); |
---|
| 1322 | } |
---|
| 1323 | |
---|
[335] | 1324 | } // namespace xios |
---|