Newsgroups: comp.parallel.pvm
From: bmanchek@ens-lyon.fr (Bob Manchek)
Subject: Re: pvm and fork()
Organization: Ecole Normale Superieure de Lyon
Date: 27 Oct 1994 11:59:40 GMT
Message-ID: <38o4nc$djg@cri.ens-lyon.fr>

In article a1t@harbinger.cc.monash.edu.au, ivan@nella28.cc.monash.edu.au (Ivan Rayner) writes:
> I would like a process to fork() and the child process to then be
> assigned a new pvm tid.  Is this possible?  Executing pvm_mytid in a
> forked process gives me the same tid as the parent (as one might
> expect).  Is there a way around this problem, or do I have to take a
> different approach, ie. is pvm_spawn the only way to create a new pvm
> task?
> 
> (Yes, I realise that I am using pvm in a way that was not quite intended)
> 
> Ivan
> -- 
> ________________________________________________________________________
> Ivan Rayner                                ivan@nellads.cc.monash.edu.au

You can do that.  There's no "official" way, so you have to know the trick.
After calling fork(), the parent will be the same PVM task.  Before it
does anything else, the child should call pvmendtask().  This disconnects
libpvm from the pvmd and cleans up.  The next pvm_*() call in the child
will reconnect it as a new task.

One side effect is that the child task is "anonymous", i.e. not spawned by
PVM.  So, it won't inherit output and trace collection.

Here's a small program I just wrote to test it:
#include <stdio.h>
#include <pvm3.h>

main(argc, argv)
	int argc;
	char **argv;
{
	int i, j;

	i = pvm_mytid();
	fprintf(stderr, "i'm the task %x\n", i);

	if (fork()) {
		pvm_recv(-1, -1);
		pvm_bufinfo(pvm_getrbuf(), (int *)0, (int *)0, &i);
		fprintf(stderr, "i the parent got a message from %x\n", i);

	} else {
		pvmendtask();
		j = pvm_mytid();
		fprintf(stderr, "i'm the child %x\n", j);
		pvm_packf("%+", PvmDataDefault);
		pvm_send(i, 0);
	}
	pvm_exit();
	exit(0);
}

b
---
/ Robert Manchek                University of Tennessee     /
/                               Computer Science Department /
/ (615)974-8295                 Ayres Hall #104             /
/ manchek@CS.UTK.EDU.           Knoxville TN  37996-1301    /
/     http://www.netlib.org/utk/people/BobManchek.html      /



