Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Parallel::ForkManager pass object from child to parent

by david2008 (Scribe)
on Feb 05, 2013 at 09:41 UTC ( #1017092=perlquestion: print w/replies, xml ) Need Help??
david2008 has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

I have the following question.
I have a computation which i want to make in parallel.
For this purpose i want to fork a couple of childs and make with them the computation.
The result of each child is an object which i want to return the parent.
The parent will then combine the computation.
My question is how do i return an object from the child to the parent.

In the documentation it is written:
"Each child process may optionally send 1 data structure back to the parent. By data structure, we mean a reference to a string, hash or array. The contents of the data structure are written out to temporary files on disc using the Storable modules' store() method."

So i don't see a way to pass an object back.
On the other hand, in perl all the objects are plain data structures which are blessed.
So can't i just retrieve the structure and bless it with the package name ? Is there something problematic with this?

  • Comment on Parallel::ForkManager pass object from child to parent

Replies are listed 'Best First'.
Re: Parallel::ForkManager pass object from child to parent
by moritz (Cardinal) on Feb 05, 2013 at 09:45 UTC
Re: Parallel::ForkManager pass object from child to parent
by sundialsvc4 (Abbot) on Feb 05, 2013 at 14:04 UTC

    Clearly, you should make sure before going too far that you do have the computing resources necessary to allow the computations to really occur “in parallel” on the hardware, and that you do not pay an advantage-overwhelming cost with the disk I/O.   Consider using some kind of thread-safe but in-memory queue to send results back ... perhaps sending them, not to the parent, but to a data-collecting child who does nothing else but listen on that queue.   (Yes, you are right about blessing:   it simply flips a bit and associates the object with a package-name.)   But first and foremost ... set up a little-bitty test case as a proof of concept to make sure that your idea is actually worth developing to a full-on implementation.   In too-many cases, although certainly not all of them, “fancy-pants multithreading” can actually run slower or, almost as embarrassing, no faster.   Stick your toes in the water before putting on your bathing suit on this one.

    If it does work for you, Parallel::ForkManager is a very good tool.

Re: Parallel::ForkManager pass object from child to parent
by Anonymous Monk on Feb 05, 2013 at 09:49 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1017092]
Approved by moritz
and the rats come out to play...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2018-06-24 00:08 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.