[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" |
---|
[300] | 13 | |
---|
[335] | 14 | namespace xios |
---|
[300] | 15 | { |
---|
| 16 | string CXios::rootFile="./iodef.xml" ; |
---|
| 17 | string CXios::xiosCodeId="xios.x" ; |
---|
[499] | 18 | string CXios::clientFile="./xios_client"; |
---|
| 19 | string CXios::serverFile="./xios_server"; |
---|
[1021] | 20 | string CXios::serverPrmFile="./xios_server1"; |
---|
| 21 | string CXios::serverSndFile="./xios_server2"; |
---|
[490] | 22 | |
---|
[300] | 23 | bool CXios::isClient ; |
---|
| 24 | bool CXios::isServer ; |
---|
| 25 | MPI_Comm CXios::globalComm ; |
---|
| 26 | bool CXios::usingOasis ; |
---|
[491] | 27 | bool CXios::usingServer = false; |
---|
[1021] | 28 | bool CXios::usingServer2 = false; |
---|
| 29 | int CXios::ratioServer2 = 50; |
---|
[718] | 30 | double CXios::bufferSizeFactor = 1.0; |
---|
| 31 | const double CXios::defaultBufferSizeFactor = 1.0; |
---|
[719] | 32 | StdSize CXios::minBufferSize = 1024 * sizeof(double); |
---|
[523] | 33 | bool CXios::printLogs2Files; |
---|
[511] | 34 | bool CXios::isOptPerformance = true; |
---|
[697] | 35 | CRegistry* CXios::globalRegistry = 0; |
---|
[1158] | 36 | double CXios::recvFieldTimeout = 10.0; |
---|
[490] | 37 | |
---|
[512] | 38 | //! Parse configuration file and create some objects from it |
---|
[300] | 39 | void CXios::initialize() |
---|
| 40 | { |
---|
[400] | 41 | set_new_handler(noMemory); |
---|
[346] | 42 | parseFile(rootFile); |
---|
[511] | 43 | parseXiosConfig(); |
---|
| 44 | } |
---|
| 45 | |
---|
[512] | 46 | /*! |
---|
| 47 | \brief Parse xios part of configuration file (.iodef.xml) |
---|
| 48 | Both client and server need information returned from this function |
---|
| 49 | */ |
---|
[511] | 50 | void CXios::parseXiosConfig() |
---|
| 51 | { |
---|
[311] | 52 | usingOasis=getin<bool>("using_oasis",false) ; |
---|
[506] | 53 | usingServer=getin<bool>("using_server",false) ; |
---|
[1021] | 54 | usingServer2=getin<bool>("using_server2",false) ; |
---|
| 55 | ratioServer2=getin<int>("ratio_server2",50); |
---|
[311] | 56 | info.setLevel(getin<int>("info_level",0)) ; |
---|
[512] | 57 | report.setLevel(getin<int>("info_level",50)); |
---|
[523] | 58 | printLogs2Files=getin<bool>("print_file",false); |
---|
[512] | 59 | |
---|
[511] | 60 | StdString bufMemory("memory"); |
---|
| 61 | StdString bufPerformance("performance"); |
---|
| 62 | StdString bufOpt = getin<StdString>("optimal_buffer_size", bufPerformance); |
---|
| 63 | std::transform(bufOpt.begin(), bufOpt.end(), bufOpt.begin(), ::tolower); |
---|
| 64 | if (0 == bufOpt.compare(bufMemory)) isOptPerformance = false; |
---|
| 65 | else if (0 != bufOpt.compare(bufPerformance)) |
---|
| 66 | { |
---|
| 67 | ERROR("CXios::parseXiosConfig()", << "optimal_buffer_size must be memory or performance "<< endl ); |
---|
| 68 | } |
---|
| 69 | |
---|
[718] | 70 | bufferSizeFactor = getin<double>("buffer_size_factor", defaultBufferSizeFactor); |
---|
[719] | 71 | minBufferSize = getin<int>("min_buffer_size", 1024 * sizeof(double)); |
---|
[1158] | 72 | recvFieldTimeout = getin<double>("recv_field_timeout", 10.0); |
---|
| 73 | if (recvFieldTimeout < 0.0) |
---|
| 74 | ERROR("CXios::parseXiosConfig()", "recv_field_timeout cannot be negative."); |
---|
[718] | 75 | |
---|
[300] | 76 | globalComm=MPI_COMM_WORLD ; |
---|
| 77 | } |
---|
| 78 | |
---|
[512] | 79 | /*! |
---|
| 80 | Initialize client |
---|
| 81 | \param [in] codeId identity of context |
---|
| 82 | \param [in] localComm local communicator |
---|
| 83 | \param [in/out] returnComm communicator corresponding to group of client with same codeId |
---|
| 84 | */ |
---|
[300] | 85 | void CXios::initClientSide(const string& codeId, MPI_Comm& localComm, MPI_Comm& returnComm) |
---|
| 86 | { |
---|
| 87 | initialize() ; |
---|
[490] | 88 | |
---|
[956] | 89 | isClient = true; |
---|
[491] | 90 | |
---|
| 91 | CClient::initialize(codeId,localComm,returnComm) ; |
---|
[697] | 92 | if (CClient::getRank()==0) globalRegistry = new CRegistry(returnComm) ; |
---|
[491] | 93 | |
---|
[956] | 94 | // If there are no server processes then we are in attached mode |
---|
| 95 | // and the clients are also servers |
---|
| 96 | isServer = !usingServer; |
---|
[490] | 97 | |
---|
[523] | 98 | if (printLogs2Files) |
---|
| 99 | { |
---|
[499] | 100 | CClient::openInfoStream(clientFile); |
---|
[523] | 101 | CClient::openErrorStream(clientFile); |
---|
| 102 | } |
---|
[490] | 103 | else |
---|
[523] | 104 | { |
---|
[490] | 105 | CClient::openInfoStream(); |
---|
[523] | 106 | CClient::openErrorStream(); |
---|
| 107 | } |
---|
[490] | 108 | } |
---|
[300] | 109 | |
---|
| 110 | void CXios::clientFinalize(void) |
---|
| 111 | { |
---|
[490] | 112 | CClient::finalize() ; |
---|
[697] | 113 | if (CClient::getRank()==0) |
---|
| 114 | { |
---|
| 115 | info(80)<<"Write data base Registry"<<endl<<globalRegistry->toString()<<endl ; |
---|
| 116 | globalRegistry->toFile("xios_registry.bin") ; |
---|
| 117 | delete globalRegistry ; |
---|
| 118 | } |
---|
[490] | 119 | |
---|
[401] | 120 | #ifdef XIOS_MEMTRACK |
---|
[1158] | 121 | |
---|
| 122 | #ifdef XIOS_MEMTRACK_LIGHT |
---|
| 123 | report(10) << " Memory report : current memory used by XIOS : "<< MemTrack::getCurrentMemorySize()*1.0/(1024*1024)<<" Mbyte" << endl ; |
---|
| 124 | report(10) << " Memory report : maximum memory used by XIOS : "<< MemTrack::getMaxMemorySize()*1.0/(1024*1024)<<" Mbyte" << endl ; |
---|
| 125 | #endif |
---|
| 126 | |
---|
| 127 | #ifdef XIOS_MEMTRACK_FULL |
---|
[401] | 128 | MemTrack::TrackListMemoryUsage() ; |
---|
[490] | 129 | MemTrack::TrackDumpBlocks(); |
---|
[401] | 130 | #endif |
---|
[1158] | 131 | |
---|
| 132 | CClient::closeInfoStream(); |
---|
| 133 | |
---|
| 134 | #endif |
---|
[490] | 135 | } |
---|
| 136 | |
---|
[512] | 137 | //! Init server by parsing only xios part of config file |
---|
[509] | 138 | void CXios::initServer() |
---|
| 139 | { |
---|
| 140 | set_new_handler(noMemory); |
---|
| 141 | std::set<StdString> parseList; |
---|
| 142 | parseList.insert("xios"); |
---|
| 143 | xml::CXMLParser::ParseFile(rootFile, parseList); |
---|
[511] | 144 | parseXiosConfig(); |
---|
[509] | 145 | } |
---|
| 146 | |
---|
[512] | 147 | //! Initialize server then put it into listening state |
---|
[1054] | 148 | void CXios::initServerSide(void) |
---|
[300] | 149 | { |
---|
[509] | 150 | initServer(); |
---|
[1158] | 151 | isClient = false; |
---|
| 152 | isServer = true; |
---|
[1021] | 153 | |
---|
| 154 | // Initialize all aspects MPI |
---|
| 155 | CServer::initialize(); |
---|
[697] | 156 | if (CServer::getRank()==0) globalRegistry = new CRegistry(CServer::intraComm) ; |
---|
| 157 | |
---|
[523] | 158 | if (printLogs2Files) |
---|
| 159 | { |
---|
[1021] | 160 | if (CServer::serverLevel == 0) |
---|
[983] | 161 | { |
---|
| 162 | CServer::openInfoStream(serverFile); |
---|
| 163 | CServer::openErrorStream(serverFile); |
---|
| 164 | } |
---|
[1021] | 165 | else if (CServer::serverLevel == 1) |
---|
[983] | 166 | { |
---|
[1021] | 167 | CServer::openInfoStream(serverPrmFile); |
---|
| 168 | CServer::openErrorStream(serverPrmFile); |
---|
[983] | 169 | } |
---|
| 170 | else |
---|
| 171 | { |
---|
[1021] | 172 | CServer::openInfoStream(serverSndFile); |
---|
| 173 | CServer::openErrorStream(serverSndFile); |
---|
[983] | 174 | } |
---|
[523] | 175 | } |
---|
[490] | 176 | else |
---|
[523] | 177 | { |
---|
[490] | 178 | CServer::openInfoStream(); |
---|
[523] | 179 | CServer::openErrorStream(); |
---|
| 180 | } |
---|
[490] | 181 | |
---|
[491] | 182 | // Enter the loop to listen message from Client |
---|
[490] | 183 | CServer::eventLoop(); |
---|
| 184 | |
---|
[491] | 185 | // Finalize |
---|
[697] | 186 | if (CServer::getRank()==0) |
---|
| 187 | { |
---|
| 188 | info(80)<<"Write data base Registry"<<endl<<globalRegistry->toString()<<endl ; |
---|
| 189 | globalRegistry->toFile("xios_registry.bin") ; |
---|
| 190 | delete globalRegistry ; |
---|
| 191 | } |
---|
[490] | 192 | CServer::finalize(); |
---|
[1158] | 193 | |
---|
| 194 | #ifdef XIOS_MEMTRACK |
---|
| 195 | |
---|
| 196 | #ifdef XIOS_MEMTRACK_LIGHT |
---|
| 197 | report(10) << " Memory report : current memory used by XIOS : "<< MemTrack::getCurrentMemorySize()*1.0/(1024*1024)<<" Mbyte" << endl ; |
---|
| 198 | report(10) << " Memory report : maximum memory used by XIOS : "<< MemTrack::getMaxMemorySize()*1.0/(1024*1024)<<" Mbyte" << endl ; |
---|
| 199 | #endif |
---|
| 200 | |
---|
| 201 | #ifdef XIOS_MEMTRACK_FULL |
---|
| 202 | MemTrack::TrackListMemoryUsage() ; |
---|
| 203 | MemTrack::TrackDumpBlocks(); |
---|
| 204 | #endif |
---|
| 205 | #endif |
---|
[490] | 206 | CServer::closeInfoStream(); |
---|
| 207 | } |
---|
| 208 | |
---|
[512] | 209 | //! Parse configuration file |
---|
[346] | 210 | void CXios::parseFile(const string& filename) |
---|
| 211 | { |
---|
[490] | 212 | xml::CXMLParser::ParseFile(filename); |
---|
[346] | 213 | } |
---|
[491] | 214 | |
---|
[512] | 215 | //! Set using server |
---|
[491] | 216 | void CXios::setUsingServer() |
---|
| 217 | { |
---|
| 218 | usingServer = true; |
---|
| 219 | } |
---|
| 220 | |
---|
[512] | 221 | //! Unset using server |
---|
[491] | 222 | void CXios::setNotUsingServer() |
---|
| 223 | { |
---|
| 224 | usingServer = false; |
---|
| 225 | } |
---|
[300] | 226 | } |
---|