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