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

Last change on this file since 1190 was 1137, checked in by ymipsl, 7 years ago

Add "light" memory tracking which must be activated at compile time : make_xios --memtrack light

  • report at info level 10 : max memory consumption and the current memory consumption at the end of exection
  • info at info level 50 : at each timestep, the current memory consumption is printed

YM

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