1 | #ifndef __SERVER_HPP__ |
---|
2 | #define __SERVER_HPP__ |
---|
3 | |
---|
4 | #include "xios_spl.hpp" |
---|
5 | #include "context.hpp" |
---|
6 | #include "context_client.hpp" |
---|
7 | #include "mpi.hpp" |
---|
8 | #include "event_scheduler.hpp" |
---|
9 | #include "oasis_cinterface.hpp" |
---|
10 | |
---|
11 | namespace xios |
---|
12 | { |
---|
13 | class CServersRessource ; |
---|
14 | |
---|
15 | class CThirdPartyDriver |
---|
16 | { |
---|
17 | public: |
---|
18 | CThirdPartyDriver() |
---|
19 | { |
---|
20 | oasis_init(CXios::xiosCodeId); |
---|
21 | }; |
---|
22 | virtual ~CThirdPartyDriver() |
---|
23 | { |
---|
24 | oasis_finalize(); |
---|
25 | }; |
---|
26 | virtual void endSynchronizedDefinition() |
---|
27 | { |
---|
28 | oasis_enddef(); |
---|
29 | }; |
---|
30 | virtual void getComponentCommunicator(MPI_Comm &intraComm) |
---|
31 | { |
---|
32 | oasis_get_localcomm(intraComm); |
---|
33 | }; |
---|
34 | }; |
---|
35 | |
---|
36 | class CServer |
---|
37 | { |
---|
38 | public: |
---|
39 | static void initialize(void); |
---|
40 | static void xiosGlobalCommByFileExchange(MPI_Comm serverComm) ; |
---|
41 | static void xiosGlobalCommByPublishing(MPI_Comm serverComm) ; |
---|
42 | |
---|
43 | static void listenRootOasisEnddef(void); |
---|
44 | static void listenOasisEnddef(void); |
---|
45 | |
---|
46 | static void finalize(void); |
---|
47 | static void eventLoop(void); |
---|
48 | |
---|
49 | static MPI_Comm intraComm_; |
---|
50 | static MPI_Comm serversComm_; |
---|
51 | static std::list<MPI_Comm> interCommLeft; // interComm between server (primary, classical or secondary) and its client (client or primary server) |
---|
52 | static std::list<MPI_Comm> interCommRight; // interComm between primary server and secondary server (non-empty only for primary server pool) |
---|
53 | static std::list<MPI_Comm> contextInterComms; // list of context intercomms |
---|
54 | static std::list<MPI_Comm> contextIntraComms; // list of context intercomms (needed only in case of secondary servers) |
---|
55 | static CEventScheduler* eventScheduler; |
---|
56 | |
---|
57 | static int serverLevel ; |
---|
58 | |
---|
59 | struct contextMessage |
---|
60 | { |
---|
61 | int nbRecv; |
---|
62 | int leaderRank; |
---|
63 | }; |
---|
64 | |
---|
65 | static bool isRoot; |
---|
66 | |
---|
67 | static map<string,CContext*> contextList; |
---|
68 | static bool finished; |
---|
69 | static bool is_MPI_Initialized; |
---|
70 | |
---|
71 | public: |
---|
72 | //! Get rank of the current process in the intraComm |
---|
73 | static int getRank(); |
---|
74 | |
---|
75 | //!< Get global ranks of secondary server processes |
---|
76 | static vector<int>& getSecondaryServerGlobalRanks(); |
---|
77 | |
---|
78 | //! Open a file stream to write the info logs |
---|
79 | static void openInfoStream(const StdString& fileName); |
---|
80 | //! Write the info logs to standard output |
---|
81 | static void openInfoStream(); |
---|
82 | //! Close the info logs file if it opens |
---|
83 | static void closeInfoStream(); |
---|
84 | |
---|
85 | //! Open a file stream to write the error log |
---|
86 | static void openErrorStream(const StdString& fileName); |
---|
87 | //! Write the error log to standard error output |
---|
88 | static void openErrorStream(); |
---|
89 | //! Close the error log file if it opens |
---|
90 | static void closeErrorStream(); |
---|
91 | |
---|
92 | static CServersRessource* getServersRessource(void) { return serversRessource_;} |
---|
93 | static void launchServersRessource(MPI_Comm commServer) ; |
---|
94 | static void finalizeServersRessource(void) ; |
---|
95 | static void openStream(const StdString& fileName, const StdString& ext, std::filebuf* fb); |
---|
96 | |
---|
97 | private: |
---|
98 | static vector<int> sndServerGlobalRanks; //!< Global ranks of pool leaders on the secondary server |
---|
99 | static int rank_; //!< If (!oasis) global rank, else rank in the intraComm returned by oasis |
---|
100 | static int nbContexts; //!< Number of contexts registered by server |
---|
101 | static StdOFStream m_infoStream; |
---|
102 | static StdOFStream m_errorStream; |
---|
103 | static CServersRessource* serversRessource_ ; |
---|
104 | |
---|
105 | static CThirdPartyDriver* driver_; |
---|
106 | }; |
---|
107 | } |
---|
108 | |
---|
109 | #endif |
---|