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

Last change on this file since 983 was 983, checked in by oabramkina, 5 years ago

My branch

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