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

Last change on this file since 799 was 799, checked in by rlacroix, 7 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
Line 
1
2#include "xmlioserver_spl.hpp"
3#include "cxios.hpp"
4#include "client.hpp"
5#include "server.hpp"
6#include "xml_parser.hpp"
7#include <boost/functional/hash.hpp>
8#include "mpi.hpp"
9#include "memory.hpp"
10#include <new>
11#include "memtrack.hpp"
12#include "registry.hpp"
13
14namespace xios
15{
16  string CXios::rootFile="./iodef.xml" ;
17  string CXios::xiosCodeId="xios.x" ;
18  string CXios::clientFile="./xios_client";
19  string CXios::serverFile="./xios_server";
20
21  bool CXios::isClient ;
22  bool CXios::isServer ;
23  MPI_Comm CXios::globalComm ;
24  bool CXios::usingOasis ;
25  bool CXios::usingServer = false;
26  size_t CXios::bufferSize ;
27  double CXios::bufferServerFactorSize=2 ;
28  size_t CXios::defaultBufferSize=1024*1024*100 ; // 100Mo
29  double CXios::defaultBufferServerFactorSize=2 ;
30  bool CXios::printLogs2Files;
31  CRegistry* CXios::globalRegistry = 0;
32
33
34  void CXios::initialize()
35  {
36    set_new_handler(noMemory);
37    parseFile(rootFile);
38    usingOasis=getin<bool>("using_oasis",false) ;
39    usingServer=getin<bool>("using_server",false) ;
40    info.setLevel(getin<int>("info_level",0)) ;
41    printLogs2Files=getin<bool>("print_file",false);
42    bufferSize=getin<size_t>("buffer_size",defaultBufferSize) ;
43    bufferServerFactorSize=getin<double>("buffer_server_factor_size",defaultBufferServerFactorSize) ;
44    globalComm=MPI_COMM_WORLD ;
45  }
46
47
48  void CXios::initClientSide(const string& codeId, MPI_Comm& localComm, MPI_Comm& returnComm)
49  {
50
51    initialize() ;
52
53    isClient=true;
54
55    CClient::initialize(codeId,localComm,returnComm) ;
56    if (CClient::getRank()==0) globalRegistry = new CRegistry(returnComm) ;
57
58    if (usingServer) isServer=false;
59    else isServer=true;
60
61    if (printLogs2Files)
62    {
63      CClient::openInfoStream(clientFile);
64      CClient::openErrorStream(clientFile);
65    }
66    else
67    {
68      CClient::openInfoStream();
69      CClient::openErrorStream();
70    }
71  }
72
73  void CXios::clientFinalize(void)
74  {
75     CClient::finalize() ;
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     }
82     CClient::closeInfoStream();
83
84#ifdef XIOS_MEMTRACK
85     MemTrack::TrackListMemoryUsage() ;
86     MemTrack::TrackDumpBlocks();
87#endif
88  }
89
90
91  void CXios::initServerSide(void)
92  {
93    initialize();
94
95    isClient=true;
96    isServer=false ;
97
98    // Initialize all aspects MPI
99    CServer::initialize();
100    if (CServer::getRank()==0) globalRegistry = new CRegistry(CServer::intraComm) ;
101
102    if (printLogs2Files)
103    {
104      CServer::openInfoStream(serverFile);
105      CServer::openErrorStream(serverFile);
106    }
107    else
108    {
109      CServer::openInfoStream();
110      CServer::openErrorStream();
111    }
112
113    // Enter the loop to listen message from Client
114    CServer::eventLoop();
115
116    // Finalize
117    CServer::finalize();
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    }
124    CServer::closeInfoStream();
125  }
126
127  void CXios::parseFile(const string& filename)
128  {
129    xml::CXMLParser::ParseFile(filename);
130  }
131
132  void CXios::setUsingServer()
133  {
134    usingServer = true;
135  }
136
137  void CXios::setNotUsingServer()
138  {
139    usingServer = false;
140  }
141}
Note: See TracBrowser for help on using the repository browser.