in reply to Parallel Modules ?

Any parallel module can handle this case?

Yes, threads. Ostensibly it should be as simple as:

use threads; use Your::Module; my @AoH = map $_->join, map{ async( \&{ "Your::Module::$_" } ) } qw[ sub1 sub2 sub3 sub4 sub5 sub5 sub7 sub8 sub9 sub10 ]; ## do something with the 10 hashrefs here

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: Parallel Modules ?
by Gary Yang (Acolyte) on Nov 29, 2011 at 08:57 UTC

    Hi BrowserUk,

    use Async is a good solution. The return value from paralleled subs is hash reference, I use the AsyncData

    use Async;
    $proc = AsyncData->new(sub {...});

    But, I got errors. It says, "Magic number checking on storable string failed at /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/Storable.pm line 416, at /usr/lib/perl5/site_perl/5.8.8/Async.pm line 128". I google searched. But, did not find any good explanation and solution. Do you have any idea?

    Gary

      use Async is a good solution.

      Err, no. Use Async is a terrible solution. look at the errors it is giving you.

      I suggested use threads, which would be a good solution. For a start you wouldn't be having the errors you now have,


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

        Thanks for the comments.

        use threads;
        Somehow, I am not able to pass parameters to sub routines using threads->create.
        Below are the sample code and errors.

        Better.pm

        package Better; sub saveBetter { my ($sbn, $cost, $ur) = @_; print "sbn: $sbn\n"; print "cost: $cost\n"; print "url: $url\n"; return; } 1;

        test.pl
        #!/usr/bin/perl -w use strict; use warnings; use threads; use Better; my $sbn = "123489876"; my $lee = "12.89"; my $abc = "abcde"; my @ParamList = ($sbn, $lee, $abc); my $thr = threads->create(Better::saveBetter, @ParamList); $thr->join();
        ./test.pl
        Use of uninitialized value in concatenation (.) or string at Better.pm line 6.
        sbn: Use of uninitialized value in concatenation (.) or string at Better.pm line 7.
        cost: Use of uninitialized value in concatenation (.) or string at Better.pm line 8.
        url: Thread 1 terminated abnormally: Undefined subroutine &main::123489876 called at ./test.pl line 14.

        Changed code to
        #!/usr/bin/perl -w use strict; use warnings; use threads; use Better; my $sbn = "123489876"; my $lee = "12.89"; my $abc = "abcde"; my $thr = threads->create(Better::saveBetter, $sbn, $lee, $abc); $thr->join();

        Still got same error.

        Any idea?
        Some output of perl -V

        perl -V
        Summary of my perl5 (revision 5 version 8 subversion 8) configuration: Platform:
        osname=linux, osvers=2.6.18-128.1.10.el5, archname=x86_64-linux-thread-multi uname='linux ls20-bc2-13.build.redhat.com 2.6.18-128.1.10.el5 #1 smp wed apr 29 13:53:08 edt 2009 x86_64 x86_64 x86_64 gnulinux '
        usethreads=define use5005threads=undef useithreads=define usemultiplicity=define