source: XIOS/dev/dev_ym/XIOS_SERVICES/src/cxios.cpp @ 1765

Last change on this file since 1765 was 1765, checked in by ymipsl, 4 years ago

Some cleaning On XIOS services branch

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: 7.3 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#include "ressources_manager.hpp"
14#include "services_manager.hpp"
15#include "servers_ressource.hpp"
16
17namespace xios
18{
19  string CXios::rootFile="./iodef.xml" ;
20  string CXios::xiosCodeId="xios.x" ;
21  string CXios::clientFile="./xios_client";
22  string CXios::serverFile="./xios_server";
23  string CXios::serverPrmFile="./xios_server1";
24  string CXios::serverSndFile="./xios_server2";
25  const string CXios::defaultPoolId="default_pool_id" ;
26  const string CXios::defaultServerId="default_server_id" ;
27  const string CXios::defaultGathererId="default_gatherer_id" ;
28 
29  bool CXios::xiosStack = true;
30  bool CXios::systemStack = false;
31
32  bool CXios::isClient ;
33  bool CXios::isServer ;
34 
35  MPI_Comm CXios::globalComm ;
36  MPI_Comm CXios::xiosComm ;
37
38  bool CXios::usingOasis ;
39  bool CXios::usingServer = false;
40  bool CXios::usingServer2 = false;
41  int CXios::ratioServer2 = 50;
42  int CXios::nbPoolsServer2 = 1;
43  double CXios::bufferSizeFactor = 1.0;
44  const double CXios::defaultBufferSizeFactor = 1.0;
45  StdSize CXios::minBufferSize = 1024 * sizeof(double);
46  StdSize CXios::maxBufferSize = std::numeric_limits<int>::max() ;
47  bool CXios::printLogs2Files;
48  bool CXios::isOptPerformance = true;
49  CRegistry* CXios::globalRegistry = 0;
50  double CXios::recvFieldTimeout = 300.0;
51  bool CXios::checkEventSync=false ;
52
53  CDaemonsManager*    CXios::daemonsManager_=nullptr ;
54  CRessourcesManager* CXios::ressourcesManager_=nullptr ;
55  CServicesManager*   CXios::servicesManager_=nullptr ;
56  CContextsManager*   CXios::contextsManager_=nullptr ;
57
58  //! Parse configuration file and create some objects from it
59  void CXios::initialize()
60  {
61    set_new_handler(noMemory);
62    parseFile(rootFile);
63    parseXiosConfig();
64  }
65
66  /*!
67  \brief Parse xios part of configuration file (.iodef.xml)
68   Both client and server need information returned from this function
69  */
70  void CXios::parseXiosConfig()
71  {
72    usingOasis=getin<bool>("using_oasis",false) ;
73    usingServer=getin<bool>("using_server",false) ;
74    usingServer2=getin<bool>("using_server2",false) ;
75    ratioServer2=getin<int>("ratio_server2",50);
76    nbPoolsServer2=getin<int>("number_pools_server2",0);
77    info.setLevel(getin<int>("info_level",0)) ;
78    report.setLevel(getin<int>("info_level",50));
79    printLogs2Files=getin<bool>("print_file",false);
80
81    xiosStack=getin<bool>("xios_stack",true) ;
82    systemStack=getin<bool>("system_stack",false) ;
83    if (xiosStack && systemStack)
84    {
85      xiosStack = false;
86    }
87
88    StdString bufMemory("memory");
89    StdString bufPerformance("performance");
90    StdString bufOpt = getin<StdString>("optimal_buffer_size", bufPerformance);
91    std::transform(bufOpt.begin(), bufOpt.end(), bufOpt.begin(), ::tolower);
92    if (0 == bufOpt.compare(bufMemory)) isOptPerformance = false;
93    else if (0 != bufOpt.compare(bufPerformance))
94    {
95      ERROR("CXios::parseXiosConfig()", << "optimal_buffer_size must be memory or performance "<< endl );
96    }
97
98    bufferSizeFactor = getin<double>("buffer_size_factor", defaultBufferSizeFactor);
99    minBufferSize = getin<int>("min_buffer_size", 1024 * sizeof(double));
100    maxBufferSize = getin<int>("max_buffer_size", std::numeric_limits<int>::max());
101    recvFieldTimeout = getin<double>("recv_field_timeout", recvFieldTimeout);
102    if (recvFieldTimeout < 0.0)
103      ERROR("CXios::parseXiosConfig()", "recv_field_timeout cannot be negative.");
104
105    checkEventSync = getin<bool>("check_event_sync", checkEventSync);
106
107    globalComm=MPI_COMM_WORLD ;
108  }
109
110  /*!
111  Initialize client
112  \param [in] codeId identity of context
113  \param [in] localComm local communicator
114  \param [in/out] returnComm communicator corresponding to group of client with same codeId
115  */
116  void CXios::initClientSide(const string& codeId, MPI_Comm& localComm, MPI_Comm& returnComm)
117  TRY
118  {
119    initialize() ;
120
121    isClient = true;
122
123    //CClient::initialize(codeId,localComm,returnComm) ;
124    CClient::initialize(codeId,localComm,returnComm) ;
125   
126    // If there are no server processes then we are in attached mode
127    // and the clients are also servers
128    isServer = !usingServer;
129
130    if (printLogs2Files)
131    {
132      CClient::openInfoStream(clientFile);
133      CClient::openErrorStream(clientFile);
134    }
135    else
136    {
137      CClient::openInfoStream();
138      CClient::openErrorStream();
139    }
140  }
141  CATCH
142
143  void CXios::clientFinalize(void)
144  {
145     CClient::finalize() ;
146         
147#ifdef XIOS_MEMTRACK
148
149#ifdef XIOS_MEMTRACK_LIGHT
150       report(10) << " Memory report : current memory used by XIOS : "<<  MemTrack::getCurrentMemorySize()*1.0/(1024*1024)<<" Mbyte" << endl ;
151       report(10) << " Memory report : maximum memory used by XIOS : "<<  MemTrack::getMaxMemorySize()*1.0/(1024*1024)<<" Mbyte" << endl ;
152#endif
153
154#ifdef XIOS_MEMTRACK_FULL
155     MemTrack::TrackListMemoryUsage() ;
156     MemTrack::TrackDumpBlocks();
157#endif
158
159     CClient::closeInfoStream();
160
161#endif
162  }
163
164  //! Init server by parsing only xios part of config file
165  void CXios::initServer()
166  {
167    set_new_handler(noMemory);
168    std::set<StdString> parseList;
169    parseList.insert("xios");
170    xml::CXMLParser::ParseFile(rootFile, parseList);
171    parseXiosConfig();
172  }
173
174  //! Initialize server then put it into listening state
175  void CXios::initServerSide(void)
176  {
177    initServer();
178    isClient = false;
179    isServer = true;
180
181    // Initialize all aspects MPI
182    CServer::initialize();
183    CServer::finalize();
184
185#ifdef XIOS_MEMTRACK
186
187#ifdef XIOS_MEMTRACK_LIGHT
188       report(10) << " Memory report : current memory used by XIOS : "<<  MemTrack::getCurrentMemorySize()*1.0/(1024*1024)<<" Mbyte" << endl ;
189       report(10) << " Memory report : maximum memory used by XIOS : "<<  MemTrack::getMaxMemorySize()*1.0/(1024*1024)<<" Mbyte" << endl ;
190#endif
191
192#ifdef XIOS_MEMTRACK_FULL
193     MemTrack::TrackListMemoryUsage() ;
194     MemTrack::TrackDumpBlocks();
195#endif
196#endif
197    CServer::closeInfoStream();
198  }
199
200  //! Parse configuration file
201  void CXios::parseFile(const string& filename)
202  {
203    xml::CXMLParser::ParseFile(filename);
204  }
205
206  //! Set using server
207  void CXios::setUsingServer()
208  {
209    usingServer = true;
210  }
211
212  //! Unset using server
213  void CXios::setNotUsingServer()
214  {
215    usingServer = false;
216  }
217
218  void CXios::launchRessourcesManager(bool isXiosServer)
219  {
220    ressourcesManager_ = new CRessourcesManager(isXiosServer) ;
221  }
222
223  void CXios::launchServicesManager(bool isXiosServer)
224  {
225    servicesManager_ = new CServicesManager(isXiosServer) ;
226  }
227
228  void CXios::launchContextsManager(bool isXiosServer)
229  {
230    contextsManager_ = new CContextsManager(isXiosServer) ;
231  }
232 
233  void CXios::launchDaemonsManager(bool isXiosServer)
234  {
235    daemonsManager_ = new CDaemonsManager(isXiosServer) ;
236  }
237
238 
239  void CXios::finalizeRessourcesManager()
240  {
241    delete ressourcesManager_;
242  }
243
244  void CXios::finalizeServicesManager()
245  {
246    delete servicesManager_  ;
247  }
248
249  void CXios::finalizeContextsManager()
250  {
251    delete contextsManager_  ;
252  }
253 
254  void CXios::finalizeDaemonsManager()
255  {
256    delete daemonsManager_  ;
257  }
258 
259
260  CPoolRessource* CXios::getPoolRessource(void)
261  {
262    if (isClient) return CClient::getPoolRessource() ;
263    else if (isServer) return CServer::getServersRessource()->getPoolRessource() ;
264  }
265}
266
Note: See TracBrowser for help on using the repository browser.