source: XIOS/dev/dev_olga/src/cxios.cpp @ 1158

Last change on this file since 1158 was 1158, checked in by oabramkina, 4 years ago

Two server levels: merging with trunk r1137.
There are bugs.

  • 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: 6.3 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
14namespace xios
15{
16  string CXios::rootFile="./iodef.xml" ;
17  string CXios::xiosCodeId="xios.x" ;
18  string CXios::clientFile="./xios_client";
19  string CXios::serverFile="./xios_server";
20  string CXios::serverPrmFile="./xios_server1";
21  string CXios::serverSndFile="./xios_server2";
22
23  bool CXios::isClient ;
24  bool CXios::isServer ;
25  MPI_Comm CXios::globalComm ;
26  bool CXios::usingOasis ;
27  bool CXios::usingServer = false;
28  bool CXios::usingServer2 = false;
29  int CXios::ratioServer2 = 50;
30  double CXios::bufferSizeFactor = 1.0;
31  const double CXios::defaultBufferSizeFactor = 1.0;
32  StdSize CXios::minBufferSize = 1024 * sizeof(double);
33  bool CXios::printLogs2Files;
34  bool CXios::isOptPerformance = true;
35  CRegistry* CXios::globalRegistry = 0;
36  double CXios::recvFieldTimeout = 10.0;
37
38  //! Parse configuration file and create some objects from it
39  void CXios::initialize()
40  {
41    set_new_handler(noMemory);
42    parseFile(rootFile);
43    parseXiosConfig();
44  }
45
46  /*!
47  \brief Parse xios part of configuration file (.iodef.xml)
48   Both client and server need information returned from this function
49  */
50  void CXios::parseXiosConfig()
51  {
52    usingOasis=getin<bool>("using_oasis",false) ;
53    usingServer=getin<bool>("using_server",false) ;
54    usingServer2=getin<bool>("using_server2",false) ;
55    ratioServer2=getin<int>("ratio_server2",50);
56    info.setLevel(getin<int>("info_level",0)) ;
57    report.setLevel(getin<int>("info_level",50));
58    printLogs2Files=getin<bool>("print_file",false);
59
60    StdString bufMemory("memory");
61    StdString bufPerformance("performance");
62    StdString bufOpt = getin<StdString>("optimal_buffer_size", bufPerformance);
63    std::transform(bufOpt.begin(), bufOpt.end(), bufOpt.begin(), ::tolower);
64    if (0 == bufOpt.compare(bufMemory)) isOptPerformance = false;
65    else if (0 != bufOpt.compare(bufPerformance))
66    {
67      ERROR("CXios::parseXiosConfig()", << "optimal_buffer_size must be memory or performance "<< endl );
68    }
69
70    bufferSizeFactor = getin<double>("buffer_size_factor", defaultBufferSizeFactor);
71    minBufferSize = getin<int>("min_buffer_size", 1024 * sizeof(double));
72    recvFieldTimeout = getin<double>("recv_field_timeout", 10.0);
73    if (recvFieldTimeout < 0.0)
74      ERROR("CXios::parseXiosConfig()", "recv_field_timeout cannot be negative.");
75
76    globalComm=MPI_COMM_WORLD ;
77  }
78
79  /*!
80  Initialize client
81  \param [in] codeId identity of context
82  \param [in] localComm local communicator
83  \param [in/out] returnComm communicator corresponding to group of client with same codeId
84  */
85  void CXios::initClientSide(const string& codeId, MPI_Comm& localComm, MPI_Comm& returnComm)
86  {
87    initialize() ;
88
89    isClient = true;
90
91    CClient::initialize(codeId,localComm,returnComm) ;
92    if (CClient::getRank()==0) globalRegistry = new CRegistry(returnComm) ;
93
94    // If there are no server processes then we are in attached mode
95    // and the clients are also servers
96    isServer = !usingServer;
97
98    if (printLogs2Files)
99    {
100      CClient::openInfoStream(clientFile);
101      CClient::openErrorStream(clientFile);
102    }
103    else
104    {
105      CClient::openInfoStream();
106      CClient::openErrorStream();
107    }
108  }
109
110  void CXios::clientFinalize(void)
111  {
112     CClient::finalize() ;
113     if (CClient::getRank()==0)
114     {
115       info(80)<<"Write data base Registry"<<endl<<globalRegistry->toString()<<endl ;
116       globalRegistry->toFile("xios_registry.bin") ;
117       delete globalRegistry ;
118     }
119
120#ifdef XIOS_MEMTRACK
121
122#ifdef XIOS_MEMTRACK_LIGHT
123       report(10) << " Memory report : current memory used by XIOS : "<<  MemTrack::getCurrentMemorySize()*1.0/(1024*1024)<<" Mbyte" << endl ;
124       report(10) << " Memory report : maximum memory used by XIOS : "<<  MemTrack::getMaxMemorySize()*1.0/(1024*1024)<<" Mbyte" << endl ;
125#endif
126
127#ifdef XIOS_MEMTRACK_FULL
128     MemTrack::TrackListMemoryUsage() ;
129     MemTrack::TrackDumpBlocks();
130#endif
131
132     CClient::closeInfoStream();
133
134#endif
135  }
136
137  //! Init server by parsing only xios part of config file
138  void CXios::initServer()
139  {
140    set_new_handler(noMemory);
141    std::set<StdString> parseList;
142    parseList.insert("xios");
143    xml::CXMLParser::ParseFile(rootFile, parseList);
144    parseXiosConfig();
145  }
146
147  //! Initialize server then put it into listening state
148  void CXios::initServerSide(void)
149  {
150    initServer();
151    isClient = false;
152    isServer = true;
153
154    // Initialize all aspects MPI
155    CServer::initialize();
156    if (CServer::getRank()==0) globalRegistry = new CRegistry(CServer::intraComm) ;
157   
158    if (printLogs2Files)
159    {
160      if (CServer::serverLevel == 0)
161      {
162        CServer::openInfoStream(serverFile);
163        CServer::openErrorStream(serverFile);
164      }
165      else if (CServer::serverLevel == 1)
166      {
167        CServer::openInfoStream(serverPrmFile);
168        CServer::openErrorStream(serverPrmFile);
169      }
170      else
171      {
172        CServer::openInfoStream(serverSndFile);
173        CServer::openErrorStream(serverSndFile);
174      }
175    }
176    else
177    {
178      CServer::openInfoStream();
179      CServer::openErrorStream();
180    }
181
182    // Enter the loop to listen message from Client
183    CServer::eventLoop();
184
185    // Finalize
186     if (CServer::getRank()==0)
187     {
188       info(80)<<"Write data base Registry"<<endl<<globalRegistry->toString()<<endl ;
189       globalRegistry->toFile("xios_registry.bin") ;
190       delete globalRegistry ;
191     }
192    CServer::finalize();
193
194#ifdef XIOS_MEMTRACK
195
196#ifdef XIOS_MEMTRACK_LIGHT
197       report(10) << " Memory report : current memory used by XIOS : "<<  MemTrack::getCurrentMemorySize()*1.0/(1024*1024)<<" Mbyte" << endl ;
198       report(10) << " Memory report : maximum memory used by XIOS : "<<  MemTrack::getMaxMemorySize()*1.0/(1024*1024)<<" Mbyte" << endl ;
199#endif
200
201#ifdef XIOS_MEMTRACK_FULL
202     MemTrack::TrackListMemoryUsage() ;
203     MemTrack::TrackDumpBlocks();
204#endif
205#endif
206    CServer::closeInfoStream();
207  }
208
209  //! Parse configuration file
210  void CXios::parseFile(const string& filename)
211  {
212    xml::CXMLParser::ParseFile(filename);
213  }
214
215  //! Set using server
216  void CXios::setUsingServer()
217  {
218    usingServer = true;
219  }
220
221  //! Unset using server
222  void CXios::setNotUsingServer()
223  {
224    usingServer = false;
225  }
226}
Note: See TracBrowser for help on using the repository browser.