source: XIOS/branchs/xios-1.0/src/cxios.cpp @ 910

Last change on this file since 910 was 799, checked in by rlacroix, 9 years ago

Add registry

  • 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: 3.3 KB
RevLine 
[300]1
2#include "xmlioserver_spl.hpp"
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"
[799]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;
[317]26  size_t CXios::bufferSize ;
27  double CXios::bufferServerFactorSize=2 ;
28  size_t CXios::defaultBufferSize=1024*1024*100 ; // 100Mo
29  double CXios::defaultBufferServerFactorSize=2 ;
[548]30  bool CXios::printLogs2Files;
[799]31  CRegistry* CXios::globalRegistry = 0;
[490]32
33
[300]34  void CXios::initialize()
35  {
[400]36    set_new_handler(noMemory);
[346]37    parseFile(rootFile);
[311]38    usingOasis=getin<bool>("using_oasis",false) ;
[507]39    usingServer=getin<bool>("using_server",false) ;
[311]40    info.setLevel(getin<int>("info_level",0)) ;
[548]41    printLogs2Files=getin<bool>("print_file",false);
[317]42    bufferSize=getin<size_t>("buffer_size",defaultBufferSize) ;
43    bufferServerFactorSize=getin<double>("buffer_server_factor_size",defaultBufferServerFactorSize) ;
[300]44    globalComm=MPI_COMM_WORLD ;
45  }
46
47
48  void CXios::initClientSide(const string& codeId, MPI_Comm& localComm, MPI_Comm& returnComm)
49  {
[490]50
[300]51    initialize() ;
[490]52
[300]53    isClient=true;
[491]54
55    CClient::initialize(codeId,localComm,returnComm) ;
[799]56    if (CClient::getRank()==0) globalRegistry = new CRegistry(returnComm) ;
[491]57
[548]58    if (usingServer) isServer=false;
59    else isServer=true;
[490]60
[548]61    if (printLogs2Files)
62    {
[499]63      CClient::openInfoStream(clientFile);
[548]64      CClient::openErrorStream(clientFile);
65    }
[490]66    else
[548]67    {
[490]68      CClient::openInfoStream();
[548]69      CClient::openErrorStream();
70    }
[490]71  }
[300]72
73  void CXios::clientFinalize(void)
74  {
[490]75     CClient::finalize() ;
[799]76     if (CClient::getRank()==0)
77     {
78       info(80)<<"Write data base Registry"<<endl<<globalRegistry->toString()<<endl ;
79       globalRegistry->toFile("xios_registry.bin") ;
80       delete globalRegistry ;
81     }
[490]82     CClient::closeInfoStream();
83
[401]84#ifdef XIOS_MEMTRACK
85     MemTrack::TrackListMemoryUsage() ;
[490]86     MemTrack::TrackDumpBlocks();
[401]87#endif
[490]88  }
89
90
[300]91  void CXios::initServerSide(void)
92  {
93    initialize();
[499]94
[300]95    isClient=true;
96    isServer=false ;
97
[491]98    // Initialize all aspects MPI
[490]99    CServer::initialize();
[799]100    if (CServer::getRank()==0) globalRegistry = new CRegistry(CServer::intraComm) ;
[490]101
[548]102    if (printLogs2Files)
103    {
[499]104      CServer::openInfoStream(serverFile);
[548]105      CServer::openErrorStream(serverFile);
106    }
[490]107    else
[548]108    {
[490]109      CServer::openInfoStream();
[548]110      CServer::openErrorStream();
111    }
[490]112
[491]113    // Enter the loop to listen message from Client
[490]114    CServer::eventLoop();
115
[491]116    // Finalize
[490]117    CServer::finalize();
[799]118    if (CServer::getRank()==0)
119    {
120      info(80)<<"Write data base Registry"<<endl<<globalRegistry->toString()<<endl ;
121      globalRegistry->toFile("xios_registry.bin") ;
122      delete globalRegistry ;
123    }
[490]124    CServer::closeInfoStream();
125  }
126
[346]127  void CXios::parseFile(const string& filename)
128  {
[490]129    xml::CXMLParser::ParseFile(filename);
[346]130  }
[491]131
132  void CXios::setUsingServer()
133  {
134    usingServer = true;
135  }
136
137  void CXios::setNotUsingServer()
138  {
139    usingServer = false;
140  }
[300]141}
Note: See TracBrowser for help on using the repository browser.