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