Hi brothers,

I tried to understand fork. I think that I basically got the
theory behind it, but am far away from practical usage of this
nifty feature. What do I want to achieve? I want to simply harness
the power of SMP machines - just use all the nice BogoMIPS for
computational intensive tasks.

My first shot at it was Parallel::ForkManager:

use Parallel::ForkManager; # Yadda yadda local %hash; $pm = new Parallel::ForkManager(2); # Want use 2 CPUs now (###) foreach $thingy (@so_30_member_list) { my $pid = $pm->start and next; # (###) $hash{$thingy} = &big_heavy_computation_of($thingy); $pm->finish; # Terminates the child process (###) } &look_at_hash;
While this is really great because the loop just takes half
of the time to compute, it is not so great, because the hash
is very empty then. If I remove the (###) lines, the program
takes twice as long, but the hash is ok.

So now for me to better understand this. I assume, that with
the $pm->start and next a new child is forked with
completedly his own data, thus filling his own instance
of %hash, and then ... well ... just discarding it.

This isnīt actually what I want. How can I get the computer doing
what I want and not what Iīm telling him? :-)

Any help apreciated

Ciao


In reply to FORRRRRK again... by PetaMem

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.