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

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

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