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

Last change on this file since 1132 was 1130, checked in by oabramkina, 7 years ago

Two-level server: merging new grid functionalities and changes in the communication protocol (e.g. non-blocking context finalize, registries, oasis).

Tests on curie: test_client, test_complete, nemo (test_xios2_cmip6.exe).

To do: non-structured grid, check reading, possible bug in client/server initialization (?).

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