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