Keywords: slug

Next: Scoped Operations Up: Basics Previous: Process Grid

## Contexts

In ScaLAPACK, and thus the BLACS, each process grid is enclosed in a context . Similarly, a context is associated with every global matrix in ScaLAPACK. The use of a context provides the ability to have separate ``universes'' of message passing. This means that a process grid can safely communicate even if other (possibly overlapping) process grids are also communicating. Thus, a context is a powerful mechanism for avoiding unintentional nondeterminism in message passing and provides support for the design of safe, modular software libraries. In MPI , this concept is referred to as a communicator.

A context partitions the communication space. A message sent from one context cannot be received in another context. The use of separate communication contexts by distinct libraries (or distinct library routine invocations) insulates communication internal to a specific library routine from external communication that may be going on within the user's program.

In most respects, we can use the terms process grid and context interchangeably. For example, we may say we perform an operation ``in context X'' or ``in process grid X''. The slight difference here is that the user may define two identical process grids (say, two process grids, both of which use processes 0, 1, and 2), but each will be enclosed in its own context, so that they are distinct in operation, even though they are indistinguishable from a process grid standpoint.

Another example of the use of context might be to define a normal two-dimensional process grid within which most computation takes place. However, in certain portions of the code it may be more convenient to access the processes as a one-dimensional process grid, whereas at other times we may wish, for instance, to share information among nearest neighbors. In such cases, we will want each process to have access to three contexts: the two-dimensional process grid, the one-dimensional process grid, and a small process grid that contains the process and its nearest neighbors.

Therefore, we see that context allows us to

- create arbitrary groups of processes,
- create an indeterminate number of overlapping and/or disjoint process grids, and
- isolate the process grid so that they do not interfere with each other.

The BLACS has two process grid creation routines, `BLACS_GRIDINIT` and `BLACS_GRIDMAP`, that create a process grid and its enclosing context. These routines return context handles , which are simple integers, assigned by the BLACS to identify the context. Subsequent BLACS routines will be passed these handles, which allow the BLACS to determine from which context/process grid a routine is being called. The user should never alter or change these handles; they are opaque data objects that are only meaningful for the BLACS routines.

A defined context consumes resources. It is therefore advisable to release contexts when they are no longer needed. This release is done via the routine `BLACS_GRIDEXIT` . When the entire BLACS system is shut down (via a call to `BLACS_EXIT` ), all outstanding contexts are automatically freed. Further details about these routines can be found in Appendix D.3.

Next: Scoped Operations Up: Basics Previous: Process Grid