Automatically generated by Pod::Man 4.09 (Pod::Simple 3.35) Standard preamble: ========================================================================
NAMEPDL::ParallelCPU - Parallel Processor MultiThreading Support in PDL (Experimental)
use PDL; # Set target of 4 parallel pthreads to create, with a lower limit of # 5Meg elements for splitting processing into parallel pthreads. set_autopthread_targ(4); set_autopthread_size(5); $a = zeroes(5000,5000); # Create 25Meg element array $b = $a + 5; # Processing will be split up into multiple pthreads # Get the actual number of pthreads for the last # processing operation. $actualPthreads = get_autopthread_actual();
TerminologyThe use of the term threading can be confusing with
To reduce confusion with the existing
Functions that control PDL PThreadsThis is a brief listing and description of the
Set the target number of processor-threads (pthreads) for multi-threaded processing. Setting auto_pthread_targ
to 0 means that no pthreading will occur.
See PDL::Core for details.
Set the minimum size (in Meg-elements or 2**20 elements) of the largest PDLinvolved in a function where auto-pthreading will be performed. For small PDLs, it probably isn't worth starting multiple pthreads, so this function is used to define a minimum threshold where auto-pthreading won't be attempted.
See PDL::Core for details.
Get the actual number of pthreads executed for the last pdl processing function.
See PDL::get_autopthread_actual for details.
Global Control of PDL PThreading using Environment Variables
For example, if the environment var
How WorksThe auto-pthreading process works by analyzing threaded array dimensions in
$a = sequence(20,4,3); # Small 3-D Array, size 20,4,3 # Setup auto-pthreading: set_autopthread_targ(2); # Target of 2 pthreads set_autopthread_size(0); # Zero so that the small PDLs in this example will be pthreaded # This will be split up into 2 pthreads $c = maximum($a);
For the above example, the maximum function has a signature of "(a(n); [o]c())", which means that the first dimension of $a (size 20) is a Core dimension of the maximum function. The other dimensions of $a (size 4,3) are threaded dimensions (i.e. will be threaded-over in the maximum function.
The auto-pthreading algorithm examines the threaded dims of size (4,3) and picks the 4 dimension,
since it is evenly divisible by the autopthread_targ of 2. The processing of the maximum function is then
split into two pthreads on the size-4 dimension, with dim indexes 0,2 processed by one pthread
and dim indexes 1,3 processed by the other pthread.
Must have POSIX Threads Enabled
Auto-PThreading only works if your
Non-Threadsafe CodeNot all the libraries that
To operate properly with these types of functions, the PPCode flag NoPthread has been introduced to indicate a function as not being pthread-safe. See
Size of PDL Dimensions and PThread Target
Due to the way a
The algorithm that picks the actual number of pthreads has some smarts (but could probably be improved) to adjust down from the auto_pthread_targ to get a number of pthreads that can evenly divide one of the threaded dimensions. For example, if a
Speed improvement might be less than you expect.If you have a 8 core machine and call auto_pthread_targ with 8 to generate 8 parallel pthreads, you probably won't get a 8X improvement in speed, due to memory bandwidth issues. Even though you have 8 separate CPUs crunching away on data, you will have (for most common machine architectures) common
4 pthreads. For more complex calculations the limit will be higher.