be.hogent.tarsos.dsp.util
Class ConcurrencyUtils

java.lang.Object
  extended by be.hogent.tarsos.dsp.util.ConcurrencyUtils

public class ConcurrencyUtils
extends java.lang.Object

Concurrency utilities.

Author:
Piotr Wendykier (piotr.wendykier@gmail.com)

Method Summary
static int getNumberOfProcessors()
          Returns the number of available processors.
static int getNumberOfThreads()
          Returns the current number of threads.
static int getThreadsBeginN_1D_FFT_2Threads()
          Returns the minimal size of 1D data for which two threads are used.
static int getThreadsBeginN_1D_FFT_4Threads()
          Returns the minimal size of 1D data for which four threads are used.
static int getThreadsBeginN_2D()
          Returns the minimal size of 2D data for which threads are used.
static int getThreadsBeginN_3D()
          Returns the minimal size of 3D data for which threads are used.
static boolean isPowerOf2(int x)
          Checks if x is a power-of-two number.
static int nextPow2(int x)
          Returns the closest power-of-two number greater than or equal to x.
static int prevPow2(int x)
          Returns the closest power-of-two number less than or equal to x.
static void resetThreadsBeginN_FFT()
          Resets the minimal size of 1D data for which two and four threads are used.
static void resetThreadsBeginN()
          Resets the minimal size of 2D and 3D data for which threads are used.
static void setNumberOfThreads(int n)
          Sets the number of threads.
static void setThreadsBeginN_1D_FFT_2Threads(int n)
          Sets the minimal size of 1D data for which two threads are used.
static void setThreadsBeginN_1D_FFT_4Threads(int n)
          Sets the minimal size of 1D data for which four threads are used.
static void setThreadsBeginN_2D(int n)
          Sets the minimal size of 2D data for which threads are used.
static void setThreadsBeginN_3D(int n)
          Sets the minimal size of 3D data for which threads are used.
static void sleep(long millis)
          Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds.
static java.util.concurrent.Future<?> submit(java.lang.Runnable task)
          Submits a Runnable task for execution and returns a Future representing that task.
static void waitForCompletion(java.util.concurrent.Future<?>[] futures)
          Waits for all threads to complete computation.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getNumberOfProcessors

public static int getNumberOfProcessors()
Returns the number of available processors.

Returns:
number of available processors

getNumberOfThreads

public static int getNumberOfThreads()
Returns the current number of threads.

Returns:
the current number of threads.

setNumberOfThreads

public static void setNumberOfThreads(int n)
Sets the number of threads. If n is not a power-of-two number, then the number of threads is set to the closest power-of-two number less than n.

Parameters:
n -

getThreadsBeginN_1D_FFT_2Threads

public static int getThreadsBeginN_1D_FFT_2Threads()
Returns the minimal size of 1D data for which two threads are used.

Returns:
the minimal size of 1D data for which two threads are used

getThreadsBeginN_1D_FFT_4Threads

public static int getThreadsBeginN_1D_FFT_4Threads()
Returns the minimal size of 1D data for which four threads are used.

Returns:
the minimal size of 1D data for which four threads are used

getThreadsBeginN_2D

public static int getThreadsBeginN_2D()
Returns the minimal size of 2D data for which threads are used.

Returns:
the minimal size of 2D data for which threads are used

getThreadsBeginN_3D

public static int getThreadsBeginN_3D()
Returns the minimal size of 3D data for which threads are used.

Returns:
the minimal size of 3D data for which threads are used

setThreadsBeginN_1D_FFT_2Threads

public static void setThreadsBeginN_1D_FFT_2Threads(int n)
Sets the minimal size of 1D data for which two threads are used.

Parameters:
n - the minimal size of 1D data for which two threads are used

setThreadsBeginN_1D_FFT_4Threads

public static void setThreadsBeginN_1D_FFT_4Threads(int n)
Sets the minimal size of 1D data for which four threads are used.

Parameters:
n - the minimal size of 1D data for which four threads are used

setThreadsBeginN_2D

public static void setThreadsBeginN_2D(int n)
Sets the minimal size of 2D data for which threads are used.

Parameters:
n - the minimal size of 2D data for which threads are used

setThreadsBeginN_3D

public static void setThreadsBeginN_3D(int n)
Sets the minimal size of 3D data for which threads are used.

Parameters:
n - the minimal size of 3D data for which threads are used

resetThreadsBeginN_FFT

public static void resetThreadsBeginN_FFT()
Resets the minimal size of 1D data for which two and four threads are used.


resetThreadsBeginN

public static void resetThreadsBeginN()
Resets the minimal size of 2D and 3D data for which threads are used.


nextPow2

public static int nextPow2(int x)
Returns the closest power-of-two number greater than or equal to x.

Parameters:
x -
Returns:
the closest power-of-two number greater than or equal to x

prevPow2

public static int prevPow2(int x)
Returns the closest power-of-two number less than or equal to x.

Parameters:
x -
Returns:
the closest power-of-two number less then or equal to x

isPowerOf2

public static boolean isPowerOf2(int x)
Checks if x is a power-of-two number.

Parameters:
x -
Returns:
true if x is a power-of-two number

sleep

public static void sleep(long millis)
Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds.

Parameters:
millis -

submit

public static java.util.concurrent.Future<?> submit(java.lang.Runnable task)
Submits a Runnable task for execution and returns a Future representing that task.

Parameters:
task - a Runnable task for execution
Returns:
a Future representing the task

waitForCompletion

public static void waitForCompletion(java.util.concurrent.Future<?>[] futures)
Waits for all threads to complete computation.

Parameters:
futures -