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

Last change on this file since 2591 was 2591, checked in by jderouillat, 9 months ago

Free additional communicators

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