Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re^5: Could there be a ThreadedMapReduce (instead of DistributedMapReduce)?

by BrowserUk (Pope)
on Oct 20, 2006 at 20:14 UTC ( #579696=note: print w/replies, xml ) Need Help??

in reply to Re^4: Could there be a ThreadedMapReduce (instead of DistributedMapReduce)?
in thread Could there be ThreadedMapReduce (and/or ForkedMapReduce) instead of DistributedMapReduce?

Is this too complicated for you?

#! perl -slw use strict; use threads; use threads::shared::Scalar; my $shared = threads::shared::Scalar->new; for ( 1.. 10 ) { async { sleep 1 + rand 3; $shared->value .= ":$_"; }; } $_->join for threads->list; print $shared->value; __END__ C:\test>579015 :1:2:3:5:6:9:4:7:8:10 C:\test>579015 :1:2:6:9:3:5:7:10:4:8 C:\test>579015 :4:5:6:7:8:9:3:1:2:10

Update: A slightly simpler version:

#! perl -slw use strict; use threads::shared::Scalar; our $T ||= 10; our $N ||= 1000; my $shared = threads::shared::Scalar->new; for( 1 .. $T ) { async{ for( 1 .. $N ) { $shared->value++; } }; } waitall; print $shared->value; __END__ C:\test>sharedScalar.plt -T=1000 -N=1000 1000000 C:\test>sharedScalar.plt -T=500 -N=1000 500000 C:\test>sharedScalar.plt -T=500 -N=12345 6172500 C:\test>sharedScalar.plt -T=123 -N=10 1230

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://579696]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2017-02-27 03:13 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (376 votes). Check out past polls.