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

Last change on this file since 517 was 512, checked in by mhnguyen, 9 years ago

Correct bug causing infinite run on multiple server and do some code clean

+) Correct a stupid typo which causes the bug
+) Add comments for class Contextclient
+) Remove some redundant codes

Test
+) On Curie
+) Connection mode: Attached: One and Multiple; Seperated: One and Multiple server
+) File mode: One and multiple file
+) All tests passed (Will it make the trusting board become red :)? )

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