[300] | 1 | |
---|
| 2 | #include "xmlioserver_spl.hpp" |
---|
| 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; |
---|
[317] | 25 | size_t CXios::bufferSize ; |
---|
| 26 | double CXios::bufferServerFactorSize=2 ; |
---|
| 27 | size_t CXios::defaultBufferSize=1024*1024*100 ; // 100Mo |
---|
| 28 | double CXios::defaultBufferServerFactorSize=2 ; |
---|
[490] | 29 | bool CXios::printInfo2File; |
---|
[499] | 30 | bool CXios::isServerSide; |
---|
[490] | 31 | |
---|
| 32 | |
---|
[300] | 33 | void CXios::initialize() |
---|
| 34 | { |
---|
[400] | 35 | set_new_handler(noMemory); |
---|
[346] | 36 | parseFile(rootFile); |
---|
[311] | 37 | usingOasis=getin<bool>("using_oasis",false) ; |
---|
[506] | 38 | usingServer=getin<bool>("using_server",false) ; |
---|
[311] | 39 | info.setLevel(getin<int>("info_level",0)) ; |
---|
[491] | 40 | printInfo2File=getin<bool>("print_file",false); |
---|
[317] | 41 | bufferSize=getin<size_t>("buffer_size",defaultBufferSize) ; |
---|
| 42 | bufferServerFactorSize=getin<double>("buffer_server_factor_size",defaultBufferServerFactorSize) ; |
---|
[300] | 43 | globalComm=MPI_COMM_WORLD ; |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | |
---|
| 47 | void CXios::initClientSide(const string& codeId, MPI_Comm& localComm, MPI_Comm& returnComm) |
---|
| 48 | { |
---|
| 49 | initialize() ; |
---|
[490] | 50 | |
---|
[300] | 51 | isClient=true; |
---|
[491] | 52 | |
---|
| 53 | CClient::initialize(codeId,localComm,returnComm) ; |
---|
| 54 | |
---|
[499] | 55 | if (usingServer) isServerSide = isServer=false; |
---|
| 56 | else isServerSide = isServer=true; |
---|
[490] | 57 | |
---|
| 58 | if (printInfo2File) |
---|
[499] | 59 | CClient::openInfoStream(clientFile); |
---|
[490] | 60 | else |
---|
| 61 | CClient::openInfoStream(); |
---|
| 62 | } |
---|
[300] | 63 | |
---|
| 64 | void CXios::clientFinalize(void) |
---|
| 65 | { |
---|
[490] | 66 | CClient::finalize() ; |
---|
| 67 | CClient::closeInfoStream(); |
---|
| 68 | |
---|
[401] | 69 | #ifdef XIOS_MEMTRACK |
---|
| 70 | MemTrack::TrackListMemoryUsage() ; |
---|
[490] | 71 | MemTrack::TrackDumpBlocks(); |
---|
[401] | 72 | #endif |
---|
[490] | 73 | } |
---|
| 74 | |
---|
[509] | 75 | void CXios::initServer() |
---|
| 76 | { |
---|
| 77 | set_new_handler(noMemory); |
---|
| 78 | std::set<StdString> parseList; |
---|
| 79 | parseList.insert("xios"); |
---|
| 80 | xml::CXMLParser::ParseFile(rootFile, parseList); |
---|
| 81 | // parseFile(rootFile); |
---|
| 82 | usingOasis=getin<bool>("using_oasis",false) ; |
---|
| 83 | info.setLevel(getin<int>("info_level",0)) ; |
---|
| 84 | printInfo2File=getin<bool>("print_file",false); |
---|
| 85 | bufferSize=getin<size_t>("buffer_size",defaultBufferSize) ; |
---|
| 86 | bufferServerFactorSize=getin<double>("buffer_server_factor_size",defaultBufferServerFactorSize) ; |
---|
| 87 | globalComm=MPI_COMM_WORLD ; |
---|
[490] | 88 | |
---|
[509] | 89 | } |
---|
| 90 | |
---|
[300] | 91 | void CXios::initServerSide(void) |
---|
| 92 | { |
---|
[509] | 93 | // initialize(); |
---|
| 94 | initServer(); |
---|
[300] | 95 | isClient=true; |
---|
| 96 | isServer=false ; |
---|
| 97 | |
---|
[499] | 98 | isServerSide = true; |
---|
| 99 | |
---|
[491] | 100 | // Initialize all aspects MPI |
---|
[490] | 101 | CServer::initialize(); |
---|
| 102 | |
---|
| 103 | if (printInfo2File) |
---|
[499] | 104 | CServer::openInfoStream(serverFile); |
---|
[490] | 105 | else |
---|
| 106 | CServer::openInfoStream(); |
---|
| 107 | |
---|
[491] | 108 | // Enter the loop to listen message from Client |
---|
[490] | 109 | CServer::eventLoop(); |
---|
| 110 | |
---|
[491] | 111 | // Finalize |
---|
[490] | 112 | CServer::finalize(); |
---|
| 113 | CServer::closeInfoStream(); |
---|
| 114 | } |
---|
| 115 | |
---|
[346] | 116 | void CXios::parseFile(const string& filename) |
---|
| 117 | { |
---|
[490] | 118 | xml::CXMLParser::ParseFile(filename); |
---|
[346] | 119 | } |
---|
[491] | 120 | |
---|
| 121 | void CXios::setUsingServer() |
---|
| 122 | { |
---|
| 123 | usingServer = true; |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | void CXios::setNotUsingServer() |
---|
| 127 | { |
---|
| 128 | usingServer = false; |
---|
| 129 | } |
---|
[300] | 130 | } |
---|