source: XIOS/dev/branch_yushan_merged/src/cxios.cpp @ 1160

Last change on this file since 1160 was 1160, checked in by yushan, 7 years ago

fix bad commit. Back to R1155 branch not merged

  • 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.4 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{
[490]16
[1134]17  extern int test_omp_rank;
18  #pragma omp threadprivate(test_omp_rank)
19
20  const string CXios::rootFile="./iodef.xml" ;
21  const string CXios::xiosCodeId="xios.x" ;
22  const string CXios::clientFile="./xios_client";
23  const string CXios::serverFile="./xios_server";
24
25
[300]26  bool CXios::isClient ;
27  bool CXios::isServer ;
[1134]28
29
[300]30  MPI_Comm CXios::globalComm ;
[1134]31
32 
[300]33  bool CXios::usingOasis ;
[491]34  bool CXios::usingServer = false;
[1134]35
36
[718]37  double CXios::bufferSizeFactor = 1.0;
38  const double CXios::defaultBufferSizeFactor = 1.0;
[719]39  StdSize CXios::minBufferSize = 1024 * sizeof(double);
[1134]40
41
[523]42  bool CXios::printLogs2Files;
[511]43  bool CXios::isOptPerformance = true;
[697]44  CRegistry* CXios::globalRegistry = 0;
[1029]45  double CXios::recvFieldTimeout = 10.0;
[490]46
[512]47  //! Parse configuration file and create some objects from it
[300]48  void CXios::initialize()
49  {
[400]50    set_new_handler(noMemory);
[1134]51   
52   
53    #pragma omp critical
54    {
55      parseFile(rootFile); 
56    }
57    #pragma omp barrier
[511]58    parseXiosConfig();
59  }
60
[512]61  /*!
62  \brief Parse xios part of configuration file (.iodef.xml)
63   Both client and server need information returned from this function
64  */
[511]65  void CXios::parseXiosConfig()
66  {
[311]67    usingOasis=getin<bool>("using_oasis",false) ;
[506]68    usingServer=getin<bool>("using_server",false) ;
[311]69    info.setLevel(getin<int>("info_level",0)) ;
[512]70    report.setLevel(getin<int>("info_level",50));
[523]71    printLogs2Files=getin<bool>("print_file",false);
[512]72
[511]73    StdString bufMemory("memory");
74    StdString bufPerformance("performance");
75    StdString bufOpt = getin<StdString>("optimal_buffer_size", bufPerformance);
76    std::transform(bufOpt.begin(), bufOpt.end(), bufOpt.begin(), ::tolower);
77    if (0 == bufOpt.compare(bufMemory)) isOptPerformance = false;
78    else if (0 != bufOpt.compare(bufPerformance))
79    {
80      ERROR("CXios::parseXiosConfig()", << "optimal_buffer_size must be memory or performance "<< endl );
81    }
82
[718]83    bufferSizeFactor = getin<double>("buffer_size_factor", defaultBufferSizeFactor);
[719]84    minBufferSize = getin<int>("min_buffer_size", 1024 * sizeof(double));
[1029]85    recvFieldTimeout = getin<double>("recv_field_timeout", 10.0);
86    if (recvFieldTimeout < 0.0)
87      ERROR("CXios::parseXiosConfig()", "recv_field_timeout cannot be negative.");
[718]88
[1134]89 
90    int num_ep;
91    if(isClient) 
92    { 
93      num_ep = omp_get_num_threads();
94    }
95   
96    if(isServer) 
97    { 
98      num_ep = omp_get_num_threads();
99    }
100   
101    MPI_Info info;
102    #pragma omp master
103    {
104      MPI_Comm *ep_comm;
105      MPI_Comm_create_endpoints(MPI_COMM_WORLD, num_ep, info, ep_comm);  // servers should reach here too.
106      passage = ep_comm; 
107    }
108   
109    #pragma omp barrier
110
111     
112    CXios::globalComm = passage[omp_get_thread_num()];
113
114    int tmp_rank;
115    MPI_Comm_rank(CXios::globalComm, &tmp_rank);
116
117   
118    test_omp_rank = tmp_rank;
119   
[300]120  }
121
[512]122  /*!
123  Initialize client
124  \param [in] codeId identity of context
125  \param [in] localComm local communicator
126  \param [in/out] returnComm communicator corresponding to group of client with same codeId
127  */
[300]128  void CXios::initClientSide(const string& codeId, MPI_Comm& localComm, MPI_Comm& returnComm)
129  {
[1134]130    isClient = true;
131   
[300]132    initialize() ;
[490]133
[1134]134    CClient::initialize(codeId,localComm,returnComm) ;
[491]135
[697]136    if (CClient::getRank()==0) globalRegistry = new CRegistry(returnComm) ;
[491]137
[956]138    // If there are no server processes then we are in attached mode
139    // and the clients are also servers
140    isServer = !usingServer;
[490]141
[523]142    if (printLogs2Files)
143    {
[1134]144      #pragma omp critical
[499]145      CClient::openInfoStream(clientFile);
[523]146      CClient::openErrorStream(clientFile);
147    }
[490]148    else
[523]149    {
[490]150      CClient::openInfoStream();
[523]151      CClient::openErrorStream();
152    }
[490]153  }
[300]154
155  void CXios::clientFinalize(void)
156  {
[490]157     CClient::finalize() ;
[697]158     if (CClient::getRank()==0)
159     {
[1134]160       #pragma omp critical (_output)
[697]161       info(80)<<"Write data base Registry"<<endl<<globalRegistry->toString()<<endl ;
162       globalRegistry->toFile("xios_registry.bin") ;
163       delete globalRegistry ;
164     }
[1160]165     CClient::closeInfoStream();
166 
167
[401]168#ifdef XIOS_MEMTRACK
[1156]169
170#ifdef XIOS_MEMTRACK_LIGHT
171       report(10) << " Memory report : current memory used by XIOS : "<<  MemTrack::getCurrentMemorySize()*1.0/(1024*1024)<<" Mbyte" << endl ;
172       report(10) << " Memory report : maximum memory used by XIOS : "<<  MemTrack::getMaxMemorySize()*1.0/(1024*1024)<<" Mbyte" << endl ;
173#endif
174
175#ifdef XIOS_MEMTRACK_FULL
[401]176     MemTrack::TrackListMemoryUsage() ;
[490]177     MemTrack::TrackDumpBlocks();
[401]178#endif
[490]179  }
180
[512]181  //! Init server by parsing only xios part of config file
[509]182  void CXios::initServer()
183  {
[1134]184    int initialized;
185    MPI_Initialized(&initialized);
186    if (initialized) CServer::is_MPI_Initialized=true ;
187    else CServer::is_MPI_Initialized=false ;
188     
189 
190    if(!CServer::is_MPI_Initialized)
191    {
192      MPI_Init(NULL, NULL);
193    }
194     
[509]195    set_new_handler(noMemory);
196    std::set<StdString> parseList;
197    parseList.insert("xios");
198    xml::CXMLParser::ParseFile(rootFile, parseList);
[511]199    parseXiosConfig();
[509]200  }
201
[512]202  //! Initialize server then put it into listening state
[300]203  void CXios::initServerSide(void)
204  {
[1134]205   
[956]206    isClient = false;
207    isServer = true;
[1134]208   
209    initServer();
210   
211   
[491]212    // Initialize all aspects MPI
[490]213    CServer::initialize();
[697]214    if (CServer::getRank()==0) globalRegistry = new CRegistry(CServer::intraComm) ;
215   
[523]216    if (printLogs2Files)
217    {
[499]218      CServer::openInfoStream(serverFile);
[523]219      CServer::openErrorStream(serverFile);
220    }
[490]221    else
[523]222    {
[490]223      CServer::openInfoStream();
[523]224      CServer::openErrorStream();
225    }
[490]226
[491]227    // Enter the loop to listen message from Client
[490]228    CServer::eventLoop();
229
[491]230    // Finalize
[697]231     if (CServer::getRank()==0)
232     {
233       info(80)<<"Write data base Registry"<<endl<<globalRegistry->toString()<<endl ;
234       globalRegistry->toFile("xios_registry.bin") ;
235       delete globalRegistry ;
236     }
[1134]237
[1157]238    CServer::finalize();
[1160]239       
[490]240    CServer::closeInfoStream();
241  }
242
[512]243  //! Parse configuration file
[346]244  void CXios::parseFile(const string& filename)
245  {
[490]246    xml::CXMLParser::ParseFile(filename);
[346]247  }
[491]248
[512]249  //! Set using server
[491]250  void CXios::setUsingServer()
251  {
252    usingServer = true;
253  }
254
[512]255  //! Unset using server
[491]256  void CXios::setNotUsingServer()
257  {
258    usingServer = false;
259  }
[300]260}
Note: See TracBrowser for help on using the repository browser.