forked from openshmem-org/specification
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request openshmem-org#43 from manjugv/ticket-218
Thread Safety Proposal (RM Ticket openshmem-org#218)
- Loading branch information
Showing
9 changed files
with
213 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
\apisummary{ | ||
Initializes the OpenSHMEM library, similar to \FUNC{shmem\_init}, and performs any | ||
initialization required for supporting the provided thread level. | ||
} | ||
|
||
\begin{apidefinition} | ||
|
||
\begin{Csynopsis} | ||
int shmem_init_thread(int requested, int *provided); | ||
\end{Csynopsis} | ||
|
||
\begin{apiarguments} | ||
\apiargument{IN}{requested}{The thread level support requested by the user.} | ||
\apiargument{OUT}{provided}{The thread level support provided by the \openshmem implementation.} | ||
\end{apiarguments} | ||
|
||
\apidescription{ | ||
\FUNC{shmem\_init\_thread} initializes the \openshmem library in the same way as | ||
\FUNC{shmem\_init}. In addition, \FUNC{shmem\_init\_thread} also performs | ||
the initialization required for supporting the provided thread level. | ||
The argument \VAR{requested} is used to specify the desired level of | ||
thread support. The argument \VAR{provided} returns the support level | ||
provided by the library. The allowed values for \VAR{provided} and | ||
\VAR{requested} are \CONST{SHMEM\_THREAD\_SINGLE}, \CONST{SHMEM\_THREAD\_FUNNELED}, | ||
\CONST{SHMEM\_THREAD\_SERIALIZED}, or \CONST{SHMEM\_THREAD\_MULTIPLE}. | ||
|
||
An \openshmem program is initialized either by \FUNC{shmem\_init} or \FUNC{shmem\_init\_thread}. | ||
Similar to \FUNC{shmem\_init}, the \FUNC{shmem\_init\_thread} routine may not | ||
be called multiple times in an \openshmem program. If the call to \FUNC{shmem\_init\_thread} | ||
is unsuccessful in allocating and initializing resources for the | ||
\openshmem library, then the behavior of any subsequent call | ||
to the \openshmem library is undefined. | ||
} | ||
|
||
\apireturnvalues{ | ||
\FUNC{shmem\_init\_thread} returns 0 upon success; otherwise, it returns a | ||
non-zero value. | ||
} | ||
|
||
\apinotes{ | ||
The \openshmem library can be initialized either by \FUNC{shmem\_init} | ||
or \FUNC{shmem\_init\_thread}. If the \openshmem library is initialized | ||
by \FUNC{shmem\_init}, the library implementation can choose to | ||
support one of the defined thread levels. | ||
} | ||
|
||
\end{apidefinition} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
\apisummary{ | ||
Returns the level of thread support provided by the library. | ||
} | ||
|
||
\begin{apidefinition} | ||
|
||
\begin{Csynopsis} | ||
void shmem_query_thread(int *provided); | ||
\end{Csynopsis} | ||
|
||
\begin{apiarguments} | ||
\apiargument{OUT}{provided}{The thread level support provided by the \openshmem implementation.} | ||
\end{apiarguments} | ||
|
||
\apidescription{ | ||
The \FUNC{shmem\_query\_thread} call returns the level of thread support | ||
currently being provided. The value returned will be same as \VAR{provided} | ||
returned in the \FUNC{shmem\_init\_thread}, if the \openshmem library was | ||
initialized by \FUNC{shmem\_init\_thread}. If the library was initialized by | ||
\FUNC{shmem\_init}, the implementation can choose to provide one of the defined | ||
thread levels, and \FUNC{shmem\_query\_thread} returns this thread level. | ||
} | ||
|
||
\apireturnvalues{ | ||
None. | ||
} | ||
|
||
\apinotes{ | ||
None. | ||
} | ||
\end{apidefinition} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
This section specifies the interaction between \openshmem interfaces and the | ||
user threads, and also describes the routines that can be used for initializing and | ||
querying the thread environment. There are four levels of threading supported by | ||
the \openshmem implementation. | ||
|
||
\begin{itemize} | ||
\item {\bf \CONST{SHMEM\_THREAD\_SINGLE}} The \openshmem program may not be multithreaded. | ||
|
||
\item {\bf \CONST{SHMEM\_THREAD\_FUNNELED}} | ||
The \openshmem program may be multithreaded. However, the program must ensure | ||
that only the main thread invokes the \openshmem interfaces. The main thread | ||
is the thread that invokes either \FUNC{shmem\_init} or \FUNC{shmem\_init\_thread}. | ||
|
||
\item {\bf \CONST{SHMEM\_THREAD\_SERIALIZED}} | ||
The \openshmem program may be multithreaded. However, the program must ensure | ||
that the \openshmem interfaces are not invoked concurrently by multiple threads. | ||
|
||
\item {\bf \CONST{SHMEM\_THREAD\_MULTIPLE}} | ||
The \openshmem program may be multithreaded and any thread may invoke the \openshmem | ||
interfaces. | ||
\end{itemize} | ||
|
||
\hspace{-15pt} | ||
{\bf Semantics} | ||
|
||
\begin{itemize} | ||
\item | ||
In \CONST{SHMEM\_THREAD\_FUNNELED}, \CONST{SHMEM\_THREAD\_SERIALIZED}, and | ||
\CONST{SHMEM\_THREAD\_MULTIPLE} thread levels, the \FUNC{shmem\_init} and | ||
\FUNC{shmem\_finalize} calls may only be invoked by the same thread. | ||
|
||
\item | ||
Any \openshmem operation initiated by a thread is considered an action of the | ||
\ac{PE} as a whole. The symmetric heap and symmetric variables scope are not | ||
impacted by multiple threads invoking the \openshmem interfaces, i.e., | ||
each \ac{PE} has a single symmetric data segment and symmetric heap that is shared by | ||
all threads within that \ac{PE}. For example, a thread invoking a memory allocation | ||
routine such as \FUNC{shmem\_malloc} allocates memory that is accessible by | ||
all threads of the \ac{PE}. The requirement that the same symmetric heap operations | ||
must be executed by all \acp{PE} in the same order also applies in a threaded | ||
environment. Similarly, the completion of collective operations is not impacted | ||
by multiple threads. For example, \FUNC{shmem\_barrier\_all} is completed when | ||
all \acp{PE} enter and exit the \FUNC{shmem\_barrier\_all} call, even though | ||
only one thread in the \ac{PE} is participating in the collective call. | ||
|
||
\item Blocking \openshmem calls will only block the calling thread, allowing | ||
other threads, if available, to continue the execution. The calling thread will | ||
be blocked until the event on which it is waiting occurs. Once the blocked communication is | ||
completed, the thread is ready for continuing the execution. A blocked thread | ||
will not prevent progress of other threads on the same \ac{PE}, and will not | ||
prevent them from executing other \openshmem calls when the thread level permits. | ||
Also, a blocked thread will not prevent the progress of \openshmem calls on other \acp{PE}. | ||
|
||
\item In the \CONST{SHMEM\_THREAD\_MULTIPLE} thread level, all \openshmem calls are thread-safe, | ||
i.e., two concurrently running threads may make \openshmem calls and the outcome | ||
will be as if the calls executed in some order, even if their execution is interleaved. | ||
|
||
\item In the \CONST{SHMEM\_THREAD\_SERIALIZED} and \CONST{SHMEM\_THREAD\_MULTIPLE} thread levels, | ||
if multiple threads call the collective calls, it is the programmer's responsibility | ||
to ensure the correct ordering of collective calls, including the symmetric | ||
heap management functions. | ||
|
||
\end{itemize} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters