Newsgroups: comp.parallel.mpi
From: marr@dcs.ed.ac.uk (Marcus Marr)
Subject: Cancelling Pending Messages
Organization: Computer Systems Group, The University of Edinburgh
Date: Thu, 4 Aug 1994 15:15:40 GMT
Message-ID: <MARR.94Aug4161541@carna.dcs.ed.ac.uk>


I have  a process which has a queue of messages which are all waiting
to be received.  The process is no longer interested in any of them,
so they could all be cancelled.

MPI_Cancel() can be used to cancel pending non-blocking communication
operations (send or receive), but as far as I know no counterpart
exists for blocking receives.

Effectively, the process needs to receive the message without parsing
the content.  Since the message is no longer relevant, no buffer space
should be needed, and neither the count nor the datatype should have
to be specified.  Ideally, a call of the form:

	MPI_Recv(NULL, 0, MPI_ANYTYPE, source, tag comm, status)

should work, as specifying NULL as the initial address of the receive
buffer should be sufficient information for MPI_Recv() to ignore the
message.

Unfortunately there is no mention in the MPI standard (March 31, 1994)
of the behaviour when buf==NULL, which could mean that the
implementation might return a buffer overflow error, a type mismatch
error, or even cause a segmentation fault.  The alternative is to:

	use MPI_Probe() and MPI_Get_count() to find the length of the
		message, using MPI_PACKED as the datatype (which
		matches anything), 
	allocate the buffer space, 
	use MPI_Irecv() to initiate a receive
	use MPI_Cancel() to cancel the receive
	use MPI_Wait() to wait for cancellation or completion.

This seems excessive for both the programmer and the machine, and it
is likely that an implementation of MPI_Recv with the above behaviour
would be more efficient than the stated alternative on many (all?)
platforms.  The cost would be an extra condition test (buf==NULL) for
every MPI_Recv() call.

Similarly, the behaviour of:

	 MPI_Send(NULL, 0, MPI_ANYTYPE, dest, tag, comm)

is not specified, although I would assume that no implementations
would complain.

What I would like to know is:

	What is the behaviour defined in the standard?

	If the behaviour is undefined, is the suggested behaviour
		described above a sensible definition?

	How would the above calls be handled in the current batch of
		MPI implementations?



Rationale
=========

As a simple example, two processes can be used to form a search
pipeline where the first stage enumerates all elements of the search
space, and the second stage filters out all those elements that do not
match some specified selection criteria.  The pipeline should stop
when the second process has found, for example, 10 elements satisfying
the search criteria.  This can be done by sending a kill message to
the first process, which the first process polls for before sending
each element of the search space.

There may be one or more elements already sent by the first process
but still waiting to be received by the second process after the kill
message has been sent, so it would be good house-keeping practice for
the second process to discard all the un-received messages.


Marcus Marr,
Department of Computer Science,
University of Edinburgh




