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