Skip to content

Supporting multiple SHMEM initialize/finalize calls #263

Description

@minsii

Goal

Allowing the user program to initialize and finalize SHMEM multiple times in order to support the scenario where SHMEM is used as the communication runtime of other libraries.

Problem Description

Current SHMEM spec defines that (1) multiple calls to shmem_init|shmem_init_thread within a program result in undefined behavior, and (2)shmem_finalize must be the last OpenSHMEM library call encountered in the OpenSHMEM portion of a program.

The above semantics allows the program to have at most one SHMEM portion, and interleaving calls to init or finalize become illegal. Thus, SHMEM is not able to be used as the communication runtime for multiple libraries. The following two examples show typical usages of init/finalize in this scenario, both of them are prohibited in current spec (FOO and BAR can be either a library or the main program).

Example-1

FOO_init();  // internally calls shmem_init
BAR_init(); // internally calls shmem_init
/* computation */
FOO_finalize(); // internally calls shmem_finalize
BAR_finalize(); // internally calls shmem_finalize

Example-2

FOO_init();  // internally calls shmem_init
/* computation 1 */
FOO_finalize(); // internally calls shmem_finalize
BAR_init(); // internally calls shmem_init
/* computation 2 */
BAR_finalize(); // internally calls shmem_finalize

Proposed Solution

Change in specification

  1. Multiple OpenSHMEM portions can exist within a program. An OpenSHMEM portion begins with a call to shmem_init|shmem_init_thread call, and ends with a call toshmem_finalize.
  2. The first shmem_init|shmem_init_thread call of an OpenSHMEM portion allocates and initializes resources for OpenSHMEM communication; the last shmem_finalize call of the same portion releases all resources initialized in this portion.
  3. Calling shmem_init|shmem_init_thread more than once within a program is permitted. However, calling init, init, finalize, finalize in a program will only initialize a single OpenSHMEM portion, even if the calls are made by different threads.
  4. In an OpenSHMEM portion, a subsequent call to shmem_init_thread|shmem_init has no subsequent effect. The thread level cannot be changed after initialization.
  5. The provided parameter of shmem_init_thread|shmem_query_thread returns the thread level initialized in the current OpenSHMEM portion.

Possible implementation

  1. The OpenSHMEM runtime may maintain an internal refcount global variable, which is increased at every shmem_init|shmem_init_thread call, and decreased at every shmem_finalize call.
  2. The resource is allocated and initialization at a shmem_init|shmem_init_thread call only if refcount==0; the resource is released at a shmem_finalize call only if refcount==0.

Requirement to user

  1. The user of OpenSHMEM is responsible to ensure that the same amount of init and finalize calls are made within a program. For instance, calling init, init, finalize may cause unreleased resource in an OpenSHMEM portion, and subsequent calls to OpenSHMEM (except the call to shmem_finalize) result in undefined behavior.

Current Progress

  • Implementing the proposed solution in an OpenSHMEM implementation.
  • Preparing changed specification.

This issue is separated from ticket #243 . See past discussion at #243.

Metadata

Metadata

Assignees

Labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions