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

Last change on this file since 706 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
Line 
1
2#include "xios_spl.hpp"
3#include "cxios.hpp"
4#include "client.hpp"
5#include "server.hpp"
6#include "xml_parser.hpp"
7#include <boost/functional/hash.hpp>
8#include "mpi.hpp"
9#include "memory.hpp"
10#include <new>
11#include "memtrack.hpp"
12#include "registry.hpp"
13
14namespace xios
15{
16  string CXios::rootFile="./iodef.xml" ;
17  string CXios::xiosCodeId="xios.x" ;
18  string CXios::clientFile="./xios_client";
19  string CXios::serverFile="./xios_server";
20
21  bool CXios::isClient ;
22  bool CXios::isServer ;
23  MPI_Comm CXios::globalComm ;
24  bool CXios::usingOasis ;
25  bool CXios::usingServer = false;
26  double CXios::bufferServerFactorSize=1.0 ;
27  double CXios::defaultBufferServerFactorSize=1.0 ;
28  bool CXios::printLogs2Files;
29  bool CXios::isOptPerformance = true;
30  CRegistry* CXios::globalRegistry = 0;
31
32  //! Parse configuration file and create some objects from it
33  void CXios::initialize()
34  {
35    set_new_handler(noMemory);
36    parseFile(rootFile);
37    parseXiosConfig();
38  }
39
40  /*!
41  \brief Parse xios part of configuration file (.iodef.xml)
42   Both client and server need information returned from this function
43  */
44  void CXios::parseXiosConfig()
45  {
46    usingOasis=getin<bool>("using_oasis",false) ;
47    usingServer=getin<bool>("using_server",false) ;
48    info.setLevel(getin<int>("info_level",0)) ;
49    report.setLevel(getin<int>("info_level",50));
50    printLogs2Files=getin<bool>("print_file",false);
51
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) ;
63    globalComm=MPI_COMM_WORLD ;
64  }
65
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  */
72  void CXios::initClientSide(const string& codeId, MPI_Comm& localComm, MPI_Comm& returnComm)
73  {
74    initialize() ;
75
76    isClient=true;
77
78    CClient::initialize(codeId,localComm,returnComm) ;
79    if (CClient::getRank()==0) globalRegistry = new CRegistry(returnComm) ;
80
81    if (usingServer) isServer=false;
82    else isServer=true;
83
84    if (printLogs2Files)
85    {
86      CClient::openInfoStream(clientFile);
87      CClient::openErrorStream(clientFile);
88    }
89    else
90    {
91      CClient::openInfoStream();
92      CClient::openErrorStream();
93    }
94  }
95
96  void CXios::clientFinalize(void)
97  {
98     CClient::finalize() ;
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     }
105     CClient::closeInfoStream();
106 
107
108#ifdef XIOS_MEMTRACK
109     MemTrack::TrackListMemoryUsage() ;
110     MemTrack::TrackDumpBlocks();
111#endif
112  }
113
114  //! Init server by parsing only xios part of config file
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);
121    parseXiosConfig();
122  }
123
124  //! Initialize server then put it into listening state
125  void CXios::initServerSide(void)
126  {
127    initServer();
128    isClient=true;
129    isServer=false ;
130
131    // Initialize all aspects MPI
132    CServer::initialize();
133    if (CServer::getRank()==0) globalRegistry = new CRegistry(CServer::intraComm) ;
134   
135    if (printLogs2Files)
136    {
137      CServer::openInfoStream(serverFile);
138      CServer::openErrorStream(serverFile);
139    }
140    else
141    {
142      CServer::openInfoStream();
143      CServer::openErrorStream();
144    }
145
146    // Enter the loop to listen message from Client
147    CServer::eventLoop();
148
149    // Finalize
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     }
156    CServer::finalize();
157    CServer::closeInfoStream();
158  }
159
160  //! Parse configuration file
161  void CXios::parseFile(const string& filename)
162  {
163    xml::CXMLParser::ParseFile(filename);
164  }
165
166  //! Set using server
167  void CXios::setUsingServer()
168  {
169    usingServer = true;
170  }
171
172  //! Unset using server
173  void CXios::setNotUsingServer()
174  {
175    usingServer = false;
176  }
177}
Note: See TracBrowser for help on using the repository browser.