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

Last change on this file since 1150 was 1130, checked in by oabramkina, 7 years ago

Two-level server: merging new grid functionalities and changes in the communication protocol (e.g. non-blocking context finalize, registries, oasis).

Tests on curie: test_client, test_complete, nemo (test_xios2_cmip6.exe).

To do: non-structured grid, check reading, possible bug in client/server initialization (?).

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