source: XIOS/dev/dev_ym/XIOS_COUPLING/src/cxios.cpp @ 2209

Last change on this file since 2209 was 2209, checked in by ymipsl, 3 years ago

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