next up previous contents index
Next: G3-Class Up: 16.2.5 Zipcode Calls Previous: Letter-Generating Primitives

Letter-Consuming Primitives

void g2_Send(ZIP_MAILER *mailer, char *letter, int p, int q);
Collective operations combine, broadcast   (fanout), and collapse (fanin) are defined and have been highly tuned for this class (see schematics in [Skjellum:90c]).

Combines and fanins are over arbitrary associative-commutative operators specified by (*comb_fn)(). Broadcasts share data of arbitrary length, assuming all participants know the source. Collapses combine information assuming all participants know the destination:

int error = 
    g2_combine(ZIP_MAILER *mailer, /* 2D grid mailer */
          void *buffer,      /* where result is accumulated */
          void (*comb_fn)(), /* operator for combine */
          int size           /* size of buffer items in bytes */
          int items);        /* number of buffer items */

    error = g2_fanout(ZIP_MAILER *mailer,
          void **data,             /* data/result */
          int *length,             /* data length */
          int orig_p, int orig_q); /* grid origin of data */

    error = g2_fanin(ZIP_MAILER *mailer,
          int dest_p, int dest_q,  /* destination on grid */
          void *buffer, void (*comb_fn)(), 
          int size, int nitems);
Shorthands provide direct access to row and column children mailers, tersely providing common communication patterns within the two-dimensional grid:

g2_row_combine(mailer, buffer, comb_fn, size, items);
g2_col_combine(mailer, buffer, comb_fn, size, items);

g2_row_fanout(mailer, &data, &length, orig_q);
g2_col_fanout(mailer, &data, &length, orig_p;
g2_row_fanin(mailer, dest_q, buffer, comb_fn, size, items);
g2_col_fanin(mailer, dest_p, buffer, comb_fn, size, items);
The row/column instructions above compile to G1-grid calls, since rows and columns of G2 mailers are implemented via G1 mailers. G2-Grid mailer creation:

ZIP_MAILER *mailer = g2_grid_open(int *P, int *Q, 
                                  ZIP_ADDRESSEES *addr);

Once a G2 grid mailer has been established, it is possible to derive subgrid mailers by a cooperative call between all the participants in the original g2_grid_open(). In normal applications, this will result in a set of additional mailers in the postmaster (usually host program) process, and one additional G2 grid mailer in each node process. This call allows subgrids to be aligned to the original grid in reasonably general ways, but requires a basic cartesian subgridding, in that each subgrid defined must be a rectangular collection of processes.

The postmaster of the original mailer (often the host process), initiates the subgrid open request as follows:

 /* array of pointer to subgrid mailers: */
 ZIP_MAILER **subgrid_mailers =
     g2_subgrid_open(ZIP_MAILER *mailer, 
              /* mailer already opened */
              /* for each (p,q) on original grid, 
                 marks its subgrid: */
     int (*select_fn)(int p, int q, void *extra),  
     void *select_extra;  /* extra data needed by select_fn() */
     int *nsubgrids);     /* the number of subgrids created   */
while each process in the original g2_grid_open() does a second, standard g2_grid_open():
    ZIP_MAILER *subgrid_mailer = g2_grid_open(&P, &Q, NULL);
Each subgrid so created has its own unique contexts of communication.

Finally, it is often necessary to determine the grid shape , as well as the current process's location on the grid , when using two-dimensional logical grids. Often this information is housed only in the mailer (though some applications may choose to duplicate this information). The following calls provide simple access to these four quantities.

int p,q, P, Q; ZIP_MAILER *mailer;

/* set variables (P,Q) to grid shape: */
void g2_PQ(ZIP_MAILER *mailer, int P, int Q);

/* set variables (p,q) to grid position: */
void g2_pq(ZIP_MAILER *mailer, int p, int q);

These are the preferred forms for accessing grid information from G2-Class mailers.

next up previous contents index
Next: G3-Class Up: 16.2.5 Zipcode Calls Previous: Letter-Generating Primitives

Guy Robinson
Wed Mar 1 10:19:35 EST 1995