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