00001 //---------------------------------------------------------------------------- 00002 /** @file SgMpiSynchronizer.h 00003 */ 00004 //---------------------------------------------------------------------------- 00005 00006 #ifndef SG_MPISYNCHRONIZER_H 00007 #define SG_MPISYNCHRONIZER_H 00008 00009 #include <iostream> 00010 #include <string> 00011 #include <boost/shared_ptr.hpp> 00012 #include "SgMove.h" 00013 #include "SgSystem.h" 00014 00015 //---------------------------------------------------------------------------- 00016 00017 class SgUctSearch; 00018 00019 class SgUctThreadState; 00020 00021 class SgUctGameInfo; 00022 00023 /** Interface for mpi synchronizers. */ 00024 class SgMpiSynchronizer 00025 { 00026 public: 00027 virtual ~SgMpiSynchronizer(); 00028 00029 virtual std::string ToNodeFilename(const std::string &filename) const = 0; 00030 00031 virtual bool IsRootProcess() const = 0; 00032 00033 virtual void OnStartSearch(SgUctSearch &search) = 0; 00034 00035 virtual void OnEndSearch(SgUctSearch &search) = 0; 00036 00037 virtual void OnThreadStartSearch(SgUctSearch &search, 00038 SgUctThreadState &state) = 0; 00039 00040 virtual void OnThreadEndSearch(SgUctSearch &search, 00041 SgUctThreadState &state) = 0; 00042 00043 virtual void OnSearchIteration(SgUctSearch &search, 00044 std::size_t gameNumber, 00045 int threadId, 00046 const SgUctGameInfo& info) = 0; 00047 00048 virtual void OnStartPonder() = 0; 00049 00050 virtual void OnEndPonder() = 0; 00051 00052 virtual void WriteStatistics(std::ostream& out) const = 0; 00053 00054 virtual void SynchronizeUserAbort(bool &flag) = 0; 00055 00056 virtual void SynchronizePassWins(bool &flag) = 0; 00057 00058 virtual void SynchronizeEarlyPassPossible(bool &flag) = 0; 00059 00060 virtual void SynchronizeMove(SgMove &move) = 0; 00061 00062 virtual void SynchronizeValue(float &value) = 0; 00063 00064 virtual void SynchronizeSearchStatus(float &value, bool &earlyAbort, 00065 std::size_t &rootMoveCount) = 0; 00066 }; 00067 00068 typedef boost::shared_ptr<SgMpiSynchronizer> SgMpiSynchronizerHandle; 00069 00070 //---------------------------------------------------------------------------- 00071 00072 /** Synchronizer with empty implementation. */ 00073 class SgMpiNullSynchronizer : public SgMpiSynchronizer 00074 { 00075 public: 00076 SgMpiNullSynchronizer(); 00077 00078 virtual ~SgMpiNullSynchronizer(); 00079 00080 static SgMpiSynchronizerHandle Create(); 00081 00082 virtual std::string ToNodeFilename(const std::string &filename) const; 00083 00084 virtual bool IsRootProcess() const; 00085 00086 virtual void OnStartSearch(SgUctSearch &search); 00087 00088 virtual void OnEndSearch(SgUctSearch &search); 00089 00090 virtual void OnThreadStartSearch(SgUctSearch &search, 00091 SgUctThreadState &state); 00092 00093 virtual void OnThreadEndSearch(SgUctSearch &search, 00094 SgUctThreadState &state); 00095 00096 virtual void OnSearchIteration(SgUctSearch &search, std::size_t gameNumber, 00097 int threadId, const SgUctGameInfo& info); 00098 00099 virtual void OnStartPonder(); 00100 00101 virtual void OnEndPonder(); 00102 00103 virtual void WriteStatistics(std::ostream& out) const; 00104 00105 virtual void SynchronizeUserAbort(bool &flag); 00106 00107 virtual void SynchronizePassWins(bool &flag); 00108 00109 virtual void SynchronizeEarlyPassPossible(bool &flag); 00110 00111 virtual void SynchronizeMove(SgMove &move); 00112 00113 virtual void SynchronizeValue(float &value); 00114 00115 virtual void SynchronizeSearchStatus(float &value, bool &earlyAbort, 00116 std::size_t &rootMoveCount); 00117 00118 }; 00119 00120 // Ensure forward definitions 00121 // are eventually declared 00122 #include "SgUctSearch.h" 00123 00124 //---------------------------------------------------------------------------- 00125 00126 #endif // SG_MPISYNCHRONIZER_H