Newsgroups: comp.parallel.pvm
From: Jonathan King <nobody@nowhere.else>
Subject: Re: Lost logging on pvml.0 /
Organization: Hewlett-Packard Co.
Date: Wed, 14 Aug 1996 13:28:11 -0700
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Message-ID: <321236DB.3B3@nowhere.else>

Laurent Rosenfeld wrote:
> 
> Hi everyone,,
> 
> I am using PVM on a linux box to develop a C application which should
> eventually run on a workstation network, and I ran into two problems:
> 
> 1.  At one point during my development work, PVM stopped writing anything
>     into the pvml.0 file in /tmp/ (except one line saying "ready" after
>     some numbers).  This makes debugging very tedious, because
>     the only way to figure out what the spawned tasks are doing is by sending
>     messages to the parent.  At one point, PVM wrote again into this file the
>     printf statements of the spawned tasks, but just once, and then stopped
>     again.

Weird.  If you are using pvm_spawn, you can use pvm_catchout to redirect
child output to the parent's terminal.  However, if you're using fork(),
I don't think that will work.  Maybe just have each task open a (unique)
file and write output there?  You lose synchronization, but I've never
found the log file to be particularly... helpful... with ordering
output.

> 2.  The program on which I am working follows a master/slave paradigm. One
>     master spawns five slaves. The problem is that, in order to perform
>     their work, the slaves must fork and create children (I have to use fork,
>     rather than pvm_spawning subtasks, because the children must use shared
>     memory segments common to themselves and the slave which created
>     them); forking itself appears to be working fine, but I want the
>     children of the slaves to be able to receive messages
>     from the parent/master or from other tasks. It seems that children can't
>     pvm_recv (or pcm_send, for that matter) on the same port as their parent
>     slave, although I have used special msgtags depending on whether the
>     message is sent to the parent slave or to a child subtask.
> 
>     Can anyone confirm that this is impossible, or tell me how this can
>     be done ?

It can be done, but after forking the child, the parent and child have
the same tid, which confuses pvm.  However, by immediately disconnecting
the child from pvm, and reconnecting, the child is assigned its own tid,
and communication can resume.  Here's a function that does just that. 
Credit Robert Mancheck, who posted this a long time ago.


/* begin pvm_fork.c */

int pvm_fork(cpid)
int *cpid;              /* returns child pid if nonnull */
{
  int ptid;                       /* tid of parent */
  int tid;                        /* tid to return */
  int pid;                        /* pid of child */
  int sbf, rbf;

  sbf = pvm_setsbuf(0);
  rbf = pvm_setrbuf(0);

  if ((ptid = pvm_mytid()) < 0)
    {
      tid = ptid;
      goto done;
    }

  if (pid = fork()) {             /* parent */
    if (pid == -1) {
      tid = PvmOutOfRes;
      goto done;
    }

    tid = pvm_recv(-1, MSG_FORK);
    if (tid < 0)
      goto done;
    tid = -1;
    pvm_upkint(&tid, 1, 1);

    if (cpid)
      *cpid = pid;

  } else {                                /* child */
    pvmendtask();
    tid = pvm_mytid();
    pvm_initsend(PvmDataRaw);
    pvm_pkint(&tid, 1, 1);
    pvm_send(ptid, MSG_FORK);
    tid = 0;
  }

 done:
  if (sbf = pvm_setsbuf(sbf))
    pvm_freebuf(sbf);
  if (rbf = pvm_setrbuf(rbf))
    pvm_freebuf(rbf);
  return tid;
}

/* end pvm_fork.c */

Good luck.
Jon King

#######################################################
# Jonathan B. King        kingjo@research.cs.orst.edu #
# M.S. Student in C.S.    jking@cv.hp.com             #
#                                                     #
# Replying to this address will not work.  Please use #
#   one of the above email addresses to contact me.   #
#                                                     #
#              My opinions are my own.                #
#######################################################

