From: Josh Guffin <guffin@purdue.edu>
Newsgroups: comp.parallel.mpi
Subject: Re: timing for Wait(all|any)
Date: Thu, 8 Jul 1999 08:47:39 -0500
Organization: Purdue University
Message-Id: <Pine.SOL.3.96.990708083041.15066A-100000@herald.cc.purdue.edu>
References: <Pine.LNX.4.10.9907080046420.3782-100000@krispc6.physik.uni-karlsruhe.de>
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
In-Reply-To: <Pine.LNX.4.10.9907080046420.3782-100000@krispc6.physik.uni-karlsruhe.de>
Xref: ukc comp.parallel.mpi:5304


You may want to try simply using blocking receives. Try this...

//c version
int numprocs, numprocsLeft;
int myBuffer
MPI_Comm_size(MPI_COMM_WORLD,numprocs);
numprocsLeft = numprocs - 1;

while(numprocsLeft) {
    MPI_Recv(&myBuffer,1,MPI_INTEGER,MPI_ANY_SOURCE,
             MPI_ANY_TAG,MPI_COMM_WORLD,&status);
    numprocsLeft--;
}

This will accept receives from any source, while numprocsLeft is not
0.  If you want to only accept one from each source, add the following
line between the Receive call and the decrement of numprocsLeft:

if(status.MPI_TAG) 

Have the slaves send a tag of 1 on their first message, and a zero on
all following messages.

c	FORTRAN VERSION
c
	integer numprocs,numprocsLeft,mybuffer
c
	call MPI_COMM_SIZE(MPI_COMM_WORLD,numprocs,ierr)
	numprocsLeft = numprocs - 1
c
 13	continue
	call MPI_RECV(mybuffer,1,MPI_INTEGER,MPI_ANY_SOURCE,
     *  MPI_ANY_TAG,MPI_COMM_WORLD,status,ierr)
	numprocsLeft = numprocsLeft - 1
	if (numprocsLeft .ne. 0) then
	goto 13
	end if
c

In fortran the test for a zero tag would look like this:
c
	if (status(MPI_TAG) .ne. 0) then
	numprocsLeft = numprocsLeft - 1
	end if
c

Hope this helps

Josh

On Thu, 8 Jul 1999, Johannes Zellner wrote:

> 
> recently I tryed a one-master - multiple-servers program.
> 
> The master sends jobs to the servers (Send) and sets up (Irecv)'s
> for each server. Then it goes to a (Waitany) and if this returns
> does another (Send)/(Irecv) for the particular Waitany's Request.source().
> 
> As the server jobs take quite a while compared to the master-server
> traffic, I supposed my master to eat almost no cpu.
> 
> But: running this on a single machine with for example `-np 3'
>      and each process gets about 33% cpu, also the master.
>      what's going on there? (How is the Wait stuff implemented)
> 
> Or: HOWTO program a smart master ?
> 
> Any hints would be much appreciated.
> 
> --
>    Johannes
> 
> 
> 

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
= Josh Guffin                                 guffin@purdue.edu =
= Purdue U. HEP - TASK E           expert.cc.purdue.edu/~guffin =
=                   #include <std/disclaimer>                   =
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=     

