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

Last change on this file since 1029 was 1029, checked in by rlacroix, 7 years ago

Make the timeout for xios_recv_field configurable.

The new option "recv_field_timeout" can now be used to set the timeout expressed in seconds. Default value is still 10s.

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