source: XIOS/branchs/xios-1.0/src/cxios.cpp @ 548

Last change on this file since 548 was 548, checked in by rlacroix, 8 years ago

Backport r523 into the stable branch.

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: 2.7 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  size_t CXios::bufferSize ;
26  double CXios::bufferServerFactorSize=2 ;
27  size_t CXios::defaultBufferSize=1024*1024*100 ; // 100Mo
28  double CXios::defaultBufferServerFactorSize=2 ;
29  bool CXios::printLogs2Files;
30
31
32  void CXios::initialize()
33  {
34    set_new_handler(noMemory);
35    parseFile(rootFile);
36    usingOasis=getin<bool>("using_oasis",false) ;
37    usingServer=getin<bool>("using_server",false) ;
38    info.setLevel(getin<int>("info_level",0)) ;
39    printLogs2Files=getin<bool>("print_file",false);
40    bufferSize=getin<size_t>("buffer_size",defaultBufferSize) ;
41    bufferServerFactorSize=getin<double>("buffer_server_factor_size",defaultBufferServerFactorSize) ;
42    globalComm=MPI_COMM_WORLD ;
43  }
44
45
46  void CXios::initClientSide(const string& codeId, MPI_Comm& localComm, MPI_Comm& returnComm)
47  {
48
49    initialize() ;
50
51    isClient=true;
52
53    CClient::initialize(codeId,localComm,returnComm) ;
54
55    if (usingServer) isServer=false;
56    else isServer=true;
57
58    if (printLogs2Files)
59    {
60      CClient::openInfoStream(clientFile);
61      CClient::openErrorStream(clientFile);
62    }
63    else
64    {
65      CClient::openInfoStream();
66      CClient::openErrorStream();
67    }
68  }
69
70  void CXios::clientFinalize(void)
71  {
72     CClient::finalize() ;
73     CClient::closeInfoStream();
74
75#ifdef XIOS_MEMTRACK
76     MemTrack::TrackListMemoryUsage() ;
77     MemTrack::TrackDumpBlocks();
78#endif
79  }
80
81
82  void CXios::initServerSide(void)
83  {
84    initialize();
85
86    isClient=true;
87    isServer=false ;
88
89    // Initialize all aspects MPI
90    CServer::initialize();
91
92    if (printLogs2Files)
93    {
94      CServer::openInfoStream(serverFile);
95      CServer::openErrorStream(serverFile);
96    }
97    else
98    {
99      CServer::openInfoStream();
100      CServer::openErrorStream();
101    }
102
103    // Enter the loop to listen message from Client
104    CServer::eventLoop();
105
106    // Finalize
107    CServer::finalize();
108    CServer::closeInfoStream();
109  }
110
111  void CXios::parseFile(const string& filename)
112  {
113    xml::CXMLParser::ParseFile(filename);
114  }
115
116  void CXios::setUsingServer()
117  {
118    usingServer = true;
119  }
120
121  void CXios::setNotUsingServer()
122  {
123    usingServer = false;
124  }
125}
Note: See TracBrowser for help on using the repository browser.