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