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

Last change on this file since 1878 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
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  CCouplerManager*    CXios::couplerManager_=nullptr ;
58
59  //! Parse configuration file and create some objects from it
60  void CXios::initialize()
61  {
62    set_new_handler(noMemory);
63    parseFile(rootFile);
64    parseXiosConfig();
65  }
66
67  /*!
68  \brief Parse xios part of configuration file (.iodef.xml)
69   Both client and server need information returned from this function
70  */
71  void CXios::parseXiosConfig()
72  {
73    usingOasis=getin<bool>("using_oasis",false) ;
74    usingServer=getin<bool>("using_server",false) ;
75    usingServer2=getin<bool>("using_server2",false) ;
76    ratioServer2=getin<int>("ratio_server2",50);
77    nbPoolsServer2=getin<int>("number_pools_server2",0);
78    info.setLevel(getin<int>("info_level",0)) ;
79    report.setLevel(getin<int>("info_level",50));
80    printLogs2Files=getin<bool>("print_file",false);
81
82    xiosStack=getin<bool>("xios_stack",true) ;
83    systemStack=getin<bool>("system_stack",false) ;
84    if (xiosStack && systemStack)
85    {
86      xiosStack = false;
87    }
88
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
99    bufferSizeFactor = getin<double>("buffer_size_factor", defaultBufferSizeFactor);
100    minBufferSize = getin<int>("min_buffer_size", 1024 * sizeof(double));
101    maxBufferSize = getin<int>("max_buffer_size", std::numeric_limits<int>::max());
102    recvFieldTimeout = getin<double>("recv_field_timeout", recvFieldTimeout);
103    if (recvFieldTimeout < 0.0)
104      ERROR("CXios::parseXiosConfig()", "recv_field_timeout cannot be negative.");
105
106    checkEventSync = getin<bool>("check_event_sync", checkEventSync);
107
108    globalComm=MPI_COMM_WORLD ;
109  }
110
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  */
117  void CXios::initClientSide(const string& codeId, MPI_Comm& localComm, MPI_Comm& returnComm)
118  TRY
119  {
120    initialize() ;
121
122    isClient = true;
123
124    //CClient::initialize(codeId,localComm,returnComm) ;
125    CClient::initialize(codeId,localComm,returnComm) ;
126   
127    // If there are no server processes then we are in attached mode
128    // and the clients are also servers
129    isServer = !usingServer;
130
131    if (printLogs2Files)
132    {
133      CClient::openInfoStream(clientFile);
134      CClient::openErrorStream(clientFile);
135    }
136    else
137    {
138      CClient::openInfoStream();
139      CClient::openErrorStream();
140    }
141  }
142  CATCH
143
144  void CXios::clientFinalize(void)
145  {
146     CClient::finalize() ;
147         
148#ifdef XIOS_MEMTRACK
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
156     MemTrack::TrackListMemoryUsage() ;
157     MemTrack::TrackDumpBlocks();
158#endif
159
160     CClient::closeInfoStream();
161
162#endif
163  }
164
165  //! Init server by parsing only xios part of config file
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);
172    parseXiosConfig();
173  }
174
175  //! Initialize server then put it into listening state
176  void CXios::initServerSide(void)
177  {
178    initServer();
179    isClient = false;
180    isServer = true;
181
182    // Initialize all aspects MPI
183    CServer::initialize();
184    CServer::finalize();
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
198    CServer::closeInfoStream();
199  }
200
201  //! Parse configuration file
202  void CXios::parseFile(const string& filename)
203  {
204    xml::CXMLParser::ParseFile(filename);
205  }
206
207  //! Set using server
208  void CXios::setUsingServer()
209  {
210    usingServer = true;
211  }
212
213  //! Unset using server
214  void CXios::setNotUsingServer()
215  {
216    usingServer = false;
217  }
218
219  void CXios::launchRessourcesManager(bool isXiosServer)
220  {
221    ressourcesManager_ = new CRessourcesManager(isXiosServer) ;
222  }
223
224  void CXios::launchCouplerManager(bool isXiosServer)
225  {
226    couplerManager_ = new CCouplerManager(isXiosServer) ;
227  }
228
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
244 
245  void CXios::finalizeRessourcesManager()
246  {
247    delete ressourcesManager_;
248  }
249
250  void CXios::finalizeCouplerManager()
251  {
252    delete couplerManager_;
253  }
254
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
271  CPoolRessource* CXios::getPoolRessource(void)
272  {
273    if (isClient) return CClient::getPoolRessource() ;
274    else if (isServer) return CServer::getServersRessource()->getPoolRessource() ;
275  }
276}
277
Note: See TracBrowser for help on using the repository browser.