Nengo.ca

ca.nengo.util.impl
Class NodeThreadPool

java.lang.Object
  extended by ca.nengo.util.impl.NodeThreadPool

public class NodeThreadPool
extends java.lang.Object

A pool of threads for running nodes in. All interaction with the threads is done through this class.


Field Summary
protected static int defaultNumJavaThreads
           
protected static int maxNumJavaThreads
           
protected  double myAverageTimePerStep
           
protected static boolean myCollectTimings
           
protected  float myEndTime
           
protected  java.lang.Object myLock
           
protected  Node[] myNodes
           
protected static int myNumJavaThreads
           
protected  int myNumSteps
           
protected  int myNumThreads
           
protected  Projection[] myProjections
           
protected  long myRunStartTime
           
protected  float myStartTime
           
protected  ThreadTask[] myTasks
           
protected  NodeThread[] myThreads
           
protected  int numThreadsComplete
           
protected  int numThreadsWaiting
           
protected  boolean runFinished
           
protected  boolean threadsRunning
           
 
Constructor Summary
protected NodeThreadPool()
           
  NodeThreadPool(Network network, java.util.List<ThreadTask> threadTasks)
           
 
Method Summary
static java.util.List<Node> collectNodes(Node[] startingNodes, boolean breakDownNetworkArrays)
          Return all the nodes in the network except subnetworks.
static java.util.List<Projection> collectProjections(Node[] startingNodes, Projection[] startingProjections)
          Return all the projections in the network.
static java.util.List<ThreadTask> collectTasks(Node[] startingNodes)
          Return all the tasks in the network.
 float getEndTime()
           
static int getMaxNumJavaThreads()
           
static int getNumJavaThreads()
           
 boolean getRunFinished()
           
 float getStartTime()
           
protected  void initialize(Network network, java.util.List<ThreadTask> threadTasks)
          1.
static boolean isCollectingTimings()
           
static boolean isMultithreading()
           
 void kill()
          Kill the threads in the pool by interrupting them.
static void setCollectTimings(boolean collectTimings)
           
static void setNumJavaThreads(int value)
           
 void step(float startTime, float endTime)
          Tell the threads in the current thread pool to take a step.
 void threadFinished()
          Called by the threads in this pool to signal that they are done a phase.
 void threadWait()
          Called by the threads in this node pool.
static void turnOffMultithreading()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

maxNumJavaThreads

protected static final int maxNumJavaThreads
See Also:
Constant Field Values

defaultNumJavaThreads

protected static final int defaultNumJavaThreads
See Also:
Constant Field Values

myNumJavaThreads

protected static int myNumJavaThreads

myNumThreads

protected int myNumThreads

myThreads

protected NodeThread[] myThreads

myLock

protected java.lang.Object myLock

myNodes

protected Node[] myNodes

myProjections

protected Projection[] myProjections

myTasks

protected ThreadTask[] myTasks

numThreadsComplete

protected volatile int numThreadsComplete

numThreadsWaiting

protected volatile int numThreadsWaiting

threadsRunning

protected volatile boolean threadsRunning

runFinished

protected volatile boolean runFinished

myStartTime

protected float myStartTime

myEndTime

protected float myEndTime

myCollectTimings

protected static boolean myCollectTimings

myRunStartTime

protected long myRunStartTime

myAverageTimePerStep

protected double myAverageTimePerStep

myNumSteps

protected int myNumSteps
Constructor Detail

NodeThreadPool

protected NodeThreadPool()

NodeThreadPool

public NodeThreadPool(Network network,
                      java.util.List<ThreadTask> threadTasks)
Method Detail

getNumJavaThreads

public static int getNumJavaThreads()

setNumJavaThreads

public static void setNumJavaThreads(int value)

getMaxNumJavaThreads

public static int getMaxNumJavaThreads()

isMultithreading

public static boolean isMultithreading()

turnOffMultithreading

public static void turnOffMultithreading()

isCollectingTimings

public static boolean isCollectingTimings()

setCollectTimings

public static void setCollectTimings(boolean collectTimings)

getStartTime

public float getStartTime()

getEndTime

public float getEndTime()

getRunFinished

public boolean getRunFinished()

initialize

protected void initialize(Network network,
                          java.util.List<ThreadTask> threadTasks)
1. Checks whether the GPU is to be used for the simulation. If it is, creates a GPU Thread, passes this thread the nodes and projections which are to be run on the GPU, and calls the initialization function of the gpu thread's NEFGPUInterface. Starts the GPU thread. 2. Creates the appropriate number of java threads and assigns to each a fair number of projections, nodes and tasks from those that remain after the GPU data has been dealt with. Starts the Java threads. 3. Initializes synchronization primitives and variables for collecting timing data if applicable.


step

public void step(float startTime,
                 float endTime)
Tell the threads in the current thread pool to take a step. The step consists of three phases: projections, nodes, tasks. All threads must complete a stage before any thread begins the next stage, so, for example, all threads must finish processing all of their projections before any thread starts processing its nodes.


threadWait

public void threadWait()
                throws java.lang.InterruptedException
Called by the threads in this node pool. Called once they finish a phase (projections, nodes or tasks). Forces them to wait on myLock.

Throws:
java.lang.InterruptedException

threadFinished

public void threadFinished()
                    throws java.lang.InterruptedException
Called by the threads in this pool to signal that they are done a phase.

Throws:
java.lang.InterruptedException

kill

public void kill()
Kill the threads in the pool by interrupting them. Each thread will handle the interrupt signal by ending its run method, which kills it.


collectNodes

public static java.util.List<Node> collectNodes(Node[] startingNodes,
                                                boolean breakDownNetworkArrays)
Return all the nodes in the network except subnetworks. Essentially returns a "flattened" version of the network. The breakDownNetworkArrays param lets the caller choose whether to include Network Arrays in the returned list (=false) or to return the NEFEnsemble in the network array (=true). This facility is provided because sometimes Network Arrays should be treated like Networks, which is what they are as far as java is concerned (they extend the NetworkImpl class), and sometimes it is better to treat them like NEFEnsembles, which they are designed to emulate (they're supposed to be an easier-to-build version of large NEFEnsembles).


collectProjections

public static java.util.List<Projection> collectProjections(Node[] startingNodes,
                                                            Projection[] startingProjections)
Return all the projections in the network. Essentially returns all the projections that would be in a "flattened" version of the network.


collectTasks

public static java.util.List<ThreadTask> collectTasks(Node[] startingNodes)
Return all the tasks in the network. Essentially returns all the tasks that would be in a "flattened" version of the network.


Nengo.ca