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

Last change on this file since 2603 was 2602, checked in by ymipsl, 8 months ago

bug fix : incorrect call to mpi_comm_free

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