Subject: some corrections to example

From: L J Clarke <[email-masked]>
Date: Tue, 13 Apr 93 10:58:49 BST

There were some silly mistakes in the example I sent out. Here I just
correct that.

Regards
Lyndon

Let me give a very simple example for class Simple in C, assuming that
object identifiers are expressed as type "void *" and group and
communicator handles are expressed also as type "long".  In practice we
may implement object identifiers as opaque entities, but it's simpler to
show this (void *) stuff here.  I omit all error checks and standard
speed optimisations as well.

#----------------------------------------
# Library fragment

void * Simple_contructor(long G)
{
  Simple_state *state Simple_alloc_state(); /* Class state memory allocator */

  state->communicator = mpi_create_group_communicator(G,
                                       MPI_NULL_CONTEXT,
                                    MPI_SECURE_CONTEXT);
  return (void *)state;
}

void Simple_destructor(void *id)
{
  Simple_state *state = (Simple_state *)id; /* Macros can be faster */

  mpi_delete_communicator(state->communicator);

  Simple_dealloc_state(state); /* Class state memory deallocator */

  return;
}

void Simple_maketea_double(void *id, double *data, int items)
{
  Simple_state *state = (Simple_state *)id; /* Macros can be faster */

  /* next line is just to show how easy it is to get at the communicator */
  long communicator   = state->communicator; 

  /* make "items" cups of double precision tea :-)

     with 
     communication 
     using
     communicator */

  return;
}

void Simple_maketea_float(void *id, float *data, int items)
{
  Simple_state *state = (Simple_state *)id; /* Macros can be faster */

  /* next line is just to show how easy it is to get at the communicator */
  long communicator   = state->communicator; 

  /* make "items" cups of single precision tea :-)

     with 
     communication 
     using
     communicator */

  return;
}

#
#----------------------------------------

#----------------------------------------
# User fragment

/* some decls */

void *simple_ga, *simple_gb, *simple_ha, *simple_hb;
double data[16];
float  fata[16];

/* stuff */

simple_ga = Simple_constructor(G);
if (in_H) {
  simple_ha = Simple_constructor(H);
  simple_maketea_double(simple_hb, data, 16);
  simple_maketea_float(simple_hb, fata, 16);
  simple_hb = Simple_constructor(H);
}
simple_maketea_float(simple_ga, fata, 16);
simple_gb = Simple_constructor(G);
simple_maketea_double(simple_gb, data, 7);

/* more stuff */

#
#----------------------------------------

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