[342] | 1 | #ifndef __SERVER_HPP__ |
---|
| 2 | #define __SERVER_HPP__ |
---|
[300] | 3 | |
---|
[591] | 4 | #include "xios_spl.hpp" |
---|
[300] | 5 | #include "context.hpp" |
---|
[697] | 6 | #include "context_client.hpp" |
---|
[382] | 7 | #include "mpi.hpp" |
---|
[492] | 8 | #include "event_scheduler.hpp" |
---|
[2335] | 9 | #include "oasis_cinterface.hpp" |
---|
[300] | 10 | |
---|
[335] | 11 | namespace xios |
---|
[300] | 12 | { |
---|
[1761] | 13 | class CServersRessource ; |
---|
| 14 | |
---|
[2335] | 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 | |
---|
[300] | 36 | class CServer |
---|
| 37 | { |
---|
[523] | 38 | public: |
---|
| 39 | static void initialize(void); |
---|
[1761] | 40 | static void xiosGlobalCommByFileExchange(MPI_Comm serverComm) ; |
---|
| 41 | static void xiosGlobalCommByPublishing(MPI_Comm serverComm) ; |
---|
| 42 | |
---|
[2333] | 43 | static void listenRootOasisEnddef(void); |
---|
| 44 | static void listenOasisEnddef(void); |
---|
[2523] | 45 | static void testingEventScheduler(void); |
---|
| 46 | |
---|
[523] | 47 | static void finalize(void); |
---|
| 48 | static void eventLoop(void); |
---|
[1765] | 49 | |
---|
[2332] | 50 | static MPI_Comm intraComm_; |
---|
[1761] | 51 | static MPI_Comm serversComm_; |
---|
[1639] | 52 | static std::list<MPI_Comm> interCommLeft; // interComm between server (primary, classical or secondary) and its client (client or primary server) |
---|
| 53 | static std::list<MPI_Comm> interCommRight; // interComm between primary server and secondary server (non-empty only for primary server pool) |
---|
| 54 | static std::list<MPI_Comm> contextInterComms; // list of context intercomms |
---|
| 55 | static std::list<MPI_Comm> contextIntraComms; // list of context intercomms (needed only in case of secondary servers) |
---|
[523] | 56 | static CEventScheduler* eventScheduler; |
---|
[983] | 57 | |
---|
[1021] | 58 | static int serverLevel ; |
---|
[1009] | 59 | |
---|
[523] | 60 | struct contextMessage |
---|
| 61 | { |
---|
| 62 | int nbRecv; |
---|
| 63 | int leaderRank; |
---|
| 64 | }; |
---|
[300] | 65 | |
---|
[523] | 66 | static bool isRoot; |
---|
[490] | 67 | |
---|
[1054] | 68 | static map<string,CContext*> contextList; |
---|
[523] | 69 | static bool finished; |
---|
| 70 | static bool is_MPI_Initialized; |
---|
[490] | 71 | |
---|
[523] | 72 | public: |
---|
[1243] | 73 | //! Get rank of the current process in the intraComm |
---|
[523] | 74 | static int getRank(); |
---|
[490] | 75 | |
---|
[1180] | 76 | //!< Get global ranks of secondary server processes |
---|
[1168] | 77 | static vector<int>& getSecondaryServerGlobalRanks(); |
---|
| 78 | |
---|
[523] | 79 | //! Open a file stream to write the info logs |
---|
[490] | 80 | static void openInfoStream(const StdString& fileName); |
---|
[523] | 81 | //! Write the info logs to standard output |
---|
[490] | 82 | static void openInfoStream(); |
---|
[523] | 83 | //! Close the info logs file if it opens |
---|
[490] | 84 | static void closeInfoStream(); |
---|
| 85 | |
---|
[523] | 86 | //! Open a file stream to write the error log |
---|
| 87 | static void openErrorStream(const StdString& fileName); |
---|
| 88 | //! Write the error log to standard error output |
---|
| 89 | static void openErrorStream(); |
---|
| 90 | //! Close the error log file if it opens |
---|
| 91 | static void closeErrorStream(); |
---|
| 92 | |
---|
[1761] | 93 | static CServersRessource* getServersRessource(void) { return serversRessource_;} |
---|
| 94 | static void launchServersRessource(MPI_Comm commServer) ; |
---|
[2274] | 95 | static void finalizeServersRessource(void) ; |
---|
[2212] | 96 | static void openStream(const StdString& fileName, const StdString& ext, std::filebuf* fb); |
---|
[1761] | 97 | |
---|
[523] | 98 | private: |
---|
[1243] | 99 | static vector<int> sndServerGlobalRanks; //!< Global ranks of pool leaders on the secondary server |
---|
| 100 | static int rank_; //!< If (!oasis) global rank, else rank in the intraComm returned by oasis |
---|
| 101 | static int nbContexts; //!< Number of contexts registered by server |
---|
[490] | 102 | static StdOFStream m_infoStream; |
---|
[523] | 103 | static StdOFStream m_errorStream; |
---|
[2274] | 104 | static CServersRessource* serversRessource_ ; |
---|
[2335] | 105 | |
---|
| 106 | static CThirdPartyDriver* driver_; |
---|
[523] | 107 | }; |
---|
[300] | 108 | } |
---|
| 109 | |
---|
| 110 | #endif |
---|