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

Last change on this file since 517 was 512, checked in by mhnguyen, 10 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
RevLine 
[300]1
2#include "xmlioserver_spl.hpp"
3#include "cxios.hpp"
[342]4#include "client.hpp"
5#include "server.hpp"
[346]6#include "xml_parser.hpp"
[300]7#include <boost/functional/hash.hpp>
[382]8#include "mpi.hpp"
[400]9#include "memory.hpp"
10#include <new>
[401]11#include "memtrack.hpp"
[300]12
[335]13namespace xios
[300]14{
15  string CXios::rootFile="./iodef.xml" ;
16  string CXios::xiosCodeId="xios.x" ;
[499]17  string CXios::clientFile="./xios_client";
18  string CXios::serverFile="./xios_server";
[490]19
[300]20  bool CXios::isClient ;
21  bool CXios::isServer ;
22  MPI_Comm CXios::globalComm ;
23  bool CXios::usingOasis ;
[491]24  bool CXios::usingServer = false;
[512]25  double CXios::bufferServerFactorSize=1.0 ;
26  double CXios::defaultBufferServerFactorSize=1.0 ;
[490]27  bool CXios::printInfo2File;
[499]28  bool CXios::isServerSide;
[511]29  bool CXios::isOptPerformance = true;
[490]30
[512]31  //! Parse configuration file and create some objects from it
[300]32  void CXios::initialize()
33  {
[400]34    set_new_handler(noMemory);
[346]35    parseFile(rootFile);
[511]36    parseXiosConfig();
37  }
38
[512]39  /*!
40  \brief Parse xios part of configuration file (.iodef.xml)
41   Both client and server need information returned from this function
42  */
[511]43  void CXios::parseXiosConfig()
44  {
[311]45    usingOasis=getin<bool>("using_oasis",false) ;
[506]46    usingServer=getin<bool>("using_server",false) ;
[311]47    info.setLevel(getin<int>("info_level",0)) ;
[512]48    report.setLevel(getin<int>("info_level",50));
[491]49    printInfo2File=getin<bool>("print_file",false);
[512]50
[511]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) ;
[300]62    globalComm=MPI_COMM_WORLD ;
63  }
64
[512]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  */
[300]71  void CXios::initClientSide(const string& codeId, MPI_Comm& localComm, MPI_Comm& returnComm)
72  {
73    initialize() ;
[490]74
[300]75    isClient=true;
[491]76
77    CClient::initialize(codeId,localComm,returnComm) ;
78
[499]79    if (usingServer) isServerSide = isServer=false;
80    else isServerSide = isServer=true;
[490]81
82    if (printInfo2File)
[499]83      CClient::openInfoStream(clientFile);
[490]84    else
85      CClient::openInfoStream();
86  }
[300]87
88  void CXios::clientFinalize(void)
89  {
[490]90     CClient::finalize() ;
91     CClient::closeInfoStream();
92
[401]93#ifdef XIOS_MEMTRACK
94     MemTrack::TrackListMemoryUsage() ;
[490]95     MemTrack::TrackDumpBlocks();
[401]96#endif
[490]97  }
98
[512]99  //! Init server by parsing only xios part of config file
[509]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);
[511]106    parseXiosConfig();
[509]107  }
108
[512]109  //! Initialize server then put it into listening state
[300]110  void CXios::initServerSide(void)
111  {
[509]112    initServer();
[300]113    isClient=true;
114    isServer=false ;
115
[499]116    isServerSide = true;
117
[491]118    // Initialize all aspects MPI
[490]119    CServer::initialize();
120
121    if (printInfo2File)
[499]122      CServer::openInfoStream(serverFile);
[490]123    else
124      CServer::openInfoStream();
125
[491]126    // Enter the loop to listen message from Client
[490]127    CServer::eventLoop();
128
[491]129    // Finalize
[490]130    CServer::finalize();
131    CServer::closeInfoStream();
132  }
133
[512]134  //! Parse configuration file
[346]135  void CXios::parseFile(const string& filename)
136  {
[490]137    xml::CXMLParser::ParseFile(filename);
[346]138  }
[491]139
[512]140  //! Set using server
[491]141  void CXios::setUsingServer()
142  {
143    usingServer = true;
144  }
145
[512]146  //! Unset using server
[491]147  void CXios::setNotUsingServer()
148  {
149    usingServer = false;
150  }
[300]151}
Note: See TracBrowser for help on using the repository browser.