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

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

Two server levels: merging registries of secondary server pools into one and then writing the merged one.

Tested on curie with toy_cmip6.

  • 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: 8.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" ;
[499]18  string CXios::clientFile="./xios_client";
19  string CXios::serverFile="./xios_server";
[1021]20  string CXios::serverPrmFile="./xios_server1";
21  string CXios::serverSndFile="./xios_server2";
[490]22
[300]23  bool CXios::isClient ;
24  bool CXios::isServer ;
25  MPI_Comm CXios::globalComm ;
26  bool CXios::usingOasis ;
[491]27  bool CXios::usingServer = false;
[1021]28  bool CXios::usingServer2 = false;
29  int CXios::ratioServer2 = 50;
[718]30  double CXios::bufferSizeFactor = 1.0;
31  const double CXios::defaultBufferSizeFactor = 1.0;
[719]32  StdSize CXios::minBufferSize = 1024 * sizeof(double);
[523]33  bool CXios::printLogs2Files;
[511]34  bool CXios::isOptPerformance = true;
[697]35  CRegistry* CXios::globalRegistry = 0;
[1158]36  double CXios::recvFieldTimeout = 10.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) ;
[1021]54    usingServer2=getin<bool>("using_server2",false) ;
55    ratioServer2=getin<int>("ratio_server2",50);
[311]56    info.setLevel(getin<int>("info_level",0)) ;
[512]57    report.setLevel(getin<int>("info_level",50));
[523]58    printLogs2Files=getin<bool>("print_file",false);
[512]59
[511]60    StdString bufMemory("memory");
61    StdString bufPerformance("performance");
62    StdString bufOpt = getin<StdString>("optimal_buffer_size", bufPerformance);
63    std::transform(bufOpt.begin(), bufOpt.end(), bufOpt.begin(), ::tolower);
64    if (0 == bufOpt.compare(bufMemory)) isOptPerformance = false;
65    else if (0 != bufOpt.compare(bufPerformance))
66    {
67      ERROR("CXios::parseXiosConfig()", << "optimal_buffer_size must be memory or performance "<< endl );
68    }
69
[718]70    bufferSizeFactor = getin<double>("buffer_size_factor", defaultBufferSizeFactor);
[719]71    minBufferSize = getin<int>("min_buffer_size", 1024 * sizeof(double));
[1158]72    recvFieldTimeout = getin<double>("recv_field_timeout", 10.0);
73    if (recvFieldTimeout < 0.0)
74      ERROR("CXios::parseXiosConfig()", "recv_field_timeout cannot be negative.");
[718]75
[300]76    globalComm=MPI_COMM_WORLD ;
77  }
78
[512]79  /*!
80  Initialize client
81  \param [in] codeId identity of context
82  \param [in] localComm local communicator
83  \param [in/out] returnComm communicator corresponding to group of client with same codeId
84  */
[300]85  void CXios::initClientSide(const string& codeId, MPI_Comm& localComm, MPI_Comm& returnComm)
86  {
87    initialize() ;
[490]88
[956]89    isClient = true;
[491]90
91    CClient::initialize(codeId,localComm,returnComm) ;
[697]92    if (CClient::getRank()==0) globalRegistry = new CRegistry(returnComm) ;
[491]93
[956]94    // If there are no server processes then we are in attached mode
95    // and the clients are also servers
96    isServer = !usingServer;
[490]97
[523]98    if (printLogs2Files)
99    {
[499]100      CClient::openInfoStream(clientFile);
[523]101      CClient::openErrorStream(clientFile);
102    }
[490]103    else
[523]104    {
[490]105      CClient::openInfoStream();
[523]106      CClient::openErrorStream();
107    }
[490]108  }
[300]109
110  void CXios::clientFinalize(void)
111  {
[490]112     CClient::finalize() ;
[697]113     if (CClient::getRank()==0)
114     {
115       info(80)<<"Write data base Registry"<<endl<<globalRegistry->toString()<<endl ;
116       globalRegistry->toFile("xios_registry.bin") ;
117       delete globalRegistry ;
118     }
[490]119
[401]120#ifdef XIOS_MEMTRACK
[1158]121
122#ifdef XIOS_MEMTRACK_LIGHT
123       report(10) << " Memory report : current memory used by XIOS : "<<  MemTrack::getCurrentMemorySize()*1.0/(1024*1024)<<" Mbyte" << endl ;
124       report(10) << " Memory report : maximum memory used by XIOS : "<<  MemTrack::getMaxMemorySize()*1.0/(1024*1024)<<" Mbyte" << endl ;
125#endif
126
127#ifdef XIOS_MEMTRACK_FULL
[401]128     MemTrack::TrackListMemoryUsage() ;
[490]129     MemTrack::TrackDumpBlocks();
[401]130#endif
[1158]131
132     CClient::closeInfoStream();
133
134#endif
[490]135  }
136
[512]137  //! Init server by parsing only xios part of config file
[509]138  void CXios::initServer()
139  {
140    set_new_handler(noMemory);
141    std::set<StdString> parseList;
142    parseList.insert("xios");
143    xml::CXMLParser::ParseFile(rootFile, parseList);
[511]144    parseXiosConfig();
[509]145  }
146
[512]147  //! Initialize server then put it into listening state
[1054]148  void CXios::initServerSide(void)
[300]149  {
[509]150    initServer();
[1158]151    isClient = false;
152    isServer = true;
[1021]153
154    // Initialize all aspects MPI
155    CServer::initialize();
[697]156    if (CServer::getRank()==0) globalRegistry = new CRegistry(CServer::intraComm) ;
157   
[523]158    if (printLogs2Files)
159    {
[1021]160      if (CServer::serverLevel == 0)
[983]161      {
162        CServer::openInfoStream(serverFile);
163        CServer::openErrorStream(serverFile);
164      }
[1021]165      else if (CServer::serverLevel == 1)
[983]166      {
[1021]167        CServer::openInfoStream(serverPrmFile);
168        CServer::openErrorStream(serverPrmFile);
[983]169      }
170      else
171      {
[1021]172        CServer::openInfoStream(serverSndFile);
173        CServer::openErrorStream(serverSndFile);
[983]174      }
[523]175    }
[490]176    else
[523]177    {
[490]178      CServer::openInfoStream();
[523]179      CServer::openErrorStream();
180    }
[490]181
[491]182    // Enter the loop to listen message from Client
[490]183    CServer::eventLoop();
184
[491]185    // Finalize
[1168]186    if (!usingServer2)
187    {
188      if (CServer::getRank()==0)
189      {
190        info(80)<<"Write data base Registry"<<endl<<globalRegistry->toString()<<endl ;
191        globalRegistry->toFile("xios_registry.bin") ;
192        delete globalRegistry ;
193      }
194    }
195    else
196    {
197      // If using two server levels, first merge globalRegistry of each server pool into one registry on the first pool
198      if (CServer::serverLevel == 2)
199      {
200        vector<int>& secondaryServerGlobalRanks = CServer::getSecondaryServerGlobalRanks();
201        int firstPoolGlobalRank = secondaryServerGlobalRanks[0];
202        int rankGlobal;
203        MPI_Comm_rank(globalComm, &rankGlobal);
204
205        // All pools (except the first): send globalRegistry to the first pool
206        if (rankGlobal != firstPoolGlobalRank)
207        {
208          int registrySize = globalRegistry->size();
209          MPI_Send(&registrySize,1,MPI_LONG,firstPoolGlobalRank,15,CXios::globalComm) ;
210          CBufferOut buffer(registrySize) ;
211          globalRegistry->toBuffer(buffer) ;
212          MPI_Send(buffer.start(),registrySize,MPI_CHAR,firstPoolGlobalRank,15,CXios::globalComm) ;
213        }
214
215        // First pool: receive globalRegistry of all secondary server pools, merge and write the resultant registry
216        else
217        {
218          MPI_Status status;
219          char* recvBuff;
220
221          CRegistry globalRegistrySndServers (CServer::intraComm);
222          globalRegistrySndServers.mergeRegistry(*globalRegistry) ;
223
224          for (int i=1; i< secondaryServerGlobalRanks.size(); i++)
225          {
226            int rank = secondaryServerGlobalRanks[i];
227            int registrySize = 0;
228            MPI_Recv(&registrySize, 1, MPI_LONG, rank, 15, CXios::globalComm, &status);
229            recvBuff = new char[registrySize];
230            MPI_Recv(recvBuff, registrySize, MPI_CHAR, rank, 15, CXios::globalComm, &status);
231            CBufferIn buffer(recvBuff, registrySize) ;
232            CRegistry recvRegistry;
233            recvRegistry.fromBuffer(buffer) ;
234            globalRegistrySndServers.mergeRegistry(recvRegistry) ;
235            delete[] recvBuff;
236          }
237
238          info(80)<<"Write data base Registry"<<endl<<globalRegistrySndServers.toString()<<endl ;
239          globalRegistrySndServers.toFile("xios_registry.bin") ;
240
241        }
242      }
243      delete globalRegistry;
244    }
[490]245    CServer::finalize();
[1158]246
247#ifdef XIOS_MEMTRACK
248
249#ifdef XIOS_MEMTRACK_LIGHT
250       report(10) << " Memory report : current memory used by XIOS : "<<  MemTrack::getCurrentMemorySize()*1.0/(1024*1024)<<" Mbyte" << endl ;
251       report(10) << " Memory report : maximum memory used by XIOS : "<<  MemTrack::getMaxMemorySize()*1.0/(1024*1024)<<" Mbyte" << endl ;
252#endif
253
254#ifdef XIOS_MEMTRACK_FULL
255     MemTrack::TrackListMemoryUsage() ;
256     MemTrack::TrackDumpBlocks();
257#endif
258#endif
[490]259    CServer::closeInfoStream();
260  }
261
[512]262  //! Parse configuration file
[346]263  void CXios::parseFile(const string& filename)
264  {
[490]265    xml::CXMLParser::ParseFile(filename);
[346]266  }
[491]267
[512]268  //! Set using server
[491]269  void CXios::setUsingServer()
270  {
271    usingServer = true;
272  }
273
[512]274  //! Unset using server
[491]275  void CXios::setNotUsingServer()
276  {
277    usingServer = false;
278  }
[300]279}
Note: See TracBrowser for help on using the repository browser.