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


In reply to WorkCrew threading by FFRANK

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.