source: XIOS/dev/dev_olga/src/cxios.cpp @ 1009

Last change on this file since 1009 was 983, checked in by oabramkina, 8 years ago

My branch

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