http://www.perlmonks.org?node_id=628506

FFRANK has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

Perlthrtut - "In the work crew model, several threads are created that do essentially the same thing to different pieces of data."

Looking for a dummy example of workCrew threading, to be built on.

Something like: 1) take an array of numbers, 2) split it equally between 10 threads (each thread would process 1/10 of the array), 3) do something with those (some sub), 4) return the results into an array (initial positions), 5) return the indice of the initial number that has generated the highest result.

#!/usr/bin/perl -w use strict; use threads; use PDL; my @array = qw (9 10 3 2 4 7 8 1 5 6); # Separate the data in threads, do the sub (e.g add one), # return values into array at their original position (indice) my @array = qw (resThread1 resThread2 ...) my $piddle = pdl (@array); my ($min, $max, $min_ind, $max_ind) = minmaximum($piddle); print $max_ind,"\n";
Would the time gain be ~ 10 by using this approach on a single processor (say @array is big)...

Thanks very much,

Frank