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