in reply to Re: Parallel Modules ?
in thread Parallel Modules ?

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

Replies are listed 'Best First'.
Re^3: Parallel Modules ?
by BrowserUk (Patriarch) on Nov 29, 2011 at 11:11 UTC
    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

        Your problem is this line:

        my $thr = threads->create(Better::saveBetter, @ParamList); ##.......................^^^^^^^^^^^^^^^^^^

        The indicated part (Better::saveBetter) is invoking that subroutine and then passing the result to threads->create() as the first argument.

        Replace that line with:

        my $thr = threads->create( \&Better::saveBetter, @ParamList );

        And your sample will work.

        Or rather it will once you correct the typo:

        my ($sbn, $cost, $ur) = @_; #..................^^^ print "url: $url\n"; #..............^^^^

        Which would have been caught if you had use strict & use warnings in your module.

        And would be far more obvious visually if you formatted your code with spaces in the right places:

        my( $sbn, $cost, $ur ) = @_;

        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.

        The start of some sanity?