1 | |
---|
2 | #include "xmlioserver_spl.hpp" |
---|
3 | #include "cxios.hpp" |
---|
4 | #include "client.hpp" |
---|
5 | #include "server.hpp" |
---|
6 | #include "xml_parser.hpp" |
---|
7 | #include <boost/functional/hash.hpp> |
---|
8 | #include "mpi.hpp" |
---|
9 | #include "memory.hpp" |
---|
10 | #include <new> |
---|
11 | #include "memtrack.hpp" |
---|
12 | |
---|
13 | namespace xios |
---|
14 | { |
---|
15 | string CXios::rootFile="./iodef.xml" ; |
---|
16 | string CXios::xiosCodeId="xios.x" ; |
---|
17 | string CXios::clientFile="./xios_client"; |
---|
18 | string CXios::serverFile="./xios_server"; |
---|
19 | |
---|
20 | bool CXios::isClient ; |
---|
21 | bool CXios::isServer ; |
---|
22 | MPI_Comm CXios::globalComm ; |
---|
23 | bool CXios::usingOasis ; |
---|
24 | bool CXios::usingServer = false; |
---|
25 | size_t CXios::bufferSize ; |
---|
26 | double CXios::bufferServerFactorSize=2 ; |
---|
27 | size_t CXios::defaultBufferSize=1024*1024*100 ; // 100Mo |
---|
28 | double CXios::defaultBufferServerFactorSize=2 ; |
---|
29 | bool CXios::printInfo2File; |
---|
30 | bool CXios::isServerSide; |
---|
31 | bool CXios::isOptPerformance = true; |
---|
32 | |
---|
33 | void CXios::initialize() |
---|
34 | { |
---|
35 | set_new_handler(noMemory); |
---|
36 | parseFile(rootFile); |
---|
37 | parseXiosConfig(); |
---|
38 | } |
---|
39 | |
---|
40 | void CXios::parseXiosConfig() |
---|
41 | { |
---|
42 | usingOasis=getin<bool>("using_oasis",false) ; |
---|
43 | usingServer=getin<bool>("using_server",false) ; |
---|
44 | info.setLevel(getin<int>("info_level",0)) ; |
---|
45 | report.setLevel(getin<int>("info_level",0)); |
---|
46 | printInfo2File=getin<bool>("print_file",false); |
---|
47 | bufferSize=getin<size_t>("buffer_size",defaultBufferSize) ; |
---|
48 | StdString bufMemory("memory"); |
---|
49 | StdString bufPerformance("performance"); |
---|
50 | StdString bufOpt = getin<StdString>("optimal_buffer_size", bufPerformance); |
---|
51 | std::transform(bufOpt.begin(), bufOpt.end(), bufOpt.begin(), ::tolower); |
---|
52 | if (0 == bufOpt.compare(bufMemory)) isOptPerformance = false; |
---|
53 | else if (0 != bufOpt.compare(bufPerformance)) |
---|
54 | { |
---|
55 | ERROR("CXios::parseXiosConfig()", << "optimal_buffer_size must be memory or performance "<< endl ); |
---|
56 | } |
---|
57 | |
---|
58 | // bufferServerFactorSize=getin<double>("buffer_server_factor_size",defaultBufferServerFactorSize) ; |
---|
59 | bufferServerFactorSize=getin<double>("buffer_factor_size",defaultBufferServerFactorSize) ; |
---|
60 | globalComm=MPI_COMM_WORLD ; |
---|
61 | } |
---|
62 | |
---|
63 | void CXios::initClientSide(const string& codeId, MPI_Comm& localComm, MPI_Comm& returnComm) |
---|
64 | { |
---|
65 | initialize() ; |
---|
66 | |
---|
67 | isClient=true; |
---|
68 | |
---|
69 | CClient::initialize(codeId,localComm,returnComm) ; |
---|
70 | |
---|
71 | if (usingServer) isServerSide = isServer=false; |
---|
72 | else isServerSide = isServer=true; |
---|
73 | |
---|
74 | if (printInfo2File) |
---|
75 | CClient::openInfoStream(clientFile); |
---|
76 | else |
---|
77 | CClient::openInfoStream(); |
---|
78 | } |
---|
79 | |
---|
80 | void CXios::clientFinalize(void) |
---|
81 | { |
---|
82 | CClient::finalize() ; |
---|
83 | CClient::closeInfoStream(); |
---|
84 | |
---|
85 | #ifdef XIOS_MEMTRACK |
---|
86 | MemTrack::TrackListMemoryUsage() ; |
---|
87 | MemTrack::TrackDumpBlocks(); |
---|
88 | #endif |
---|
89 | } |
---|
90 | |
---|
91 | void CXios::initServer() |
---|
92 | { |
---|
93 | set_new_handler(noMemory); |
---|
94 | std::set<StdString> parseList; |
---|
95 | parseList.insert("xios"); |
---|
96 | xml::CXMLParser::ParseFile(rootFile, parseList); |
---|
97 | parseXiosConfig(); |
---|
98 | } |
---|
99 | |
---|
100 | void CXios::initServerSide(void) |
---|
101 | { |
---|
102 | // initialize(); |
---|
103 | initServer(); |
---|
104 | isClient=true; |
---|
105 | isServer=false ; |
---|
106 | |
---|
107 | isServerSide = true; |
---|
108 | |
---|
109 | // Initialize all aspects MPI |
---|
110 | CServer::initialize(); |
---|
111 | |
---|
112 | if (printInfo2File) |
---|
113 | CServer::openInfoStream(serverFile); |
---|
114 | else |
---|
115 | CServer::openInfoStream(); |
---|
116 | |
---|
117 | // Enter the loop to listen message from Client |
---|
118 | CServer::eventLoop(); |
---|
119 | |
---|
120 | // Finalize |
---|
121 | CServer::finalize(); |
---|
122 | CServer::closeInfoStream(); |
---|
123 | } |
---|
124 | |
---|
125 | void CXios::parseFile(const string& filename) |
---|
126 | { |
---|
127 | xml::CXMLParser::ParseFile(filename); |
---|
128 | } |
---|
129 | |
---|
130 | void CXios::setUsingServer() |
---|
131 | { |
---|
132 | usingServer = true; |
---|
133 | } |
---|
134 | |
---|
135 | void CXios::setNotUsingServer() |
---|
136 | { |
---|
137 | usingServer = false; |
---|
138 | } |
---|
139 | } |
---|