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

Last change on this file since 1027 was 1021, checked in by oabramkina, 7 years ago

Intermeadiate version for merging with new server functionalities.

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