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