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

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

dev: intermediate commit.

  • 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::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(void)
139  {
140    initServer();
141
142    // Initialize all aspects MPI
143    CServer::initialize();
144    isServer = true;
145    if (CServer::serverLevel == 1)
146      isClient = true;
147    else
148      isClient = false;
149
150    if (CServer::getRank()==0) globalRegistry = new CRegistry(CServer::intraComm) ;
151   
152    if (printLogs2Files)
153    {
154      if (CServer::serverLevel == 0)
155      {
156        CServer::openInfoStream(serverFile);
157        CServer::openErrorStream(serverFile);
158      }
159      else if (CServer::serverLevel == 1)
160      {
161        CServer::openInfoStream(serverPrmFile);
162        CServer::openErrorStream(serverPrmFile);
163      }
164      else
165      {
166        CServer::openInfoStream(serverSndFile);
167        CServer::openErrorStream(serverSndFile);
168      }
169    }
170    else
171    {
172      CServer::openInfoStream();
173      CServer::openErrorStream();
174    }
175
176    // Enter the loop to listen message from Client
177    CServer::eventLoop();
178
179    // Finalize
180     if (CServer::getRank()==0)
181     {
182       info(80)<<"Write data base Registry"<<endl<<globalRegistry->toString()<<endl ;
183       globalRegistry->toFile("xios_registry.bin") ;
184       delete globalRegistry ;
185     }
186    CServer::finalize();
187    CServer::closeInfoStream();
188  }
189
190  //! Parse configuration file
191  void CXios::parseFile(const string& filename)
192  {
193    xml::CXMLParser::ParseFile(filename);
194  }
195
196  //! Set using server
197  void CXios::setUsingServer()
198  {
199    usingServer = true;
200  }
201
202  //! Unset using server
203  void CXios::setNotUsingServer()
204  {
205    usingServer = false;
206  }
207}
Note: See TracBrowser for help on using the repository browser.