Skip to content

Commit 1169fce

Browse files
authored
Merge pull request #512 from jdinan/jdinan/multi-init
Add Multi-init/finalize Support
2 parents 3319c5a + f1b7c87 commit 1169fce

File tree

8 files changed

+100
-34
lines changed

8 files changed

+100
-34
lines changed

content/backmatter.tex

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,6 @@ \chapter{Undefined Behavior in OpenSHMEM}\label{sec:undefined}
143143
immediately upon an \openshmem call into the uninitialized library.
144144
\tabularnewline
145145
\hline
146-
Multiple calls to initialization routines & In an \openshmem program where
147-
the initialization routines \FUNC{shmem\_init} or \FUNC{shmem\_init\_thread}
148-
have already been called, any subsequent calls to these initialization routines
149-
result in undefined behavior.
150-
\tabularnewline
151-
\hline
152146
Specifying invalid \ac{PE} numbers & For \openshmem routines that accept a
153147
\ac{PE} number as an argument, if the \ac{PE} number is invalid for the
154148
team associated with the operation (either implicitly or explicitly), the
@@ -661,6 +655,11 @@ \section{Version 1.6}
661655
The following list describes the specific changes in \openshmem[1.6]:
662656
\begin{itemize}
663657
%
658+
\item Added support for initialization and finalization routines to be called
659+
multiple times, and added an initialization status query API
660+
\FUNC{shmem\_query\_initialized}.
661+
\ChangelogRef{subsec:shmem_init, subsec:shmem_finalize, subsec:shmem_query_initialized}%
662+
%
664663
\item Added interleaved block transfer APIs \FUNC{shmem\_ibget} and
665664
\FUNC{shmem\_ibput}.
666665
\ChangelogRef{subsec:shmem_ibget, subsec:shmem_ibput}%

content/execution_model.tex

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,15 @@
88

99
\ac{PE} execution is loosely coupled, relying on \openshmem operations to
1010
communicate and synchronize among executing \acp{PE}. The \openshmem phase in
11-
a program begins with a call to the initialization routine \FUNC{shmem\_init}
11+
a program begins with the first call to the initialization routine \FUNC{shmem\_init}
1212
or \FUNC{shmem\_init\_thread}, which must be performed before using any of the
1313
other \openshmem library routines.
14-
An \openshmem program concludes its use of the \openshmem library when all \acp{PE} call
14+
An \openshmem program concludes its use of the \openshmem library when all \acp{PE}
15+
make their final call to
1516
\FUNC{shmem\_finalize} or any \ac{PE} calls \FUNC{shmem\_global\_exit}.
16-
During a call to \FUNC{shmem\_finalize}, the \openshmem library must
17-
complete all pending communication and release all the resources associated to
18-
the library using an implicit collective synchronization across \acp{PE}.
19-
Calling any \openshmem routine before initialization or after
20-
\FUNC{shmem\_finalize} leads to undefined behavior. After finalization, a
21-
subsequent initialization call also leads to undefined behavior.
17+
During the last call to \FUNC{shmem\_finalize}, the \openshmem library synchronizes
18+
all \acp{PE}, completes all pending communication and releases all the resources
19+
associated to the library.
2220

2321
The \acp{PE} of the \openshmem program are identified by unique integers. The
2422
identifiers are integers assigned in a monotonically increasing manner from zero

content/shmem_finalize.tex

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,33 @@
1515
\end{apiarguments}
1616

1717
\apidescription{
18-
\FUNC{shmem\_finalize} is a collective operation that ends the \openshmem
19-
portion of a program previously initialized by \FUNC{shmem\_init} or \FUNC{shmem\_init\_thread} and
20-
releases all resources used by the \openshmem library. This collective
21-
operation requires all \acp{PE} to participate in the call. There is an
22-
implicit global barrier in \FUNC{shmem\_finalize} to ensure that pending
23-
communications are completed and that no resources are released until all
24-
\acp{PE} have entered \FUNC{shmem\_finalize}.
25-
This routine destroys all teams created by the \openshmem program.
18+
\FUNC{shmem\_finalize} ends the \openshmem
19+
portion of a program previously initialized by \FUNC{shmem\_init} or \FUNC{shmem\_init\_thread}.
20+
This is a collective
21+
operation that requires all \acp{PE} to participate in the call.
22+
23+
An \openshmem program may perform a series of matching
24+
initialization and finalization calls.
25+
The last call to \FUNC{shmem\_finalize} in this series
26+
releases all resources used by the \openshmem library.
27+
This call destroys all teams created by the \openshmem program.
2628
As a result, all shareable contexts are destroyed.
2729
The user is
2830
responsible for destroying all contexts with the
29-
\CONST{SHMEM\_CTX\_PRIVATE} option enabled prior to calling this routine;
31+
\CONST{SHMEM\_CTX\_PRIVATE} option enabled prior to this call;
3032
otherwise, the behavior is undefined.
31-
\FUNC{shmem\_finalize} must be
32-
the last \openshmem library call encountered in the \openshmem portion of a
33-
program. A call to \FUNC{shmem\_finalize} will release all resources
34-
initialized by a corresponding call to \FUNC{shmem\_init} or \FUNC{shmem\_init\_thread}. All processes
33+
34+
The last call to \FUNC{shmem\_finalize} performs an implicit global barrier
35+
to ensure that pending communications are completed and that no resources
36+
are released until all \acp{PE} have entered \FUNC{shmem\_finalize}. All
37+
other calls to \FUNC{shmem\_finalize} perform an operation semantically
38+
equivalent to \FUNC{shmem\_barrier\_all} and return without freeing any
39+
\openshmem resources.
40+
41+
The last call to \FUNC{shmem\_finalize} causes the \openshmem library
42+
to enter an uninitialized state. No further \openshmem calls may be
43+
made until an \openshmem initialization routine is called.
44+
All processes
3545
that represent the \acp{PE} will still exist after the
3646
call to \FUNC{shmem\_finalize} returns, but they will no longer have access
3747
to resources that have been released.
@@ -42,12 +52,19 @@
4252
}
4353

4454
\apinotes{
45-
\FUNC{shmem\_finalize} releases all resources used by the \openshmem library
55+
The last call to \FUNC{shmem\_finalize} releases all resources used by the \openshmem library
4656
including the symmetric memory heap and pointers initiated by
4757
\FUNC{shmem\_ptr}. This collective operation requires all \acp{PE} to
4858
participate in the call, not just a subset of the \acp{PE}. The
4959
non-\openshmem portion of a program may continue after a call to
5060
\FUNC{shmem\_finalize} by all \acp{PE}.
61+
62+
Calls to \FUNC{shmem\_finalize} that are not the last in a series of
63+
initialization and finalization calls do not free any \openshmem resources.
64+
Thus, teams, contexts, or symmetric memory allocations may be leaked until
65+
the final call to \FUNC{shmem\_finalize}. Applications that perform
66+
multiple initialization and finalization calls should free resources prior
67+
to calling \FUNC{shmem\_finalize} to avoid such leaks.
5168
}
5269

5370
\begin{apiexamples}

content/shmem_init.tex

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,15 @@
1818
library. It is a collective operation that all \acp{PE} must call before any
1919
other \openshmem routine may be called. At the end of the \openshmem program
2020
which it initialized, the call to \FUNC{shmem\_init} must be matched with a
21-
call to \FUNC{shmem\_finalize}. After the first call to \FUNC{shmem\_init}, a
22-
subsequent call to \FUNC{shmem\_init} or \FUNC{shmem\_init\_thread} in the
23-
same program results in undefined behavior.
21+
call to \FUNC{shmem\_finalize}.
22+
23+
The \FUNC{shmem\_init} and \FUNC{shmem\_init\_thread} initialization
24+
routines may be called multiple times within an \openshmem program. A
25+
corresponding call to \FUNC{shmem\_finalize} must be made for each call to
26+
an \openshmem initialization routine. The \openshmem library must not be
27+
finalized until after the last call to \FUNC{shmem\_finalize} and may be
28+
re-initialized with a subsequent call to an initialization routine.
29+
2430
}
2531

2632
\apireturnvalues{

content/shmem_init_thread.tex

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,19 @@
2424
\VAR{requested} are \CONST{SHMEM\_THREAD\_SINGLE}, \CONST{SHMEM\_THREAD\_FUNNELED},
2525
\CONST{SHMEM\_THREAD\_SERIALIZED}, and \CONST{SHMEM\_THREAD\_MULTIPLE}.
2626

27-
An \openshmem program is initialized either by \FUNC{shmem\_init} or \FUNC{shmem\_init\_thread}.
28-
Once an \openshmem library initialization call has been performed, a subsequent
29-
initialization call in the same program results in undefined behavior.
27+
The \FUNC{shmem\_init} and \FUNC{shmem\_init\_thread} initialization
28+
routines may be called multiple times within an \openshmem program. A
29+
corresponding call to \FUNC{shmem\_finalize} must be made for each call to
30+
an \openshmem initialization routine. The \openshmem library must not be
31+
finalized until after the last call to \FUNC{shmem\_finalize} and may be
32+
re-initialized with a subsequent call to an initialization routine.
33+
3034
If the call to \FUNC{shmem\_init\_thread}
3135
is unsuccessful in allocating and initializing resources for the
3236
\openshmem library, then the behavior of any subsequent call
3337
to the \openshmem library is undefined.
38+
39+
3440
}
3541

3642
\apireturnvalues{
@@ -43,6 +49,9 @@
4349
or \FUNC{shmem\_init\_thread}. If the \openshmem library is initialized
4450
by \FUNC{shmem\_init}, the library implementation can choose to
4551
support any one of the defined thread levels.
52+
53+
The \openshmem library may not be able to change the level of threading support
54+
provided after the first initialization call has been made.
4655
}
4756

4857
\end{apidefinition}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
\apisummary{
2+
Returns the initialized status of the \openshmem library.
3+
}
4+
5+
\begin{apidefinition}
6+
7+
\begin{Csynopsis}
8+
void @\FuncDecl{shmem\_query\_initialized}@(int *initialized);
9+
\end{Csynopsis}
10+
11+
\begin{apiarguments}
12+
\apiargument{OUT}{initialized}{Nonzero if the \openshmem library is in the initialized state. Zero otherwise.}
13+
\end{apiarguments}
14+
15+
\apidescription{
16+
The \FUNC{shmem\_query\_initialized} call returns the initialization status
17+
of the \openshmem library. If the application has called an \openshmem
18+
initialization routine and has not yet made the corresponding call to
19+
\FUNC{shmem\_finalize}, this routine returns nonzero. Otherwise, it returns
20+
zero.
21+
22+
This function may be called at any time, regardless of the thread safety
23+
level of the \openshmem library.
24+
}
25+
26+
\apireturnvalues{
27+
None.
28+
}
29+
30+
\end{apidefinition}

content/shmem_query_thread.tex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
initialized by \FUNC{shmem\_init\_thread}. If the library was initialized by
2020
\FUNC{shmem\_init}, the implementation can choose to provide any one of the defined
2121
thread levels, and \FUNC{shmem\_query\_thread} returns this thread level.
22+
23+
This function may be called at any time, regardless of the thread safety
24+
level of the \openshmem library.
2225
}
2326

2427
\apireturnvalues{

main_spec.tex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ \subsubsection{\textbf{SHMEM\_QUERY\_THREAD}}
9292
\label{subsec:shmem_query_thread}
9393
\input{content/shmem_query_thread}
9494

95+
\subsubsection{\textbf{SHMEM\_QUERY\_INITIALIZED}}
96+
\label{subsec:shmem_query_initialized}
97+
\input{content/shmem_query_initialized}
98+
9599

96100
\subsection{Memory Management Routines}
97101
\label{sec:memory_management}

0 commit comments

Comments
 (0)