com.jogamp.opencl.util.concurrent
Class CLCommandQueuePool<C extends CLQueueContext>

java.lang.Object
  extended by com.jogamp.opencl.util.concurrent.CLCommandQueuePool<C>
All Implemented Interfaces:
CLResource

public class CLCommandQueuePool<C extends CLQueueContext>
extends Object
implements CLResource

A multithreaded, fixed size pool of OpenCL command queues. It serves as a multiplexer distributing tasks over N queues usually run on N devices. The usage of this pool is similar to ExecutorService but it uses CLTasks instead of Callables and provides a per-queue context for resource sharing across all tasks of one queue.

Author:
Michael Bien

Nested Class Summary
static class CLCommandQueuePool.FinishAction
          The action executed after a task completes.
 
Method Summary
static
<C extends CLQueueContext>
CLCommandQueuePool<C>
create(CLQueueContextFactory<C> factory, CLMultiContext mc, CLCommandQueue.Mode... modes)
           
static
<C extends CLQueueContext>
CLCommandQueuePool
create(CLQueueContextFactory<C> factory, Collection<CLCommandQueue> queues)
           
static
<C extends CLQueueContext>
CLCommandQueuePool<C>
create(CLQueueContextFactory<C> factory, Collection<CLDevice> devices, CLCommandQueue.Mode... modes)
           
 void finishQueues()
          Calls CLCommandQueue.finish() on all queues.
 void flushQueues()
          Calls CLCommandQueue.flush() on all queues.
 CLCommandQueuePool.FinishAction getFinishAction()
           
 List<CLCommandQueue> getQueues()
          Returns the command queues used in this pool.
 int getSize()
          Returns the size of this pool (number of command queues).
<R> List<Future<R>>
invokeAll(Collection<? extends CLTask<? super C,R>> tasks)
          Submits all tasks to the pool for immediate execution (blocking) and returns their Future holding the result.
<R> List<Future<R>>
invokeAll(Collection<? extends CLTask<? super C,R>> tasks, long timeout, TimeUnit unit)
          Submits all tasks to the pool for immediate execution (blocking) and returns their Future holding the result.
 boolean isReleased()
          Returns true if CLResource.release() has been called.
 void release()
          Releases all queues.
 void setFinishAction(CLCommandQueuePool.FinishAction action)
          Sets the action which is run after every completed task.
<R> Future<R>
submit(CLTask<? super C,R> task)
          Submits this task to the pool for execution returning its Future.
<R> List<Future<R>>
submitAll(Collection<? extends CLTask<? super C,R>> tasks)
          Submits all tasks to the pool for execution and returns their Future.
<C extends CLQueueContext>
CLCommandQueuePool
switchContext(CLQueueContextFactory<C> factory)
          Switches the context of all queues - this operation can be expensive.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

create

public static <C extends CLQueueContext> CLCommandQueuePool<C> create(CLQueueContextFactory<C> factory,
                                                                      CLMultiContext mc,
                                                                      CLCommandQueue.Mode... modes)

create

public static <C extends CLQueueContext> CLCommandQueuePool<C> create(CLQueueContextFactory<C> factory,
                                                                      Collection<CLDevice> devices,
                                                                      CLCommandQueue.Mode... modes)

create

public static <C extends CLQueueContext> CLCommandQueuePool create(CLQueueContextFactory<C> factory,
                                                                   Collection<CLCommandQueue> queues)

submit

public <R> Future<R> submit(CLTask<? super C,R> task)
Submits this task to the pool for execution returning its Future.

See Also:
ExecutorService.submit(java.util.concurrent.Callable)

submitAll

public <R> List<Future<R>> submitAll(Collection<? extends CLTask<? super C,R>> tasks)
Submits all tasks to the pool for execution and returns their Future. Calls submit(com.jogamp.opencl.util.concurrent.CLTask) for every task.


invokeAll

public <R> List<Future<R>> invokeAll(Collection<? extends CLTask<? super C,R>> tasks)
                          throws InterruptedException
Submits all tasks to the pool for immediate execution (blocking) and returns their Future holding the result.

Throws:
InterruptedException
See Also:
ExecutorService.invokeAll(java.util.Collection)

invokeAll

public <R> List<Future<R>> invokeAll(Collection<? extends CLTask<? super C,R>> tasks,
                                     long timeout,
                                     TimeUnit unit)
                          throws InterruptedException
Submits all tasks to the pool for immediate execution (blocking) and returns their Future holding the result.

Throws:
InterruptedException
See Also:
ExecutorService.invokeAll(java.util.Collection, long, java.util.concurrent.TimeUnit)

switchContext

public <C extends CLQueueContext> CLCommandQueuePool switchContext(CLQueueContextFactory<C> factory)
Switches the context of all queues - this operation can be expensive. Blocks until all tasks finish and sets up a new context for all queues.

Returns:
this

flushQueues

public void flushQueues()
Calls CLCommandQueue.flush() on all queues.


finishQueues

public void finishQueues()
Calls CLCommandQueue.finish() on all queues.


release

public void release()
Releases all queues.

Specified by:
release in interface CLResource

getQueues

public List<CLCommandQueue> getQueues()
Returns the command queues used in this pool.


getSize

public int getSize()
Returns the size of this pool (number of command queues).


getFinishAction

public CLCommandQueuePool.FinishAction getFinishAction()

isReleased

public boolean isReleased()
Description copied from interface: CLResource
Returns true if CLResource.release() has been called.

Specified by:
isReleased in interface CLResource

setFinishAction

public void setFinishAction(CLCommandQueuePool.FinishAction action)
Sets the action which is run after every completed task. This is mainly intended for debugging, default value is CLCommandQueuePool.FinishAction.DO_NOTHING.


toString

public String toString()
Overrides:
toString in class Object