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

Last change on this file since 523 was 523, checked in by rlacroix, 9 years ago

Improve the message error handling by mimicking the behavior of the info/report logs.

Output the error messages to the standart error message until the context is correctly initialized. Then, output the error messages to a file if the user has set "print_file" parameter to "true".

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