Parallel Region model element
ParallelRegion defines a piece of code that can be run in parallel on a shared memory parallel (SMP) computer
The element encapsulates access to Parallel Region
in the Parallel Java library.
Usage
To add a parallel region element to your model, drag the icon element to the list of your model elements
and edit the desired code. This code can make use of the following predefined constants and methods:
- int _threadCount: the number of threads running
- int _threadIndex: the index of the current thread
- int _firstThreadIndex(int min, int max): divides the range into seevrl subintervals and returns the first index for the current thread
- int _lastThreadIndex(int min, int max): divides the range into seevrl subintervals and returns the first index for the current thread
The element implements the following basic methods:
- boolean execute(int nThreads): will run the parallel code defined for this region in nThreads parallel threads.
The main thread blocks until all spanned threads finish their work. The number of threads must be bigger than 0, a value of 0 indicates
the computer should use the default number of threads (as specified by the "-Dpj.nt=4" command line directive) or just the maximum number of threads available.
- int getThreadCount(): returns the number of threads actually used in the last execution.
- long getExecutionTime(): returns the time (in milliseconds) of the last execution.
Example of use
pjRegion.execute(4); // runs the parallel code using 4 threads
pjRegion.execute(0); // runs the parallel code using the default number of threads
_println ("The region executed on "+pjRegion.getThreadCount()+" threads,");
_println ("and took "+pjRegion.getExecutionTime()+" milliseconds.");