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

Last change on this file since 697 was 697, checked in by ymipsl, 9 years ago

Implement registryIn and registryOut functionnalities.
YM

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