root/juggler/branches/2.2/modules/gadgeteer/cluster/ClusterManager.h

Revision 19729, 7.8 kB (checked in by patrick, 2 years ago)

Copyright update.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /*************** <auto-copyright.pl BEGIN do not edit this line> **************
2  *
3  * VR Juggler is (C) Copyright 1998-2007 by Iowa State University
4  *
5  * Original Authors:
6  *   Allen Bierbaum, Christopher Just,
7  *   Patrick Hartling, Kevin Meinert,
8  *   Carolina Cruz-Neira, Albert Baker
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Library General Public
12  * License as published by the Free Software Foundation; either
13  * version 2 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Library General Public License for more details.
19  *
20  * You should have received a copy of the GNU Library General Public
21  * License along with this library; if not, write to the
22  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23  * Boston, MA 02111-1307, USA.
24  *
25  *************** <auto-copyright.pl END do not edit this line> ***************/
26
27 #ifndef _CLUSTER_CLUSTER_MANAGER_H
28 #define _CLUSTER_CLUSTER_MANAGER_H
29
30 #include <gadget/gadgetConfig.h>
31
32 #include <list>
33 #include <map>
34
35 #include <vpr/Util/GUID.h>
36 #include <vpr/Util/Singleton.h>
37 #include <vpr/DynLoad/Library.h>
38
39 #include <jccl/Config/ConfigElementPtr.h>
40 #include <jccl/RTRC/ConfigElementHandler.h>
41
42 #include <cluster/ClusterDepChecker.h>
43 #include <cluster/ClusterNetwork.h>
44
45
46 namespace gadget
47 {
48    class Node;
49 }
50
51 namespace cluster
52 {
53 class ClusterPlugin;
54
55 /** \class ClusterManager ClusterManager.h cluster/ClusterManager.h
56  *
57  * Manages the synchronization of all ClusterPlugins.
58  */
59 class GADGET_CLASS_API ClusterManager : public jccl::ConfigElementHandler
60 {
61    vprSingletonHeader( ClusterManager );
62 protected:
63    /** Constructor is hidden, so no direct instantiation is allowed. */
64    ClusterManager();
65
66    virtual ~ClusterManager();
67
68    /** Constructor is hidden, so no copying is allowed. */
69    ClusterManager( const ClusterManager& cm )
70       : jccl::ConfigElementHandler( cm )
71    {
72       /* Do nothing. */;
73    }
74
75    void operator=(const ClusterManager&)
76    {
77       /* Do nothing. */ ;
78    }
79 public:
80    /**
81     * Add a new ClusterPlugin.
82     */
83    void addPlugin( ClusterPlugin* new_manager );
84
85    /**
86     * Remove an existing ClusterPlugin.
87     */
88    void removePlugin( ClusterPlugin* old_manager );
89
90    /**
91     * Return the ClusterPlugin with the given GUID.
92     */
93    ClusterPlugin* getPluginByGUID( const vpr::GUID& plugin_guid );
94 private:
95    /**
96     * Return true if the specified ClusterPlugin exists.
97     */
98    bool doesPluginExist( ClusterPlugin* old_plugin );
99
100    /**
101     * Send end block to all other connected nodes and
102     * signal each connected node to sync.
103     */
104    void sendEndBlocksAndSignalUpdate( const int temp );
105
106    /**
107     * Returns the string representation of the element type used for the
108     * ClusterManager.
109     */
110    static std::string getElementType();
111 public:
112    /**
113     * Send each ClusterPlugin's requests.
114     */
115    void sendRequests();
116
117    /**
118     * Synchronize plugins directly before the kernel calls
119     * the draw() method.
120     */
121    void preDraw();
122
123    /**
124     * Synchronize plugins directly after the kernel calls
125     * the postFrame() method.
126     */
127    void postPostFrame();
128
129    /**
130     * Cycle through ClusterPlugins until one of them can
131     * achieve swaplock.
132     */
133    void createBarrier();
134
135    /**
136     * Cause the cluster to recover when a connection to
137     * a ClusterNode is lost.
138     */
139    void recoverFromLostNode( gadget::Node* lost_node );
140
141    /**
142     * Return the representation of the network which
143     * this cluster is running on.
144     */
145    ClusterNetwork* getNetwork()
146    {
147       return mClusterNetwork;
148    }
149
150    /**
151     * Return true if ConfigElement is a remote device.
152     */
153    bool recognizeRemoteDeviceConfig( jccl::ConfigElementPtr element );
154
155    /**
156     * Return true if Configelement is a ClusterManager element.
157     */
158    bool recognizeClusterManagerConfig( jccl::ConfigElementPtr element );
159
160    /**
161     * Configure the given ConfigElement.
162     *
163     * @return true iff element was successfully configured.
164     */
165    bool configAdd( jccl::ConfigElementPtr element );
166
167    /**
168     * Shutdown the cluster using given ConfigElement.
169     *
170     * @return true iff the element (and any objects it represented)
171     *          were successfully removed.
172     */
173    bool configRemove( jccl::ConfigElementPtr element );
174
175    /**
176     * Checks if this handler can process the given element.
177     *
178     * @return true iff this handler can process element.
179     */
180    bool configCanHandle( jccl::ConfigElementPtr element );
181
182    /**
183     * Get a pointer to the ConfigElement with the given name.
184     */
185    jccl::ConfigElementPtr getConfigElementPointer( const std::string& name );
186
187    /*
188    Truth table for ClusterManager
189
190    Active   Ready
191       1        0  = 0
192       1        1  = 1
193       0        0  = 1
194       0        1  = 1
195
196       (NOT(Active AND (NOT READY)))
197       (NOT(Active) OR (Active AND Ready))
198    */
199
200    /**
201     * Return true if we are running on a cluster.
202     */
203    bool isClusterActive()
204    {
205       vpr::Guard<vpr::Mutex> guard( mClusterActiveLock );
206       return mClusterActive;
207    }
208
209    /**
210     * Return true if all dependancies have been satisfied.
211     */
212    bool isClusterReady();
213
214    /**
215     * Return true if all plugins have their dependancies satisfied.
216     */
217    bool pluginsReady();
218
219    /**
220     * Change the ready state of the ClusterManager.
221     */
222    void setClusterReady( const bool ready )
223    {
224       vpr::Guard<vpr::Mutex> guard( mClusterReadyLock );
225
226       vprDEBUG( gadgetDBG_RIM, vprDBG_CONFIG_LVL )
227          << clrOutBOLD( clrCYAN, "[ClusterManager]" )
228          << " Cluster is ready." << std::endl << vprDEBUG_FLUSH;
229
230       mClusterReady = ready;
231    }
232
233    /**
234     * Output the current status of the cluster.
235     */
236    friend GADGET_API( std::ostream& ) operator<<( std::ostream& out,
237                                                   ClusterManager& mgr );
238
239    /**
240     * Get a list of hostnames for all ClusterNodes.
241     */
242    std::vector<std::string> getNodes()
243    {
244       vpr::Guard<vpr::Mutex> guard( mNodesLock );
245       return mNodes;
246    }
247
248    /**
249     * Return the number of times that preDraw() has been called.
250     */
251    vpr::Uint64 preDrawCallCount()
252    {
253       return mPreDrawCallCount;
254    }
255
256    /**
257     * Return the number of times that postPostFrame() has been called.
258     */
259    vpr::Uint64 postPostFrameCallCount()
260    {
261       return mPostPostFrameCallCount;
262    }
263
264 private:
265    ClusterDepChecker            mDepChecker;
266
267    std::list<ClusterPlugin*>    mPlugins;            /**< List of Plugins.*/
268    vpr::Mutex                   mPluginsLock;        /**< Lock on plugins list.*/
269    std::string                  mBarrierMachineName; /**< Name of the barrier machine.*/
270    std::map<vpr::GUID, ClusterPlugin*> mPluginMap;   /**< Map of ClusterPlugins. */
271    std::vector<vpr::LibraryPtr> mLoadedPlugins;
272
273    vpr::Mutex                   mNodesLock;          /**< Lock on hostname list. */
274    std::vector<std::string>     mNodes;              /**< Hostnames of the nodes in the cluster. */
275
276    vpr::Mutex                   mClusterActiveLock;  /**< Lock on ClusterActive bool.*/
277    bool                         mClusterActive;      /**< Flag informing us if this app is running on a cluster. */
278
279    vpr::Mutex                   mClusterReadyLock;   /**< Lock on ClusterReady bool.*/
280    bool                         mClusterReady;       /**< Flag set true when all dependancies are satisfied. */
281
282    ClusterNetwork*              mClusterNetwork;     /**< The network representation of the cluster. */
283
284    vpr::Uint64                  mPreDrawCallCount;       /**< # calls to preDraw() */
285    vpr::Uint64                  mPostPostFrameCallCount; /**< # calls to postPostFrame() */
286 };
287
288 } // end namespace
289
290 #endif
Note: See TracBrowser for help on using the browser.