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

Last change on this file since 2329 was 2329, checked in by jderouillat, 2 years ago

Added dedicated options to manage send/recv checksum operations, this new xios parameters are respectively called checksum_send_fields/checksum_recv_fields (set to false by default)

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