Newsgroups: comp.parallel.pvm
From: adilger@enel.ucalgary.ca (Andreas Dilger)
Subject: Re: pvm_nrecv fails to get large messages
Organization: ECE Department, U. of Calgary, Calgary, Alberta, Canada
Date: 11 Dec 1995 20:40:21 GMT
Message-ID: <4ai4vl$s1s@ds2.acs.ucalgary.ca>

In article <Pine.SUN.3.91.951211104145.11106B-100000@silver.cs.umanitoba.ca>,
Thulasiraman Jeyaraman  <tram@silver.cs.umanitoba.ca> wrote:
>The above while loop does not guarantee that the master task waits for 
>all the slave tasks to send messages. pvm_nrecv returns bufid=0 when it 
>finds no outstanding messages. 
>
>Solution:
>
>   count = 0;
>   while (1) {
>     bufid = pvm_nrecv(-1, msgtag);
>     if (bufid == 0) continue;
>     if (bufid < 0) pvm_perror("master: recv");
>     else {
>	  pvm_upkint (&token,count,stride);   
>          printf("token=%d\n", token);
>	  count++;
>	  if (count == num_of_slave_tasks_spawned) break;
>     }
>   }

This amounts to busy waiting for the incoming messages.  Why not just use
the available functions?  As in:

for (i = 0; i < num_of_slave_tasks_spawned; i++)
{
  if ((bufid = pvm_recv(-1, msgtag)) < 0)
    pvm_perror("master: recv");
  else
  {
    pvm_upkint(&token, count, stride);
    printf("token = %d\n", token);
  }
}

If you want to ensure that you aren't stuct waiting here, you could also use
pvm_trecv() to time out after a reasonable amount of time.

Cheers, Andreas.
-- 
Andreas Dilger   University of Calgary  \"If a man ate a pound of pasta and
(403) 220-8792   Micronet Research Group \ a pound of antipasto, would they
Dept of Electrical & Computer Engineering \   cancel out, leaving him still
http://www-mddsp.enel.ucalgary.ca/People/adilger/       hungry?" -- Dogbert

