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

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

Intermeadiate version for merging with new server functionalities.

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