source: XIOS/dev/branch_openmp/src/cxios.cpp @ 1328

Last change on this file since 1328 was 1328, checked in by yushan, 6 years ago

dev_omp

  • 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: 6.3 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"
13using namespace ep_lib;
14
15namespace xios
16{
17  string CXios::rootFile="./iodef.xml" ;
18  string CXios::xiosCodeId="xios.x" ;
19  string CXios::clientFile="./xios_client";
20  string CXios::serverFile="./xios_server";
21
22  bool CXios::isClient ;
23  bool CXios::isServer ;
24  MPI_Comm CXios::globalComm ;
25  bool CXios::usingOasis ;
26  bool CXios::usingServer = false;
27  double CXios::bufferSizeFactor = 1.0;
28  const double CXios::defaultBufferSizeFactor = 1.0;
29  StdSize CXios::minBufferSize = 1024 * sizeof(double);
30  bool CXios::printLogs2Files;
31  bool CXios::isOptPerformance = true;
32  CRegistry* CXios::globalRegistry = 0;
33  double CXios::recvFieldTimeout = 10.0;
34
35  //! Parse configuration file and create some objects from it
36  void CXios::initialize()
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    recvFieldTimeout = getin<double>("recv_field_timeout", 10.0);
68    if (recvFieldTimeout < 0.0)
69      ERROR("CXios::parseXiosConfig()", "recv_field_timeout cannot be negative.");
70
71    //globalComm=MPI_COMM_WORLD ;
72    int num_ep;
73    if(isClient) 
74    { 
75      num_ep = omp_get_num_threads();
76    }
77       
78    if(isServer) 
79    { 
80      num_ep = omp_get_num_threads();
81    }
82       
83    MPI_Info info;
84    #pragma omp master
85    {
86      MPI_Comm *ep_comm;
87      MPI_Comm_create_endpoints(MPI_COMM_WORLD, num_ep, info, ep_comm);  // servers should reach here too.
88      passage = ep_comm; 
89    }
90       
91    #pragma omp barrier
92   
93         
94    CXios::globalComm = passage[omp_get_thread_num()];
95  }
96
97  /*!
98  Initialize client
99  \param [in] codeId identity of context
100  \param [in] localComm local communicator
101  \param [in/out] returnComm communicator corresponding to group of client with same codeId
102  */
103  void CXios::initClientSide(const string& codeId, MPI_Comm& localComm, MPI_Comm& returnComm)
104  {
105    isClient = true;
106   
107    initialize() ;
108
109    CClient::initialize(codeId,localComm,returnComm) ;
110    if (CClient::getRank()==0) globalRegistry = new CRegistry(returnComm) ;
111
112    // If there are no server processes then we are in attached mode
113    // and the clients are also servers
114    isServer = !usingServer;
115
116    if (printLogs2Files)
117    {
118      CClient::openInfoStream(clientFile);
119      CClient::openErrorStream(clientFile);
120    }
121    else
122    {
123      CClient::openInfoStream();
124      CClient::openErrorStream();
125    }
126  }
127
128  void CXios::clientFinalize(void)
129  {
130     CClient::finalize() ;
131     if (CClient::getRank()==0)
132     {
133       info(80)<<"Write data base Registry"<<endl<<globalRegistry->toString()<<endl ;
134       globalRegistry->toFile("xios_registry.bin") ;
135       delete globalRegistry ;
136     }
137
138#ifdef XIOS_MEMTRACK
139
140#ifdef XIOS_MEMTRACK_LIGHT
141       report(10) << " Memory report : current memory used by XIOS : "<<  MemTrack::getCurrentMemorySize()*1.0/(1024*1024)<<" Mbyte" << endl ;
142       report(10) << " Memory report : maximum memory used by XIOS : "<<  MemTrack::getMaxMemorySize()*1.0/(1024*1024)<<" Mbyte" << endl ;
143#endif
144
145#ifdef XIOS_MEMTRACK_FULL
146     MemTrack::TrackListMemoryUsage() ;
147     MemTrack::TrackDumpBlocks();
148#endif
149
150     CClient::closeInfoStream();
151
152#endif
153  }
154
155  //! Init server by parsing only xios part of config file
156  void CXios::initServer()
157  {
158    set_new_handler(noMemory);
159    std::set<StdString> parseList;
160    parseList.insert("xios");
161    xml::CXMLParser::ParseFile(rootFile, parseList);
162    parseXiosConfig();
163  }
164
165  //! Initialize server then put it into listening state
166  void CXios::initServerSide(void)
167  {
168   
169    isClient = false;
170    isServer = true;
171   
172    initServer();
173
174    // Initialize all aspects MPI
175    CServer::initialize();
176    if (CServer::getRank()==0) globalRegistry = new CRegistry(CServer::intraComm) ;
177   
178    if (printLogs2Files)
179    {
180      CServer::openInfoStream(serverFile);
181      CServer::openErrorStream(serverFile);
182    }
183    else
184    {
185      CServer::openInfoStream();
186      CServer::openErrorStream();
187    }
188
189    // Enter the loop to listen message from Client
190    CServer::eventLoop();
191
192    // Finalize
193     if (CServer::getRank()==0)
194     {
195       info(80)<<"Write data base Registry"<<endl<<globalRegistry->toString()<<endl ;
196       globalRegistry->toFile("xios_registry.bin") ;
197       delete globalRegistry ;
198     }
199    CServer::finalize();
200
201#ifdef XIOS_MEMTRACK
202
203#ifdef XIOS_MEMTRACK_LIGHT
204       report(10) << " Memory report : current memory used by XIOS : "<<  MemTrack::getCurrentMemorySize()*1.0/(1024*1024)<<" Mbyte" << endl ;
205       report(10) << " Memory report : maximum memory used by XIOS : "<<  MemTrack::getMaxMemorySize()*1.0/(1024*1024)<<" Mbyte" << endl ;
206#endif
207
208#ifdef XIOS_MEMTRACK_FULL
209     MemTrack::TrackListMemoryUsage() ;
210     MemTrack::TrackDumpBlocks();
211#endif
212#endif
213    CServer::closeInfoStream();
214  }
215
216  //! Parse configuration file
217  void CXios::parseFile(const string& filename)
218  {
219    xml::CXMLParser::ParseFile(filename);
220  }
221
222  //! Set using server
223  void CXios::setUsingServer()
224  {
225    usingServer = true;
226  }
227
228  //! Unset using server
229  void CXios::setNotUsingServer()
230  {
231    usingServer = false;
232  }
233}
Note: See TracBrowser for help on using the repository browser.