source: XIOS3/trunk/src/client.cpp @ 2562

Last change on this file since 2562 was 2547, checked in by ymipsl, 10 months ago

Major update :

  • New method to lock and unlock one-sided windows (window_dynamic) to avoid network overhead
  • Introducing multithreading on server sided to manage more efficiently dead-lock occuring (similar to co-routine which will be available and implemented in futur c++ standard), based on c++ threads
  • Suprression of old "attached mode" which is replaced by online writer and reder filters

YM

  • Property copyright set to
    Software name : XIOS (Xml I/O Server)
    http://forge.ipsl.jussieu.fr/ioserver
    Creation date : January 2009
    Licence : CeCCIL version2
    see license file in root directory : Licence_CeCILL_V2-en.txt
    or http://www.cecill.info/licences/Licence_CeCILL_V2-en.html
    Holder : CEA/LSCE (Laboratoire des Sciences du CLimat et de l'Environnement)
    CNRS/IPSL (Institut Pierre Simon Laplace)
    Project Manager : Yann Meurdesoif
    yann.meurdesoif@cea.fr
  • Property svn:eol-style set to native
File size: 21.7 KB
RevLine 
[490]1#include "globalScopeData.hpp"
[591]2#include "xios_spl.hpp"
[300]3#include "cxios.hpp"
[342]4#include "client.hpp"
[300]5#include <boost/functional/hash.hpp>
6#include "type.hpp"
7#include "context.hpp"
8#include "context_client.hpp"
9#include "oasis_cinterface.hpp"
[382]10#include "mpi.hpp"
[347]11#include "timer.hpp"
[400]12#include "buffer_client.hpp"
[1587]13#include "string_tools.hpp"
[1761]14#include "ressources_manager.hpp"
15#include "services_manager.hpp"
16#include <functional>
17#include <cstdio>
[2146]18#include "workflow_graph.hpp"
[2274]19#include "release_static_allocation.hpp"
[2418]20#include "mem_checker.hpp"
[300]21
[335]22namespace xios
[490]23{
[300]24
[1761]25    const double serverPublishDefaultTimeout=10;
26
[2332]27    MPI_Comm CClient::intraComm_ ;
28    MPI_Comm CClient::interComm_ ;
[1761]29    MPI_Comm CClient::clientsComm_ ;
30
[1639]31    std::list<MPI_Comm> CClient::contextInterComms;
[1158]32    int CClient::serverLeader ;
[300]33    bool CClient::is_MPI_Initialized ;
[1148]34    int CClient::rank_ = INVALID_RANK;
[490]35    StdOFStream CClient::m_infoStream;
[523]36    StdOFStream CClient::m_errorStream;
[1761]37    CPoolRessource* CClient::poolRessource_=nullptr ;
38
[2332]39    MPI_Comm& CClient::getInterComm(void)   { return (interComm_); }
[1587]40     
[983]41///---------------------------------------------------------------
42/*!
43 * \fn void CClient::initialize(const string& codeId, MPI_Comm& localComm, MPI_Comm& returnComm)
44 * Function creates intraComm (CClient::intraComm) for client group with id=codeId and interComm (CClient::interComm) between client and server groups.
45 * \param [in] codeId identity of context.
46 * \param [in/out] localComm local communicator.
47 * \param [in/out] returnComm (intra)communicator of client group.
48 */
49
[1639]50    void CClient::initialize(const string& codeId, MPI_Comm& localComm, MPI_Comm& returnComm)
[300]51    {
[1761]52   
53       MPI_Comm clientComm ;
54      // initialize MPI if not initialized
[300]55      int initialized ;
[1639]56      MPI_Initialized(&initialized) ;
[300]57      if (initialized) is_MPI_Initialized=true ;
58      else is_MPI_Initialized=false ;
[1761]59     
60      MPI_Comm globalComm=CXios::getGlobalComm() ;
61
62      /////////////////////////////////////////
63      ///////////// PART 1 ////////////////////
64      /////////////////////////////////////////
65     
66
67      // localComm isn't given
68      if (localComm == MPI_COMM_NULL)
69      {
70         
71        // don't use OASIS
72        if (!CXios::usingOasis)
73        {
74
75          if (!is_MPI_Initialized)
76          {
77            MPI_Init(NULL, NULL);
78          }
79          CTimer::get("XIOS").resume() ;
80          CTimer::get("XIOS init/finalize",false).resume() ;
81         
82          // split the global communicator
83          // get hash from all model to attribute a unique color (int) and then split to get client communicator
84          // every mpi process of globalComm (MPI_COMM_WORLD) must participate
85
86          int commRank, commSize ;
87          MPI_Comm_rank(globalComm,&commRank) ;
88          MPI_Comm_size(globalComm,&commSize) ;
89
90          std::hash<string> hashString ;
91          size_t hashClient=hashString(codeId) ;
92         
93          size_t* hashAll = new size_t[commSize] ;
[2238]94          MPI_Allgather(&hashClient,1,MPI_SIZE_T,hashAll,1,MPI_SIZE_T,globalComm) ;
[1761]95         
96          int color=0 ;
[2238]97          map<size_t,int> listHash ;
98          for(int i=0 ; i<=commSize ; i++) 
99            if (listHash.count(hashAll[i])==0) 
[1761]100            {
[2238]101              listHash[hashAll[i]]=color ;
[1761]102              color=color+1 ;
103            }
[2238]104            color=listHash[hashClient] ;
[1761]105          delete[] hashAll ;
106
107          MPI_Comm_split(globalComm, color, commRank, &clientComm) ;
108        }
[2335]109        else
[1761]110        {
[2335]111          ERROR("void CClient::initialize(const string& codeId, MPI_Comm& localComm, MPI_Comm& returnComm)", <<"OASIS usage is set. In these conditions, XIOS initialization needs the local_comm created by OASIS."<<endl) ;
[1761]112        }
113      }
114      else // localComm is given
115      {
116        MPI_Comm_dup(localComm,&clientComm) ;
[2333]117        MPI_Comm_dup(localComm,&intraComm_) ;
118
119        if (CXios::usingServer)
120        {
121          MPI_Comm_rank(intraComm_,&rank_) ;
122        }
123
[1761]124      }
125     
126     
127      /////////////////////////////////////////
128      ///////////// PART 2 ////////////////////
129      /////////////////////////////////////////
130     
131
132      // Create the XIOS communicator for every process which is related
133      // to XIOS, as well on client side as on server side
134     
135      MPI_Comm xiosGlobalComm ;
136      string strIds=CXios::getin<string>("clients_code_id","") ;
137      vector<string> clientsCodeId=splitRegex(strIds,"\\s*,\\s*") ;
138      if (strIds.empty())
139      {
140         // no code Ids given, suppose XIOS initialisation is global           
141         int commRank, commGlobalRank, serverLeader, clientLeader,serverRemoteLeader,clientRemoteLeader ;
142         MPI_Comm splitComm,interComm ;
143         MPI_Comm_rank(globalComm,&commGlobalRank) ;
144         MPI_Comm_split(globalComm, 0, commGlobalRank, &splitComm) ;
145         int splitCommSize, globalCommSize ;
146       
147         MPI_Comm_size(splitComm,&splitCommSize) ;
148         MPI_Comm_size(globalComm,&globalCommSize) ;
149         if (splitCommSize==globalCommSize) // no server
150         {
151           MPI_Comm_dup(globalComm,&xiosGlobalComm) ;
152           CXios::setXiosComm(xiosGlobalComm) ;
153         }
154         else
155         {
156           MPI_Comm_rank(splitComm,&commRank) ;
157           if (commRank==0) clientLeader=commGlobalRank ;
158           else clientLeader=0 ;
159           serverLeader=0 ;
160           MPI_Allreduce(&clientLeader,&clientRemoteLeader,1,MPI_INT,MPI_SUM,globalComm) ;
161           MPI_Allreduce(&serverLeader,&serverRemoteLeader,1,MPI_INT,MPI_SUM,globalComm) ;
162           MPI_Intercomm_create(splitComm, 0, globalComm, serverRemoteLeader,1341,&interComm) ;
163           MPI_Intercomm_merge(interComm,true,&xiosGlobalComm) ;
164           CXios::setXiosComm(xiosGlobalComm) ;
165         }
166      }
167      else
168      {
169
170        xiosGlobalCommByFileExchange(clientComm, codeId) ;
171     
172      }
173
174      int commRank ;
175      MPI_Comm_rank(CXios::getXiosComm(), &commRank) ;
176      MPI_Comm_split(CXios::getXiosComm(),false,commRank, &clientsComm_) ;
177     
178      // is using server or not ?
179      int xiosCommSize, clientsCommSize ; 
180      MPI_Comm_size(CXios::getXiosComm(), &xiosCommSize) ;
181      MPI_Comm_size(clientsComm_, &clientsCommSize) ;
[2547]182      if (xiosCommSize==clientsCommSize) CXios::setNotUsingServer() ;
183      else CXios::setUsingServer() ;
[1761]184
185      /////////////////////////////////////////
186      ///////////// PART 3 ////////////////////
187      /////////////////////////////////////////
188     
189      CXios::launchDaemonsManager(false) ;
[2523]190      shared_ptr<CEventScheduler> eventScheduler ;
191      poolRessource_ = new CPoolRessource(clientComm, eventScheduler, codeId, false) ;
[1761]192
193      /////////////////////////////////////////
194      ///////////// PART 4 ////////////////////
195      /////////////////////////////////////////     
[2458]196/*
197      MPI_Request req ;
198      MPI_Status status ;
[2523]199      MPI_Ibarrier(CXios::getXiosComm(),&req) ; // be sure that all services are created now, could be remove later if more asynchronisity
[2458]200      int ok=false ;
201      while (!ok)
202      {
203        CXios::getDaemonsManager()->eventLoop() ;
204        MPI_Test(&req,&ok,&status) ;
205      }
206*/     
[1761]207      returnComm = clientComm ;
208    }
209
210
211    void CClient::xiosGlobalCommByFileExchange(MPI_Comm clientComm, const string& codeId)
212    {
213 
214      MPI_Comm globalComm=CXios::getGlobalComm() ;
215      MPI_Comm xiosGlobalComm ;
216
217      string strIds=CXios::getin<string>("clients_code_id","") ;
218      vector<string> clientsCodeId=splitRegex(strIds,"\\s*,\\s*") ;
219
220      int commRank, globalRank, clientRank, serverRank ;
221      MPI_Comm_rank(clientComm, &commRank) ;
222      MPI_Comm_rank(globalComm, &globalRank) ;
223      string clientFileName("__xios_publisher::"+codeId+"__to_remove__") ;
224           
225      int error ;
226
227      if (commRank==0) // if root process publish name
228      { 
229        std::ofstream ofs (clientFileName, std::ofstream::out);
230        ofs<<globalRank ;
231        ofs.close();
232       
233  // get server root rank
234
235        std::ifstream ifs ;
236        string fileName=("__xios_publisher::"+CXios::xiosCodeId+"__to_remove__") ;
237     
238        double timeout = CXios::getin<double>("server_puplish_timeout",serverPublishDefaultTimeout) ;
239        double time ;
240         
241        do
242        {
243          CTimer::get("server_publish_timeout").resume() ; 
244          ifs.clear() ;
245          ifs.open(fileName, std::ifstream::in) ;
246          CTimer::get("server_publish_timeout").suspend() ;
247        } while (ifs.fail() && CTimer::get("server_publish_timeout").getCumulatedTime()<timeout) ;
248       
249        if (CTimer::get("server_publish_timeout").getCumulatedTime()>=timeout || ifs.fail())
250        {
251          ifs.clear() ;
252          ifs.close() ;
253          ifs.clear() ;
254          error=true ;           
255        }
256        else 
257        {
258          ifs>>serverRank ;
259          ifs.close() ;
260          error=false ;
261        } 
262
263      } 
264      MPI_Bcast(&error,1,MPI_INT,0,clientComm) ;
265     
266      if (error==false)  // you have a server
267      {
268        MPI_Comm intraComm ;
269        MPI_Comm_dup(clientComm,&intraComm) ;
270        MPI_Comm interComm ;
271       
272        int pos=0 ;
273        for(int i=0 ; codeId!=clientsCodeId[i]; i++) pos=pos+1 ;
274
275        bool high=true ;
276        for(int i=pos ; i<clientsCodeId.size(); i++)
277        { 
278          MPI_Intercomm_create(intraComm, 0, globalComm, serverRank, 3141, &interComm);
279          MPI_Comm_free(&intraComm) ;
280          MPI_Intercomm_merge(interComm,high, &intraComm ) ;
281          high=false ;
[2333]282          if (i==pos) {
283            interComm_=interComm ;
284          }
[1761]285        }
286        xiosGlobalComm=intraComm ;
287      }
288      else  // no server detected
289      {
290        vector<int> clientsRank(clientsCodeId.size()) ;
291       
292        if (commRank==0)
293        { 
294          for(int i=0;i<clientsRank.size();i++)
295          {
296            std::ifstream ifs ;
297            string fileName=("__xios_publisher::"+clientsCodeId[i]+"__to_remove__") ;
298            do
299            {
300              ifs.clear() ;
301              ifs.open(fileName, std::ifstream::in) ;
302            } while (ifs.fail()) ;
303            ifs>>clientsRank[i] ;
304            ifs.close() ;
305          }
306        }
307         
308        int client ;
309        MPI_Comm intraComm ;
310        MPI_Comm_dup(clientComm,&intraComm) ;
311        MPI_Comm interComm ;
312       
313        int pos=0 ;
314        for(int i=0 ; codeId!=clientsCodeId[i]; i++) pos=pos+1 ;
315       
316        bool high=true ;
317        for(int i=pos+1 ; i<clientsCodeId.size(); i++)
318        { 
319          if (codeId==clientsCodeId[0])   // first model play the server rule
320          {         
321            MPI_Intercomm_create(intraComm, 0, globalComm, clientsRank[i], 3141, &interComm);
322            MPI_Intercomm_merge(interComm,false, &intraComm ) ;
323          }
324          else
325          {         
326            MPI_Intercomm_create(intraComm, 0, globalComm, clientsRank[0], 3141, &interComm);
327            MPI_Intercomm_merge(interComm,high, &intraComm ) ;
328            high=false ;
329          }
[2333]330          if (i==pos) {
331            interComm_=interComm ; // NOT TESTED !
332          }
[1761]333        }
334        xiosGlobalComm=intraComm ;
335      }
336
337      MPI_Barrier(xiosGlobalComm);
338      if (commRank==0) std::remove(clientFileName.c_str()) ;         
339      MPI_Barrier(xiosGlobalComm);
340 
341      CXios::setXiosComm(xiosGlobalComm) ;
342
[1764]343      MPI_Comm commUnfree ;
344      MPI_Comm_dup(clientComm, &commUnfree ) ;
345 
[1761]346    }
347
[1765]348// to check on other architecture
[1761]349    void CClient::xiosGlobalCommByPublishing(MPI_Comm clientComm, const string& codeId)
350    {
351
352      // untested. need to be developped an a true MPI compliant library
353
354/*
355        // try to discover other client/server
356        // do you have a xios server ?
357        char portName[MPI_MAX_PORT_NAME];
358        int ierr ;
359        int commRank ;
360        MPI_Comm_rank(clientComm,&commRank) ;
361
362        MPI_Barrier(globalComm) ;
363        if (commRank==0)
364        {
365             
366          MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN );
367          const char* serviceName=CXios::xiosCodeId.c_str() ;
368          ierr=MPI_Lookup_name(CXios::xiosCodeId.c_str(), MPI_INFO_NULL, portName);
369          MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_ARE_FATAL );
370        }
371        ierr=MPI_SUCCESS ;
372        MPI_Bcast(&ierr,1,MPI_INT,0,clientComm) ;
373
374        if (ierr==MPI_SUCCESS) // you have a server
375        { 
376          MPI_Comm intraComm=clientComm ;
377          MPI_Comm interComm ;
378          for(int i=0 ; i<clientsCodeId.size(); i++)
379          { 
380            MPI_Comm_connect(portName, MPI_INFO_NULL, 0, intraComm, &interComm);
381            MPI_Intercomm_merge(interComm, true, &intraComm ) ;
382          }
383          xiosGlobalComm=intraComm ;
384        }
385        else  // you don't have any server
386        {
387          if (codeId==clientsCodeId[0]) // first code will publish his name
388          {
389
390            if (commRank==0) // if root process publish name
391            { 
392              MPI_Open_port(MPI_INFO_NULL, portName);
393              MPI_Publish_name(CXios::xiosCodeId.c_str(), MPI_INFO_NULL, portName);
394            }
395
396            MPI_Comm intraComm=clientComm ;
397            MPI_Comm interComm ;
398            for(int i=0 ; i<clientsCodeId.size()-1; i++)
399            { 
400              MPI_Comm_accept(portName, MPI_INFO_NULL, 0, intraComm, &interComm);
401              MPI_Intercomm_merge(interComm,false, &intraComm ) ;
402            }
403          }
404          else  // other clients are connecting to the first one
405          {
406            if (commRank==0)
407            {
408
409              MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN );
410              ierr=MPI_Lookup_name(CXios::xiosCodeId.c_str(), MPI_INFO_NULL, portName);
411              MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_ARE_FATAL );
412             }
413
414            MPI_Bcast(&ierr,1,MPI_INT,0,clientComm) ;
415
416            if (ierr==MPI_SUCCESS) // you can connect
417            { 
418              MPI_Comm intraComm=clientComm ;
419              MPI_Comm interComm ;
420              for(int i=0 ; i<clientsCodeId.size()-1; i++)
421              { 
422                MPI_Comm_connect(portName, MPI_INFO_NULL, 0, intraComm, &interComm);
423                MPI_Intercomm_merge(interComm, true, &intraComm ) ;
424              }
425              xiosGlobalComm=intraComm ;
426            }
427          }
428        } 
429      */
430    }
431
[490]432
[1765]433///---------------------------------------------------------------
434/*!
435 * \fn void CClient::registerContext(const string& id, MPI_Comm contextComm)
436 * \brief Sends a request to create a context to server. Creates client/server contexts.
437 * \param [in] id id of context.
438 * \param [in] contextComm.
439 * Function is only called by client.
440 */
[1761]441    void CClient::registerContext(const string& id, MPI_Comm contextComm)
442    {
443      int commRank, commSize ;
444      MPI_Comm_rank(contextComm,&commRank) ;
445      MPI_Comm_size(contextComm,&commSize) ;
[2523]446     
447      shared_ptr<CEventScheduler> eventScheduler ;
448     
449      getPoolRessource()->createService(contextComm, eventScheduler, id, 0, CServicesManager::CLIENT, 1) ;
450//      getPoolRessource()->createService(contextComm, eventScheduler, id+"_"+CXios::defaultWriterId, 0, CServicesManager::WRITER, 1) ;
451      getPoolRessource()->createNewServiceOnto(id+"_"+CXios::defaultWriterId, CServicesManager::WRITER, id) ;
452//      getPoolRessource()->createService(contextComm, eventScheduler, id+"_"+CXios::defaultReaderId, 0, CServicesManager::READER, 1) ;
453      getPoolRessource()->createNewServiceOnto(id+"_"+CXios::defaultReaderId, CServicesManager::READER, id) ;
[1761]454
455      if (commRank==0) while (!CXios::getServicesManager()->hasService(getPoolRessource()->getId(), id, 0)) { CXios::getDaemonsManager()->eventLoop();}
456
457      if (commRank==0) CXios::getContextsManager()->createServerContext(getPoolRessource()->getId(), id, 0, id) ;
458      int type=CServicesManager::CLIENT ;
459      string name = CXios::getContextsManager()->getServerContextName(getPoolRessource()->getId(), id, 0, type, id) ;
[2238]460      double time ;
461      double lastTime=0 ;
[2260]462      double latency=0 ;
[2238]463      bool out=false ;
464      while (!out)
[1761]465      {
[2238]466        time=MPI_Wtime() ;
467        if (time-lastTime > latency) 
468        {
469          out=CXios::getContextsManager()->hasContext(name, contextComm);
470          lastTime=time ;
471        }
472        if (!out) CXios::getDaemonsManager()->eventLoop() ;
[1761]473      }
474
475    }
476
477
[490]478
[1587]479/*!
480 * \fn void CClient::callOasisEnddef(void)
481 * \brief Send the order to the servers to call "oasis_enddef". It must be done by each compound of models before calling oasis_enddef on client side
482 * Function is only called by client.
483 */
484    void CClient::callOasisEnddef(void)
485    {
486      bool oasisEnddef=CXios::getin<bool>("call_oasis_enddef",true) ;
487      if (!oasisEnddef) ERROR("void CClient::callOasisEnddef(void)", <<"Function xios_oasis_enddef called but variable <call_oasis_enddef> is set to false."<<endl
488                                                                     <<"Variable <call_oasis_enddef> must be set to true"<<endl) ;
[2333]489      if (!CXios::isClient) // != isServer (change recently )
[1587]490      // Attached mode
491      {
492        // nothing to do   
493      }
494      else
495      {
496        int rank ;
497        int msg=0 ;
498
[2332]499        MPI_Comm_rank(intraComm_,&rank) ;
[1587]500        if (rank==0) 
501        {
[2332]502          MPI_Send(&msg,1,MPI_INT,0,5,interComm_) ; // tags oasis_endded = 5
[1587]503        }
504
505      }
506    }
507
[300]508    void CClient::finalize(void)
509    {
[1761]510     
511      MPI_Barrier(clientsComm_) ;
512      int commRank ;
513      MPI_Comm_rank(clientsComm_, &commRank) ;
514      if (commRank==0) CXios::getRessourcesManager()->finalize() ;
515     
516      CTimer::get("XIOS init/finalize",false).suspend() ;
517      CTimer::get("XIOS").suspend() ;
[2266]518      CXios::finalizeDaemonsManager() ;
[2274]519      finalizePoolRessource() ;
[2265]520      CContext::removeAllContexts() ; // free memory for related context
[1764]521
[2310]522      CXios::getMpiGarbageCollector().release() ; // release unfree MPI ressources
[1761]523      if (!is_MPI_Initialized)
524      {
[2335]525        if (!CXios::usingOasis) MPI_Finalize() ;
[1761]526      }
527     
528      info(20) << "Client side context is finalized"<<endl ;
529      report(0) <<" Performance report : Whole time from XIOS init and finalize: "<< CTimer::get("XIOS init/finalize").getCumulatedTime()<<" s"<<endl ;
530      report(0) <<" Performance report : total time spent for XIOS : "<< CTimer::get("XIOS").getCumulatedTime()<<" s"<<endl ;
531      report(0)<< " Performance report : time spent for waiting free buffer : "<< CTimer::get("Blocking time").getCumulatedTime()<<" s"<<endl ;
532      report(0)<< " Performance report : Ratio : "<< CTimer::get("Blocking time").getCumulatedTime()/CTimer::get("XIOS init/finalize").getCumulatedTime()*100.<<" %"<<endl ;
533      report(0)<< " Performance report : This ratio must be close to zero. Otherwise it may be usefull to increase buffer size or numbers of server"<<endl ;
534//      report(0)<< " Memory report : Current buffer_size : "<<CXios::bufferSize<<endl ;
535      report(0)<< " Memory report : Minimum buffer size required : " << CClientBuffer::maxRequestSize << " bytes" << endl ;
536      report(0)<< " Memory report : increasing it by a factor will increase performance, depending of the volume of data wrote in file at each time step of the file"<<endl ;
537      report(100)<<CTimer::getAllCumulatedTime()<<endl ;
[2535]538      if (CXios::reportMemory)
539      {
540        report(100)<<CMemChecker::getAllCumulatedMem()<<endl ;
541      }
[2146]542      CWorkflowGraph::drawWorkFlowGraph_client();
[2274]543
544      xios::releaseStaticAllocation() ;
545
[1761]546    }
547   
[2274]548    void CClient::finalizePoolRessource() 
549    { 
550      delete poolRessource_ ; poolRessource_=nullptr ;
551    }
[1761]552
[1148]553    /*!
[1243]554    * Return global rank without oasis and current rank in model intraComm in case of oasis
[1148]555    */
[490]556   int CClient::getRank()
557   {
[1148]558     return rank_;
[490]559   }
560
[523]561    /*!
562    * Open a file specified by a suffix and an extension and use it for the given file buffer.
563    * The file name will be suffix+rank+extension.
564    *
565    * \param fileName[in] protype file name
566    * \param ext [in] extension of the file
567    * \param fb [in/out] the file buffer
568    */
569    void CClient::openStream(const StdString& fileName, const StdString& ext, std::filebuf* fb)
570    {
571      StdStringStream fileNameClient;
572      int numDigit = 0;
573      int size = 0;
[1233]574      int rank;
[1761]575      MPI_Comm_size(CXios::getGlobalComm(), &size);
576      MPI_Comm_rank(CXios::getGlobalComm(),&rank);
[523]577      while (size)
578      {
579        size /= 10;
580        ++numDigit;
581      }
[497]582
[1761]583      fileNameClient << fileName << "_" << std::setfill('0') << std::setw(numDigit) << rank << ext;
[1233]584
[523]585      fb->open(fileNameClient.str().c_str(), std::ios::out);
586      if (!fb->is_open())
587        ERROR("void CClient::openStream(const StdString& fileName, const StdString& ext, std::filebuf* fb)",
[1542]588              << std::endl << "Can not open <" << fileNameClient.str() << "> file to write the client log(s).");
[523]589    }
[490]590
[523]591    /*!
592    * \brief Open a file stream to write the info logs
593    * Open a file stream with a specific file name suffix+rank
594    * to write the info logs.
595    * \param fileName [in] protype file name
596    */
597    void CClient::openInfoStream(const StdString& fileName)
598    {
599      std::filebuf* fb = m_infoStream.rdbuf();
600      openStream(fileName, ".out", fb);
[490]601
[523]602      info.write2File(fb);
603      report.write2File(fb);
604    }
[490]605
[523]606    //! Write the info logs to standard output
607    void CClient::openInfoStream()
608    {
609      info.write2StdOut();
610      report.write2StdOut();
611    }
[490]612
[523]613    //! Close the info logs file if it opens
614    void CClient::closeInfoStream()
615    {
616      if (m_infoStream.is_open()) m_infoStream.close();
617    }
[490]618
[523]619    /*!
620    * \brief Open a file stream to write the error log
621    * Open a file stream with a specific file name suffix+rank
622    * to write the error log.
623    * \param fileName [in] protype file name
624    */
625    void CClient::openErrorStream(const StdString& fileName)
626    {
627      std::filebuf* fb = m_errorStream.rdbuf();
628      openStream(fileName, ".err", fb);
629
630      error.write2File(fb);
631    }
632
633    //! Write the error log to standard error output
634    void CClient::openErrorStream()
635    {
636      error.write2StdErr();
637    }
638
639    //! Close the error log file if it opens
640    void CClient::closeErrorStream()
641    {
642      if (m_errorStream.is_open()) m_errorStream.close();
643    }
[300]644}
Note: See TracBrowser for help on using the repository browser.