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
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"
[1761]13#include "ressources_manager.hpp"
14#include "services_manager.hpp"
15#include "servers_ressource.hpp"
[2212]16#include "mem_checker.hpp"
[300]17
[335]18namespace xios
[300]19{
20  string CXios::rootFile="./iodef.xml" ;
21  string CXios::xiosCodeId="xios.x" ;
[499]22  string CXios::clientFile="./xios_client";
23  string CXios::serverFile="./xios_server";
[1021]24  string CXios::serverPrmFile="./xios_server1";
25  string CXios::serverSndFile="./xios_server2";
[1761]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 
[1622]30  bool CXios::xiosStack = true;
31  bool CXios::systemStack = false;
32
[300]33  bool CXios::isClient ;
34  bool CXios::isServer ;
[1761]35 
[1639]36  MPI_Comm CXios::globalComm ;
[1761]37  MPI_Comm CXios::xiosComm ;
38
[300]39  bool CXios::usingOasis ;
[491]40  bool CXios::usingServer = false;
[1021]41  bool CXios::usingServer2 = false;
42  int CXios::ratioServer2 = 50;
[1243]43  int CXios::nbPoolsServer2 = 1;
[718]44  double CXios::bufferSizeFactor = 1.0;
45  const double CXios::defaultBufferSizeFactor = 1.0;
[2176]46  StdSize CXios::minBufferSize = 64 * sizeof(double);
[1227]47  StdSize CXios::maxBufferSize = std::numeric_limits<int>::max() ;
[523]48  bool CXios::printLogs2Files;
[511]49  bool CXios::isOptPerformance = true;
[697]50  CRegistry* CXios::globalRegistry = 0;
[1375]51  double CXios::recvFieldTimeout = 300.0;
[1377]52  bool CXios::checkEventSync=false ;
[2329]53  bool CXios::checkSumRecv=false ;
54  bool CXios::checkSumSend=false ;
[1761]55
56  CDaemonsManager*    CXios::daemonsManager_=nullptr ;
57  CRessourcesManager* CXios::ressourcesManager_=nullptr ;
58  CServicesManager*   CXios::servicesManager_=nullptr ;
59  CContextsManager*   CXios::contextsManager_=nullptr ;
[1878]60  CCouplerManager*    CXios::couplerManager_=nullptr ;
[2209]61  CRegistryManager*   CXios::registryManager_=nullptr ;
[1761]62
[2310]63  CMpiGarbageCollector CXios::MpiGarbageCollector_  ;
64
[512]65  //! Parse configuration file and create some objects from it
[300]66  void CXios::initialize()
67  {
[400]68    set_new_handler(noMemory);
[346]69    parseFile(rootFile);
[511]70    parseXiosConfig();
71  }
72
[512]73  /*!
74  \brief Parse xios part of configuration file (.iodef.xml)
75   Both client and server need information returned from this function
76  */
[511]77  void CXios::parseXiosConfig()
78  {
[311]79    usingOasis=getin<bool>("using_oasis",false) ;
[506]80    usingServer=getin<bool>("using_server",false) ;
[1021]81    usingServer2=getin<bool>("using_server2",false) ;
82    ratioServer2=getin<int>("ratio_server2",50);
[1519]83    nbPoolsServer2=getin<int>("number_pools_server2",0);
[311]84    info.setLevel(getin<int>("info_level",0)) ;
[512]85    report.setLevel(getin<int>("info_level",50));
[523]86    printLogs2Files=getin<bool>("print_file",false);
[512]87
[1622]88    xiosStack=getin<bool>("xios_stack",true) ;
89    systemStack=getin<bool>("system_stack",false) ;
90    if (xiosStack && systemStack)
91    {
92      xiosStack = false;
93    }
94
[511]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
[718]105    bufferSizeFactor = getin<double>("buffer_size_factor", defaultBufferSizeFactor);
[719]106    minBufferSize = getin<int>("min_buffer_size", 1024 * sizeof(double));
[1227]107    maxBufferSize = getin<int>("max_buffer_size", std::numeric_limits<int>::max());
[1376]108    recvFieldTimeout = getin<double>("recv_field_timeout", recvFieldTimeout);
[1158]109    if (recvFieldTimeout < 0.0)
110      ERROR("CXios::parseXiosConfig()", "recv_field_timeout cannot be negative.");
[718]111
[1377]112    checkEventSync = getin<bool>("check_event_sync", checkEventSync);
[2329]113   
114    checkSumSend = getin<bool>("checksum_send_fields", false);
115    checkSumRecv = getin<bool>("checksum_recv_fields", false);
[1639]116
[300]117    globalComm=MPI_COMM_WORLD ;
118  }
119
[512]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  */
[1639]126  void CXios::initClientSide(const string& codeId, MPI_Comm& localComm, MPI_Comm& returnComm)
[1622]127  TRY
[300]128  {
129    initialize() ;
[490]130
[1639]131    isClient = true;
[491]132
[1761]133    //CClient::initialize(codeId,localComm,returnComm) ;
[491]134    CClient::initialize(codeId,localComm,returnComm) ;
[1761]135   
[956]136    // If there are no server processes then we are in attached mode
137    // and the clients are also servers
138    isServer = !usingServer;
[490]139
[523]140    if (printLogs2Files)
141    {
[499]142      CClient::openInfoStream(clientFile);
[523]143      CClient::openErrorStream(clientFile);
144    }
[490]145    else
[523]146    {
[490]147      CClient::openInfoStream();
[523]148      CClient::openErrorStream();
149    }
[490]150  }
[1622]151  CATCH
[300]152
153  void CXios::clientFinalize(void)
154  {
[490]155     CClient::finalize() ;
[1761]156         
[401]157#ifdef XIOS_MEMTRACK
[1158]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
[2212]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();
[401]179#endif
[1158]180
181     CClient::closeInfoStream();
182
183#endif
[490]184  }
185
[512]186  //! Init server by parsing only xios part of config file
[509]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);
[511]193    parseXiosConfig();
[509]194  }
195
[512]196  //! Initialize server then put it into listening state
[1054]197  void CXios::initServerSide(void)
[300]198  {
[2212]199    CMemChecker::get("xios").resume() ;
[1639]200    initServer();
[1638]201    isClient = false;
202    isServer = true;
203
[1021]204    // Initialize all aspects MPI
205    CServer::initialize();
[490]206    CServer::finalize();
[1158]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
[2212]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() ;
[1158]229#endif
230#endif
[2212]231    CMemChecker::get("xios").suspend() ;
232    report(0)<<CMemChecker::getAllCumulatedMem() ;
[490]233    CServer::closeInfoStream();
234  }
235
[512]236  //! Parse configuration file
[346]237  void CXios::parseFile(const string& filename)
238  {
[490]239    xml::CXMLParser::ParseFile(filename);
[346]240  }
[491]241
[512]242  //! Set using server
[491]243  void CXios::setUsingServer()
244  {
245    usingServer = true;
246  }
247
[512]248  //! Unset using server
[491]249  void CXios::setNotUsingServer()
250  {
251    usingServer = false;
252  }
[1761]253
[2209]254  void CXios::launchRegistryManager(bool isXiosServer)
255  {
256    registryManager_ = new CRegistryManager(isXiosServer) ;
257  }
258
[1761]259  void CXios::launchRessourcesManager(bool isXiosServer)
260  {
261    ressourcesManager_ = new CRessourcesManager(isXiosServer) ;
262  }
263
[1878]264  void CXios::launchCouplerManager(bool isXiosServer)
265  {
266    couplerManager_ = new CCouplerManager(isXiosServer) ;
267  }
268
[1761]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
[1764]284 
[2209]285  void CXios::finalizeRegistryManager()
286  {
287    delete registryManager_;
288  }
289
[1764]290  void CXios::finalizeRessourcesManager()
291  {
292    delete ressourcesManager_;
293  }
294
[1878]295  void CXios::finalizeCouplerManager()
296  {
297    delete couplerManager_;
298  }
299
[1764]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 
[1761]315  CPoolRessource* CXios::getPoolRessource(void)
316  {
317    if (isClient) return CClient::getPoolRessource() ;
318    else if (isServer) return CServer::getServersRessource()->getPoolRessource() ;
[2282]319   
320    MISSING_RETURN( "CPoolRessource* CXios::getPoolRessource()" );
321    return nullptr;
[1761]322  }
[300]323}
[1761]324
Note: See TracBrowser for help on using the repository browser.