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

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

backup modification

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