source: XIOS/dev/branch_yushan/src/cxios.cpp @ 1037

Last change on this file since 1037 was 1037, checked in by yushan, 4 years ago

initialize the branch

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