source: XIOS/trunk/src/cxios.cpp @ 717

Last change on this file since 717 was 698, checked in by ymipsl, 9 years ago

Minor fix : registry dump is done before stream closing on client side.
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: 4.5 KB
RevLine 
[300]1
[591]2#include "xios_spl.hpp"
[300]3#include "cxios.hpp"
[342]4#include "client.hpp"
5#include "server.hpp"
[346]6#include "xml_parser.hpp"
[300]7#include <boost/functional/hash.hpp>
[382]8#include "mpi.hpp"
[400]9#include "memory.hpp"
10#include <new>
[401]11#include "memtrack.hpp"
[697]12#include "registry.hpp"
[300]13
[335]14namespace xios
[300]15{
16  string CXios::rootFile="./iodef.xml" ;
17  string CXios::xiosCodeId="xios.x" ;
[499]18  string CXios::clientFile="./xios_client";
19  string CXios::serverFile="./xios_server";
[490]20
[300]21  bool CXios::isClient ;
22  bool CXios::isServer ;
23  MPI_Comm CXios::globalComm ;
24  bool CXios::usingOasis ;
[491]25  bool CXios::usingServer = false;
[512]26  double CXios::bufferServerFactorSize=1.0 ;
27  double CXios::defaultBufferServerFactorSize=1.0 ;
[523]28  bool CXios::printLogs2Files;
[511]29  bool CXios::isOptPerformance = true;
[697]30  CRegistry* CXios::globalRegistry = 0;
[490]31
[512]32  //! Parse configuration file and create some objects from it
[300]33  void CXios::initialize()
34  {
[400]35    set_new_handler(noMemory);
[346]36    parseFile(rootFile);
[511]37    parseXiosConfig();
38  }
39
[512]40  /*!
41  \brief Parse xios part of configuration file (.iodef.xml)
42   Both client and server need information returned from this function
43  */
[511]44  void CXios::parseXiosConfig()
45  {
[311]46    usingOasis=getin<bool>("using_oasis",false) ;
[506]47    usingServer=getin<bool>("using_server",false) ;
[311]48    info.setLevel(getin<int>("info_level",0)) ;
[512]49    report.setLevel(getin<int>("info_level",50));
[523]50    printLogs2Files=getin<bool>("print_file",false);
[512]51
[511]52    StdString bufMemory("memory");
53    StdString bufPerformance("performance");
54    StdString bufOpt = getin<StdString>("optimal_buffer_size", bufPerformance);
55    std::transform(bufOpt.begin(), bufOpt.end(), bufOpt.begin(), ::tolower);
56    if (0 == bufOpt.compare(bufMemory)) isOptPerformance = false;
57    else if (0 != bufOpt.compare(bufPerformance))
58    {
59      ERROR("CXios::parseXiosConfig()", << "optimal_buffer_size must be memory or performance "<< endl );
60    }
61
62    bufferServerFactorSize=getin<double>("buffer_factor_size",defaultBufferServerFactorSize) ;
[300]63    globalComm=MPI_COMM_WORLD ;
64  }
65
[512]66  /*!
67  Initialize client
68  \param [in] codeId identity of context
69  \param [in] localComm local communicator
70  \param [in/out] returnComm communicator corresponding to group of client with same codeId
71  */
[300]72  void CXios::initClientSide(const string& codeId, MPI_Comm& localComm, MPI_Comm& returnComm)
73  {
74    initialize() ;
[490]75
[300]76    isClient=true;
[491]77
78    CClient::initialize(codeId,localComm,returnComm) ;
[697]79    if (CClient::getRank()==0) globalRegistry = new CRegistry(returnComm) ;
[491]80
[523]81    if (usingServer) isServer=false;
82    else isServer=true;
[490]83
[523]84    if (printLogs2Files)
85    {
[499]86      CClient::openInfoStream(clientFile);
[523]87      CClient::openErrorStream(clientFile);
88    }
[490]89    else
[523]90    {
[490]91      CClient::openInfoStream();
[523]92      CClient::openErrorStream();
93    }
[490]94  }
[300]95
96  void CXios::clientFinalize(void)
97  {
[490]98     CClient::finalize() ;
[697]99     if (CClient::getRank()==0)
100     {
101       info(80)<<"Write data base Registry"<<endl<<globalRegistry->toString()<<endl ;
102       globalRegistry->toFile("xios_registry.bin") ;
103       delete globalRegistry ;
104     }
[698]105     CClient::closeInfoStream();
106 
[490]107
[401]108#ifdef XIOS_MEMTRACK
109     MemTrack::TrackListMemoryUsage() ;
[490]110     MemTrack::TrackDumpBlocks();
[401]111#endif
[490]112  }
113
[512]114  //! Init server by parsing only xios part of config file
[509]115  void CXios::initServer()
116  {
117    set_new_handler(noMemory);
118    std::set<StdString> parseList;
119    parseList.insert("xios");
120    xml::CXMLParser::ParseFile(rootFile, parseList);
[511]121    parseXiosConfig();
[509]122  }
123
[512]124  //! Initialize server then put it into listening state
[300]125  void CXios::initServerSide(void)
126  {
[509]127    initServer();
[300]128    isClient=true;
129    isServer=false ;
130
[491]131    // Initialize all aspects MPI
[490]132    CServer::initialize();
[697]133    if (CServer::getRank()==0) globalRegistry = new CRegistry(CServer::intraComm) ;
134   
[523]135    if (printLogs2Files)
136    {
[499]137      CServer::openInfoStream(serverFile);
[523]138      CServer::openErrorStream(serverFile);
139    }
[490]140    else
[523]141    {
[490]142      CServer::openInfoStream();
[523]143      CServer::openErrorStream();
144    }
[490]145
[491]146    // Enter the loop to listen message from Client
[490]147    CServer::eventLoop();
148
[491]149    // Finalize
[697]150     if (CServer::getRank()==0)
151     {
152       info(80)<<"Write data base Registry"<<endl<<globalRegistry->toString()<<endl ;
153       globalRegistry->toFile("xios_registry.bin") ;
154       delete globalRegistry ;
155     }
[490]156    CServer::finalize();
157    CServer::closeInfoStream();
158  }
159
[512]160  //! Parse configuration file
[346]161  void CXios::parseFile(const string& filename)
162  {
[490]163    xml::CXMLParser::ParseFile(filename);
[346]164  }
[491]165
[512]166  //! Set using server
[491]167  void CXios::setUsingServer()
168  {
169    usingServer = true;
170  }
171
[512]172  //! Unset using server
[491]173  void CXios::setNotUsingServer()
174  {
175    usingServer = false;
176  }
[300]177}
Note: See TracBrowser for help on using the repository browser.