source: XIOS/trunk/src/cxios.cpp @ 956

Last change on this file since 956 was 956, checked in by rlacroix, 5 years ago

Make sure CXios::isClient and CXios::isServer variables are used in a sensible way.

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