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