source: XIOS/trunk/src/cxios.cpp @ 2330

Last change on this file since 2330 was 2330, checked in by jderouillat, 23 months ago

Added dedicated options to manage send/recv checksum operations, this new xios parameters are respectively called checksum_send_fields/checksum_recv_fields (set to false by default)

  • 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: 9.7 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
14#include "graphviz.hpp"
15
16namespace xios
17{
18  string CXios::rootFile="./iodef.xml" ;
19  string CXios::xiosCodeId="xios.x" ;
20  string CXios::clientFile="./xios_client";
21  string CXios::serverFile="./xios_server";
22  string CXios::serverPrmFile="./xios_server1";
23  string CXios::serverSndFile="./xios_server2";
24
25  bool CXios::xiosStack = true;
26  bool CXios::systemStack = false;
27
28  bool CXios::isClient ;
29  bool CXios::isServer ;
30  MPI_Comm CXios::globalComm ;
31  bool CXios::usingOasis ;
32  bool CXios::usingServer = false;
33  bool CXios::usingServer2 = false;
34  int CXios::ratioServer2 = 50;
35  int CXios::nbPoolsServer2 = 1;
36  double CXios::bufferSizeFactor = 1.0;
37  const double CXios::defaultBufferSizeFactor = 1.0;
38  StdSize CXios::minBufferSize = 1024 * sizeof(double);
39  StdSize CXios::maxBufferSize = std::numeric_limits<int>::max() ;
40  bool CXios::printLogs2Files;
41  bool CXios::isOptPerformance = true;
42  CRegistry* CXios::globalRegistry = 0;
43  double CXios::recvFieldTimeout = 300.0;
44  bool CXios::checkEventSync=false ;
45  bool CXios::checkSumRecv=false ;
46  bool CXios::checkSumSend=false ;
47 
48  //! Parse configuration file and create some objects from it
49  void CXios::initialize()
50  {
51    set_new_handler(noMemory);
52    parseFile(rootFile);
53    parseXiosConfig();
54  }
55
56  /*!
57  \brief Parse xios part of configuration file (.iodef.xml)
58   Both client and server need information returned from this function
59  */
60  void CXios::parseXiosConfig()
61  {
62    usingOasis=getin<bool>("using_oasis",false) ;
63    usingServer=getin<bool>("using_server",false) ;
64    usingServer2=getin<bool>("using_server2",false) ;
65    ratioServer2=getin<int>("ratio_server2",50);
66    nbPoolsServer2=getin<int>("number_pools_server2",0);
67    info.setLevel(getin<int>("info_level",0)) ;
68    report.setLevel(getin<int>("info_level",50));
69    printLogs2Files=getin<bool>("print_file",false);
70
71    xiosStack=getin<bool>("xios_stack",true) ;
72    systemStack=getin<bool>("system_stack",false) ;
73    if (xiosStack && systemStack)
74    {
75      xiosStack = false;
76    }
77
78    StdString bufMemory("memory");
79    StdString bufPerformance("performance");
80    StdString bufOpt = getin<StdString>("optimal_buffer_size", bufPerformance);
81    std::transform(bufOpt.begin(), bufOpt.end(), bufOpt.begin(), ::tolower);
82    if (0 == bufOpt.compare(bufMemory)) isOptPerformance = false;
83    else if (0 != bufOpt.compare(bufPerformance))
84    {
85      ERROR("CXios::parseXiosConfig()", << "optimal_buffer_size must be memory or performance "<< endl );
86    }
87
88    bufferSizeFactor = getin<double>("buffer_size_factor", defaultBufferSizeFactor);
89    minBufferSize = getin<int>("min_buffer_size", 1024 * sizeof(double));
90    maxBufferSize = getin<int>("max_buffer_size", std::numeric_limits<int>::max());
91    recvFieldTimeout = getin<double>("recv_field_timeout", recvFieldTimeout);
92    if (recvFieldTimeout < 0.0)
93      ERROR("CXios::parseXiosConfig()", "recv_field_timeout cannot be negative.");
94
95    checkEventSync = getin<bool>("check_event_sync", checkEventSync);
96
97    checkSumSend = getin<bool>("checksum_send_fields", false);
98    checkSumRecv = getin<bool>("checksum_recv_fields", false);
99 
100    globalComm=MPI_COMM_WORLD ;
101  }
102
103  /*!
104  Initialize client
105  \param [in] codeId identity of context
106  \param [in] localComm local communicator
107  \param [in/out] returnComm communicator corresponding to group of client with same codeId
108  */
109  void CXios::initClientSide(const string& codeId, MPI_Comm& localComm, MPI_Comm& returnComm)
110  TRY
111  {
112    initialize() ;
113
114    isClient = true;
115
116    CClient::initialize(codeId,localComm,returnComm) ;
117    if (CClient::getRank()==0) globalRegistry = new CRegistry(returnComm) ;
118
119    // If there are no server processes then we are in attached mode
120    // and the clients are also servers
121    isServer = !usingServer;
122
123    if (printLogs2Files)
124    {
125      CClient::openInfoStream(clientFile);
126      CClient::openErrorStream(clientFile);
127    }
128    else
129    {
130      CClient::openInfoStream();
131      CClient::openErrorStream();
132    }
133  }
134  CATCH
135
136  void CXios::clientFinalize(void)
137  {
138     CClient::finalize() ;
139     if (CClient::getRank()==0)
140     {
141       info(80)<<"Write data base Registry"<<endl<<globalRegistry->toString()<<endl ;
142       globalRegistry->toFile("xios_registry.bin") ;
143       delete globalRegistry ;
144       CGraphviz::buildWorkflowGraphVisjs_with_info();
145     }
146
147#ifdef XIOS_MEMTRACK
148
149#ifdef XIOS_MEMTRACK_LIGHT
150       report(10) << " Memory report : current memory used by XIOS : "<<  MemTrack::getCurrentMemorySize()*1.0/(1024*1024)<<" Mbyte" << endl ;
151       report(10) << " Memory report : maximum memory used by XIOS : "<<  MemTrack::getMaxMemorySize()*1.0/(1024*1024)<<" Mbyte" << endl ;
152#endif
153
154#ifdef XIOS_MEMTRACK_FULL
155     MemTrack::TrackListMemoryUsage() ;
156     MemTrack::TrackDumpBlocks();
157#endif
158
159     CClient::closeInfoStream();
160
161#endif
162  }
163
164  //! Init server by parsing only xios part of config file
165  void CXios::initServer()
166  {
167    set_new_handler(noMemory);
168    std::set<StdString> parseList;
169    parseList.insert("xios");
170    xml::CXMLParser::ParseFile(rootFile, parseList);
171    parseXiosConfig();
172  }
173
174  //! Initialize server then put it into listening state
175  void CXios::initServerSide(void)
176  {
177    initServer();
178    isClient = false;
179    isServer = true;
180
181    // Initialize all aspects MPI
182    CServer::initialize();
183    if (CServer::getRank()==0 && CServer::serverLevel != 1) globalRegistry = new CRegistry(CServer::intraComm) ;
184   
185    if (printLogs2Files)
186    {
187      if (CServer::serverLevel == 0)
188      {
189        CServer::openInfoStream(serverFile);
190        CServer::openErrorStream(serverFile);
191      }
192      else if (CServer::serverLevel == 1)
193      {
194        CServer::openInfoStream(serverPrmFile);
195        CServer::openErrorStream(serverPrmFile);
196      }
197      else
198      {
199        CServer::openInfoStream(serverSndFile);
200        CServer::openErrorStream(serverSndFile);
201      }
202    }
203    else
204    {
205      CServer::openInfoStream();
206      CServer::openErrorStream();
207    }
208
209    // Enter the loop to listen message from Client
210    CServer::eventLoop();
211
212    // Finalize
213    if (CServer::serverLevel == 0)
214    {
215      if (CServer::getRank()==0)
216      {
217        info(80)<<"Write data base Registry"<<endl<<globalRegistry->toString()<<endl ;
218        globalRegistry->toFile("xios_registry.bin") ;
219        delete globalRegistry ;
220      }
221    }
222    else
223    {
224      // If using two server levels:
225      // (1) merge registries on each pool
226      // (2) send merged registries to the first pool
227      // (3) merge received registries on the first pool
228      if (CServer::serverLevel == 2)
229      {
230        vector<int>& secondaryServerGlobalRanks = CServer::getSecondaryServerGlobalRanks();
231        int firstPoolGlobalRank = secondaryServerGlobalRanks[0];
232        int rankGlobal;
233        MPI_Comm_rank(globalComm, &rankGlobal);
234
235        // Merge registries defined on each pools
236        CRegistry globalRegistrySndServers (CServer::intraComm);
237
238        // All pools (except the first): send globalRegistry to the first pool
239        for (int i=1; i<secondaryServerGlobalRanks.size(); i++)
240        {
241          if (rankGlobal == secondaryServerGlobalRanks[i])
242          {
243            globalRegistrySndServers.mergeRegistry(*globalRegistry) ;
244            int registrySize = globalRegistrySndServers.size();
245            MPI_Send(&registrySize,1,MPI_LONG,firstPoolGlobalRank,15,CXios::globalComm) ;
246            CBufferOut buffer(registrySize) ;
247            globalRegistrySndServers.toBuffer(buffer) ;
248            MPI_Send(buffer.start(),registrySize,MPI_CHAR,firstPoolGlobalRank,15,CXios::globalComm) ;
249          }
250        }
251
252        // First pool: receive globalRegistry of all secondary server pools, merge and write the resultant registry
253        if (rankGlobal == firstPoolGlobalRank)
254        {
255          MPI_Status status;
256          char* recvBuff;
257
258          globalRegistrySndServers.mergeRegistry(*globalRegistry) ;
259
260          for (int i=1; i< secondaryServerGlobalRanks.size(); i++)
261          {
262            int rank = secondaryServerGlobalRanks[i];
263            int registrySize = 0;
264            MPI_Recv(&registrySize, 1, MPI_LONG, rank, 15, CXios::globalComm, &status);
265            recvBuff = new char[registrySize];
266            MPI_Recv(recvBuff, registrySize, MPI_CHAR, rank, 15, CXios::globalComm, &status);
267            CBufferIn buffer(recvBuff, registrySize) ;
268            CRegistry recvRegistry;
269            recvRegistry.fromBuffer(buffer) ;
270            globalRegistrySndServers.mergeRegistry(recvRegistry) ;
271            delete[] recvBuff;
272          }
273
274          info(80)<<"Write data base Registry"<<endl<<globalRegistrySndServers.toString()<<endl ;
275          globalRegistrySndServers.toFile("xios_registry.bin") ;
276
277        }
278      }
279      delete globalRegistry;
280    }
281    CServer::finalize();
282
283#ifdef XIOS_MEMTRACK
284
285#ifdef XIOS_MEMTRACK_LIGHT
286       report(10) << " Memory report : current memory used by XIOS : "<<  MemTrack::getCurrentMemorySize()*1.0/(1024*1024)<<" Mbyte" << endl ;
287       report(10) << " Memory report : maximum memory used by XIOS : "<<  MemTrack::getMaxMemorySize()*1.0/(1024*1024)<<" Mbyte" << endl ;
288#endif
289
290#ifdef XIOS_MEMTRACK_FULL
291     MemTrack::TrackListMemoryUsage() ;
292     MemTrack::TrackDumpBlocks();
293#endif
294#endif
295    CServer::closeInfoStream();
296  }
297
298  //! Parse configuration file
299  void CXios::parseFile(const string& filename)
300  {
301    xml::CXMLParser::ParseFile(filename);
302  }
303
304  //! Set using server
305  void CXios::setUsingServer()
306  {
307    usingServer = true;
308  }
309
310  //! Unset using server
311  void CXios::setNotUsingServer()
312  {
313    usingServer = false;
314  }
315}
Note: See TracBrowser for help on using the repository browser.