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

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

Make sure CXios::isClient and CXios::isServer variables are used in a sensible way.

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