[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" |
---|
[1761] | 13 | #include "ressources_manager.hpp" |
---|
| 14 | #include "services_manager.hpp" |
---|
| 15 | #include "servers_ressource.hpp" |
---|
[2212] | 16 | #include "mem_checker.hpp" |
---|
[300] | 17 | |
---|
[335] | 18 | namespace xios |
---|
[300] | 19 | { |
---|
| 20 | string CXios::rootFile="./iodef.xml" ; |
---|
| 21 | string CXios::xiosCodeId="xios.x" ; |
---|
[499] | 22 | string CXios::clientFile="./xios_client"; |
---|
| 23 | string CXios::serverFile="./xios_server"; |
---|
[1021] | 24 | string CXios::serverPrmFile="./xios_server1"; |
---|
| 25 | string CXios::serverSndFile="./xios_server2"; |
---|
[1761] | 26 | const string CXios::defaultPoolId="default_pool_id" ; |
---|
| 27 | const string CXios::defaultServerId="default_server_id" ; |
---|
[2407] | 28 | const string CXios::defaultWriterId="default_writer_id" ; |
---|
| 29 | const string CXios::defaultReaderId="default_reader_id" ; |
---|
[1761] | 30 | const string CXios::defaultGathererId="default_gatherer_id" ; |
---|
[2335] | 31 | const string CXios::defaultServicesId="default_services_id" ; |
---|
[1761] | 32 | |
---|
[1622] | 33 | bool CXios::xiosStack = true; |
---|
| 34 | bool CXios::systemStack = false; |
---|
| 35 | |
---|
[300] | 36 | bool CXios::isClient ; |
---|
| 37 | bool CXios::isServer ; |
---|
[1761] | 38 | |
---|
[1639] | 39 | MPI_Comm CXios::globalComm ; |
---|
[1761] | 40 | MPI_Comm CXios::xiosComm ; |
---|
| 41 | |
---|
[300] | 42 | bool CXios::usingOasis ; |
---|
[491] | 43 | bool CXios::usingServer = false; |
---|
[1021] | 44 | bool CXios::usingServer2 = false; |
---|
| 45 | int CXios::ratioServer2 = 50; |
---|
[1243] | 46 | int CXios::nbPoolsServer2 = 1; |
---|
[718] | 47 | double CXios::bufferSizeFactor = 1.0; |
---|
| 48 | const double CXios::defaultBufferSizeFactor = 1.0; |
---|
[2176] | 49 | StdSize CXios::minBufferSize = 64 * sizeof(double); |
---|
[1227] | 50 | StdSize CXios::maxBufferSize = std::numeric_limits<int>::max() ; |
---|
[523] | 51 | bool CXios::printLogs2Files; |
---|
[511] | 52 | bool CXios::isOptPerformance = true; |
---|
[697] | 53 | CRegistry* CXios::globalRegistry = 0; |
---|
[1375] | 54 | double CXios::recvFieldTimeout = 300.0; |
---|
[1377] | 55 | bool CXios::checkEventSync=false ; |
---|
[2329] | 56 | bool CXios::checkSumRecv=false ; |
---|
| 57 | bool CXios::checkSumSend=false ; |
---|
[2420] | 58 | bool CXios::logMemory=false ; |
---|
[1761] | 59 | |
---|
| 60 | CDaemonsManager* CXios::daemonsManager_=nullptr ; |
---|
| 61 | CRessourcesManager* CXios::ressourcesManager_=nullptr ; |
---|
| 62 | CServicesManager* CXios::servicesManager_=nullptr ; |
---|
| 63 | CContextsManager* CXios::contextsManager_=nullptr ; |
---|
[1878] | 64 | CCouplerManager* CXios::couplerManager_=nullptr ; |
---|
[2209] | 65 | CRegistryManager* CXios::registryManager_=nullptr ; |
---|
[1761] | 66 | |
---|
[2310] | 67 | CMpiGarbageCollector CXios::MpiGarbageCollector_ ; |
---|
| 68 | |
---|
[512] | 69 | //! Parse configuration file and create some objects from it |
---|
[300] | 70 | void CXios::initialize() |
---|
| 71 | { |
---|
[400] | 72 | set_new_handler(noMemory); |
---|
[346] | 73 | parseFile(rootFile); |
---|
[511] | 74 | parseXiosConfig(); |
---|
| 75 | } |
---|
| 76 | |
---|
[512] | 77 | /*! |
---|
| 78 | \brief Parse xios part of configuration file (.iodef.xml) |
---|
| 79 | Both client and server need information returned from this function |
---|
| 80 | */ |
---|
[511] | 81 | void CXios::parseXiosConfig() |
---|
| 82 | { |
---|
[311] | 83 | usingOasis=getin<bool>("using_oasis",false) ; |
---|
[506] | 84 | usingServer=getin<bool>("using_server",false) ; |
---|
[1021] | 85 | usingServer2=getin<bool>("using_server2",false) ; |
---|
| 86 | ratioServer2=getin<int>("ratio_server2",50); |
---|
[1519] | 87 | nbPoolsServer2=getin<int>("number_pools_server2",0); |
---|
[311] | 88 | info.setLevel(getin<int>("info_level",0)) ; |
---|
[512] | 89 | report.setLevel(getin<int>("info_level",50)); |
---|
[523] | 90 | printLogs2Files=getin<bool>("print_file",false); |
---|
[512] | 91 | |
---|
[1622] | 92 | xiosStack=getin<bool>("xios_stack",true) ; |
---|
| 93 | systemStack=getin<bool>("system_stack",false) ; |
---|
| 94 | if (xiosStack && systemStack) |
---|
| 95 | { |
---|
| 96 | xiosStack = false; |
---|
| 97 | } |
---|
| 98 | |
---|
[511] | 99 | StdString bufMemory("memory"); |
---|
| 100 | StdString bufPerformance("performance"); |
---|
| 101 | StdString bufOpt = getin<StdString>("optimal_buffer_size", bufPerformance); |
---|
| 102 | std::transform(bufOpt.begin(), bufOpt.end(), bufOpt.begin(), ::tolower); |
---|
| 103 | if (0 == bufOpt.compare(bufMemory)) isOptPerformance = false; |
---|
| 104 | else if (0 != bufOpt.compare(bufPerformance)) |
---|
| 105 | { |
---|
| 106 | ERROR("CXios::parseXiosConfig()", << "optimal_buffer_size must be memory or performance "<< endl ); |
---|
| 107 | } |
---|
| 108 | |
---|
[718] | 109 | bufferSizeFactor = getin<double>("buffer_size_factor", defaultBufferSizeFactor); |
---|
[719] | 110 | minBufferSize = getin<int>("min_buffer_size", 1024 * sizeof(double)); |
---|
[1227] | 111 | maxBufferSize = getin<int>("max_buffer_size", std::numeric_limits<int>::max()); |
---|
[1376] | 112 | recvFieldTimeout = getin<double>("recv_field_timeout", recvFieldTimeout); |
---|
[1158] | 113 | if (recvFieldTimeout < 0.0) |
---|
| 114 | ERROR("CXios::parseXiosConfig()", "recv_field_timeout cannot be negative."); |
---|
[718] | 115 | |
---|
[1377] | 116 | checkEventSync = getin<bool>("check_event_sync", checkEventSync); |
---|
[2329] | 117 | |
---|
| 118 | checkSumSend = getin<bool>("checksum_send_fields", false); |
---|
| 119 | checkSumRecv = getin<bool>("checksum_recv_fields", false); |
---|
[2420] | 120 | |
---|
| 121 | logMemory = getin<bool>("log_memory", false); |
---|
[1639] | 122 | |
---|
[300] | 123 | globalComm=MPI_COMM_WORLD ; |
---|
| 124 | } |
---|
| 125 | |
---|
[512] | 126 | /*! |
---|
| 127 | Initialize client |
---|
| 128 | \param [in] codeId identity of context |
---|
| 129 | \param [in] localComm local communicator |
---|
| 130 | \param [in/out] returnComm communicator corresponding to group of client with same codeId |
---|
| 131 | */ |
---|
[1639] | 132 | void CXios::initClientSide(const string& codeId, MPI_Comm& localComm, MPI_Comm& returnComm) |
---|
[1622] | 133 | TRY |
---|
[300] | 134 | { |
---|
| 135 | initialize() ; |
---|
[490] | 136 | |
---|
[1639] | 137 | isClient = true; |
---|
[491] | 138 | |
---|
[1761] | 139 | //CClient::initialize(codeId,localComm,returnComm) ; |
---|
[491] | 140 | CClient::initialize(codeId,localComm,returnComm) ; |
---|
[1761] | 141 | |
---|
[956] | 142 | // If there are no server processes then we are in attached mode |
---|
| 143 | // and the clients are also servers |
---|
| 144 | isServer = !usingServer; |
---|
[490] | 145 | |
---|
[523] | 146 | if (printLogs2Files) |
---|
| 147 | { |
---|
[499] | 148 | CClient::openInfoStream(clientFile); |
---|
[523] | 149 | CClient::openErrorStream(clientFile); |
---|
| 150 | } |
---|
[490] | 151 | else |
---|
[523] | 152 | { |
---|
[490] | 153 | CClient::openInfoStream(); |
---|
[523] | 154 | CClient::openErrorStream(); |
---|
| 155 | } |
---|
[2418] | 156 | CMemChecker::logMem("CXios::initClientSide"); |
---|
[490] | 157 | } |
---|
[1622] | 158 | CATCH |
---|
[300] | 159 | |
---|
| 160 | void CXios::clientFinalize(void) |
---|
| 161 | { |
---|
[2420] | 162 | CMemChecker::logMem("CXios::clientFinalize", true); |
---|
[2418] | 163 | |
---|
[490] | 164 | CClient::finalize() ; |
---|
[1761] | 165 | |
---|
[401] | 166 | #ifdef XIOS_MEMTRACK |
---|
[1158] | 167 | |
---|
| 168 | #ifdef XIOS_MEMTRACK_LIGHT |
---|
| 169 | report(10) << " Memory report : current memory used by XIOS : "<< MemTrack::getCurrentMemorySize()*1.0/(1024*1024)<<" Mbyte" << endl ; |
---|
| 170 | report(10) << " Memory report : maximum memory used by XIOS : "<< MemTrack::getMaxMemorySize()*1.0/(1024*1024)<<" Mbyte" << endl ; |
---|
| 171 | #endif |
---|
| 172 | |
---|
| 173 | #ifdef XIOS_MEMTRACK_FULL |
---|
[2212] | 174 | report(0) << " Memory report : current memory used by XIOS : "<< MemTrack::getCurrentMemorySize()*1.0/(1024*1024)<<" Mbyte" << endl ; |
---|
| 175 | report(0) << " Memory report : maximum memory used by XIOS : "<< MemTrack::getMaxMemorySize()*1.0/(1024*1024)<<" Mbyte" << endl ; |
---|
| 176 | |
---|
| 177 | ofstream memReport ; |
---|
| 178 | std::filebuf* fb = memReport.rdbuf(); |
---|
| 179 | CClient::openStream(clientFile, ".mem", fb); |
---|
| 180 | |
---|
| 181 | MemTrack::TrackListMemoryUsage() ; |
---|
| 182 | size_t memtrack_blocks=0 ; |
---|
| 183 | memtrack_blocks=xios::CXios::getin("memtrack_blocks",memtrack_blocks) ; |
---|
| 184 | size_t memtrack_size=0 ; |
---|
| 185 | memtrack_size=xios::CXios::getin("memtrack_size",memtrack_size) ; |
---|
| 186 | MemTrack::TrackDumpBlocks(memReport, memtrack_blocks,memtrack_size); |
---|
| 187 | memReport.close(); |
---|
[401] | 188 | #endif |
---|
[1158] | 189 | |
---|
| 190 | CClient::closeInfoStream(); |
---|
| 191 | |
---|
| 192 | #endif |
---|
[490] | 193 | } |
---|
| 194 | |
---|
[512] | 195 | //! Init server by parsing only xios part of config file |
---|
[509] | 196 | void CXios::initServer() |
---|
| 197 | { |
---|
| 198 | set_new_handler(noMemory); |
---|
| 199 | std::set<StdString> parseList; |
---|
| 200 | parseList.insert("xios"); |
---|
| 201 | xml::CXMLParser::ParseFile(rootFile, parseList); |
---|
[511] | 202 | parseXiosConfig(); |
---|
[509] | 203 | } |
---|
| 204 | |
---|
[512] | 205 | //! Initialize server then put it into listening state |
---|
[1054] | 206 | void CXios::initServerSide(void) |
---|
[300] | 207 | { |
---|
[2212] | 208 | CMemChecker::get("xios").resume() ; |
---|
[1639] | 209 | initServer(); |
---|
[1638] | 210 | isClient = false; |
---|
| 211 | isServer = true; |
---|
| 212 | |
---|
[1021] | 213 | // Initialize all aspects MPI |
---|
| 214 | CServer::initialize(); |
---|
[490] | 215 | CServer::finalize(); |
---|
[1158] | 216 | |
---|
| 217 | #ifdef XIOS_MEMTRACK |
---|
| 218 | |
---|
| 219 | #ifdef XIOS_MEMTRACK_LIGHT |
---|
| 220 | report(10) << " Memory report : current memory used by XIOS : "<< MemTrack::getCurrentMemorySize()*1.0/(1024*1024)<<" Mbyte" << endl ; |
---|
| 221 | report(10) << " Memory report : maximum memory used by XIOS : "<< MemTrack::getMaxMemorySize()*1.0/(1024*1024)<<" Mbyte" << endl ; |
---|
| 222 | #endif |
---|
| 223 | |
---|
| 224 | #ifdef XIOS_MEMTRACK_FULL |
---|
[2212] | 225 | report(0) << " Memory report : current memory used by XIOS : "<< MemTrack::getCurrentMemorySize()*1.0/(1024*1024)<<" Mbyte" << endl ; |
---|
| 226 | report(0) << " Memory report : maximum memory used by XIOS : "<< MemTrack::getMaxMemorySize()*1.0/(1024*1024)<<" Mbyte" << endl ; |
---|
| 227 | ofstream memReport ; |
---|
| 228 | std::filebuf* fb = memReport.rdbuf(); |
---|
| 229 | CClient::openStream(serverFile, ".mem", fb); |
---|
| 230 | |
---|
| 231 | MemTrack::TrackListMemoryUsage() ; |
---|
| 232 | size_t memtrack_blocks=0 ; |
---|
| 233 | memtrack_blocks=xios::CXios::getin("memtrack_blocks",memtrack_blocks) ; |
---|
| 234 | size_t memtrack_size=0 ; |
---|
| 235 | memtrack_size=xios::CXios::getin("memtrack_size",memtrack_size) ; |
---|
| 236 | MemTrack::TrackDumpBlocks(memReport,memtrack_blocks,memtrack_size); |
---|
| 237 | memReport.close() ; |
---|
[1158] | 238 | #endif |
---|
| 239 | #endif |
---|
[2212] | 240 | CMemChecker::get("xios").suspend() ; |
---|
[490] | 241 | CServer::closeInfoStream(); |
---|
| 242 | } |
---|
| 243 | |
---|
[512] | 244 | //! Parse configuration file |
---|
[346] | 245 | void CXios::parseFile(const string& filename) |
---|
| 246 | { |
---|
[490] | 247 | xml::CXMLParser::ParseFile(filename); |
---|
[346] | 248 | } |
---|
[491] | 249 | |
---|
[512] | 250 | //! Set using server |
---|
[491] | 251 | void CXios::setUsingServer() |
---|
| 252 | { |
---|
| 253 | usingServer = true; |
---|
| 254 | } |
---|
| 255 | |
---|
[512] | 256 | //! Unset using server |
---|
[491] | 257 | void CXios::setNotUsingServer() |
---|
| 258 | { |
---|
| 259 | usingServer = false; |
---|
| 260 | } |
---|
[1761] | 261 | |
---|
[2209] | 262 | void CXios::launchRegistryManager(bool isXiosServer) |
---|
| 263 | { |
---|
| 264 | registryManager_ = new CRegistryManager(isXiosServer) ; |
---|
| 265 | } |
---|
| 266 | |
---|
[1761] | 267 | void CXios::launchRessourcesManager(bool isXiosServer) |
---|
| 268 | { |
---|
| 269 | ressourcesManager_ = new CRessourcesManager(isXiosServer) ; |
---|
| 270 | } |
---|
| 271 | |
---|
[1878] | 272 | void CXios::launchCouplerManager(bool isXiosServer) |
---|
| 273 | { |
---|
| 274 | couplerManager_ = new CCouplerManager(isXiosServer) ; |
---|
| 275 | } |
---|
| 276 | |
---|
[1761] | 277 | void CXios::launchServicesManager(bool isXiosServer) |
---|
| 278 | { |
---|
| 279 | servicesManager_ = new CServicesManager(isXiosServer) ; |
---|
| 280 | } |
---|
| 281 | |
---|
| 282 | void CXios::launchContextsManager(bool isXiosServer) |
---|
| 283 | { |
---|
| 284 | contextsManager_ = new CContextsManager(isXiosServer) ; |
---|
| 285 | } |
---|
| 286 | |
---|
| 287 | void CXios::launchDaemonsManager(bool isXiosServer) |
---|
| 288 | { |
---|
| 289 | daemonsManager_ = new CDaemonsManager(isXiosServer) ; |
---|
| 290 | } |
---|
| 291 | |
---|
[1764] | 292 | |
---|
[2209] | 293 | void CXios::finalizeRegistryManager() |
---|
| 294 | { |
---|
| 295 | delete registryManager_; |
---|
| 296 | } |
---|
| 297 | |
---|
[1764] | 298 | void CXios::finalizeRessourcesManager() |
---|
| 299 | { |
---|
| 300 | delete ressourcesManager_; |
---|
| 301 | } |
---|
| 302 | |
---|
[1878] | 303 | void CXios::finalizeCouplerManager() |
---|
| 304 | { |
---|
| 305 | delete couplerManager_; |
---|
| 306 | } |
---|
| 307 | |
---|
[1764] | 308 | void CXios::finalizeServicesManager() |
---|
| 309 | { |
---|
| 310 | delete servicesManager_ ; |
---|
| 311 | } |
---|
| 312 | |
---|
| 313 | void CXios::finalizeContextsManager() |
---|
| 314 | { |
---|
| 315 | delete contextsManager_ ; |
---|
| 316 | } |
---|
| 317 | |
---|
| 318 | void CXios::finalizeDaemonsManager() |
---|
| 319 | { |
---|
| 320 | delete daemonsManager_ ; |
---|
| 321 | } |
---|
| 322 | |
---|
[1761] | 323 | CPoolRessource* CXios::getPoolRessource(void) |
---|
| 324 | { |
---|
| 325 | if (isClient) return CClient::getPoolRessource() ; |
---|
| 326 | else if (isServer) return CServer::getServersRessource()->getPoolRessource() ; |
---|
[2282] | 327 | |
---|
| 328 | MISSING_RETURN( "CPoolRessource* CXios::getPoolRessource()" ); |
---|
| 329 | return nullptr; |
---|
[1761] | 330 | } |
---|
[300] | 331 | } |
---|
[1761] | 332 | |
---|