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

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

branch merged with trunk r1130

  • 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.0 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     }
[698]165     CClient::closeInfoStream();
166 
[490]167
[401]168#ifdef XIOS_MEMTRACK
169     MemTrack::TrackListMemoryUsage() ;
[490]170     MemTrack::TrackDumpBlocks();
[401]171#endif
[490]172  }
173
[512]174  //! Init server by parsing only xios part of config file
[509]175  void CXios::initServer()
176  {
[1134]177    int initialized;
178    MPI_Initialized(&initialized);
179    if (initialized) CServer::is_MPI_Initialized=true ;
180    else CServer::is_MPI_Initialized=false ;
181     
182 
183    if(!CServer::is_MPI_Initialized)
184    {
185      MPI_Init(NULL, NULL);
186    }
187     
[509]188    set_new_handler(noMemory);
189    std::set<StdString> parseList;
190    parseList.insert("xios");
191    xml::CXMLParser::ParseFile(rootFile, parseList);
[511]192    parseXiosConfig();
[509]193  }
194
[512]195  //! Initialize server then put it into listening state
[300]196  void CXios::initServerSide(void)
197  {
[1134]198   
[956]199    isClient = false;
200    isServer = true;
[1134]201   
202    initServer();
203   
204   
[491]205    // Initialize all aspects MPI
[490]206    CServer::initialize();
[697]207    if (CServer::getRank()==0) globalRegistry = new CRegistry(CServer::intraComm) ;
208   
[523]209    if (printLogs2Files)
210    {
[499]211      CServer::openInfoStream(serverFile);
[523]212      CServer::openErrorStream(serverFile);
213    }
[490]214    else
[523]215    {
[490]216      CServer::openInfoStream();
[523]217      CServer::openErrorStream();
218    }
[490]219
[491]220    // Enter the loop to listen message from Client
[490]221    CServer::eventLoop();
222
[491]223    // Finalize
[697]224     if (CServer::getRank()==0)
225     {
226       info(80)<<"Write data base Registry"<<endl<<globalRegistry->toString()<<endl ;
227       globalRegistry->toFile("xios_registry.bin") ;
228       delete globalRegistry ;
229     }
[1134]230
[490]231    CServer::finalize();
[1134]232       
[490]233    CServer::closeInfoStream();
234  }
235
[512]236  //! Parse configuration file
[346]237  void CXios::parseFile(const string& filename)
238  {
[490]239    xml::CXMLParser::ParseFile(filename);
[346]240  }
[491]241
[512]242  //! Set using server
[491]243  void CXios::setUsingServer()
244  {
245    usingServer = true;
246  }
247
[512]248  //! Unset using server
[491]249  void CXios::setNotUsingServer()
250  {
251    usingServer = false;
252  }
[300]253}
Note: See TracBrowser for help on using the repository browser.