Subject: mpi-context; MPI_ATTR_KEY_NULL proposal

From: L J Clarke <[email-masked]>
Date: Wed, 12 Jan 94 17:29:41 GMT

Dear All

I like to propose a very small addition to the cache section of our
chapter.  Colleague here just wrote the cache calls, and suggested this. 

Proposal
--------

Introduce the constant MPI_ATTR_KEY_NULL defined as an attriubte key
value which is legal, cannot be returned by MPI_ATTR_GET_KEY, and
against which no attribute may be stored. 

MPI_ATTR_GET_VALUE(comm, MPI_ATTR_KEY_NULL, attribute_val, found)

will always return found = false (provided comm is valid).

Rationale
---------

This simplifies writing libraries using the cache capability, allows
for better software practice by easier detection of non-initialised
library and encapsulation of library initialisation code where this is
shared across multiple library procedures.

With this proposal we can write code like the below.  before we would
simply have to have the initialisation code in the top of every lib
routine or call the lib init routine every time a lib routine is called. 
The addition to the drafts costs us next to nothing. 

static void lib_init(MPI_Comm);

static int key = MPI_ATTR_KEY_NULL;

void lib_call(MPI_Comm usr_comm, ...)
{
  int   *found;
  state *state;
  MPI_Comm lib_comm;

  MPI_Attr_get_value(usr_comm, key, &state, &found);
  if (! found)
    lib_init(usr_comm);

  lib_comm = state->comm;

}

lib_init(MPI_Comm usr_comm)
{
  lib_state *state;

  if (key == MPI_ATTR_KEY_NULL)
    MPI_Attr_get_key(lib_copy, lib_delete, &key, NULL);

  state = lib_alloc()

  MPI_Comm_dup(usr_comm, &state->comm)

  MPI_Attr_put_value(usr_comm, key, state)

}

Comments?

Best Wishes
Lyndon

         /--------------------------------------------------------\
    e||) | Lyndon J Clarke    Edinburgh Parallel Computing Centre | e||) 
    c||c | Tel: 031 650 5021  Email: [email-masked]  | c||c 
         \--------------------------------------------------------/

---

From: [email-masked] (James Cownie)
Date: Fri, 14 Jan 1994 17:04:31 +0000

You propose to add a pre-defined "NULL" value for the key, which is
never found by get_attr_value.

I suppose this is OK, but it doesn't really seem necessary. 
I could write your code like this (at the cost of one extra static
variable). 

static int initialised = FALSE;
static int key         = MPI_ATTR_KEY_NULL;

  if (! initialised)
    lib_init(usr_comm);

  MPI_Attr_get_value(usr_comm, key, &state, &found);   /* We KNOW this must succeeed */

  lib_comm = state->comm;
  /* And use the communicator... */
}

static void lib_init(MPI_Comm usr_comm)
{
  lib_state *state;

  if (initialised)
	return;      /* Or abort ? */

  initialised = TRUE;

  state = lib_alloc()

I find this clearer, and it requires no changes to what we have now.

Alternatively we could define a value MPI_ATTR_KEY_NULL as you require
(in fact it's probably sensible to do this). But your code still has a
BUG !

  /* At this point state will not be set if we executed the init path */
  lib_comm = state->comm;
}

The correct way to write it is explicitly to test the key, 

	

  /* At this point state will not be set if we executed the init path */
  lib_comm = state->comm;
}

I think I was objecting to your example, (and rationale, which I don't
believe), rather than the enhancement. What it buys is being able to
test for initialisation of a key without having to hold that bit of
information elsewhere, that's all. But that's probably worthwhile !

-- Jim 
James Cownie 
Meiko Limited			Meiko Inc.
650 Aztec West			Reservoir Place
Bristol BS12 4SD		1601 Trapelo Road
England				Waltham
				MA 02154

Phone : +44 454 616171		+1 617 890 7676
FAX   : +44 454 618188		+1 617 890 5042
E-Mail: [email-masked]   or    [email-masked]