Skip to content

Commit 7594121

Browse files
authored
Merge pull request #13211 from abouteiller/bugfix/env-thread-level-ignored
bugfix: Setting OMPI_MPI_THREAD_LEVEL to a value different than requested crashes
2 parents d9cccba + aff3afd commit 7594121

File tree

11 files changed

+388
-143
lines changed

11 files changed

+388
-143
lines changed

docs/man-openmpi/man3/MPI_Finalize.3.rst

Lines changed: 70 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ MPI_Finalize
55

66
.. include_body
77
8-
:ref:`MPI_Finalize` |mdash| Terminates MPI execution environment.
8+
:ref:`MPI_Finalize` |mdash| Terminates MPI world model.
99

1010
.. The following file was automatically generated
1111
.. include:: ./bindings/mpi_finalize.rst
@@ -18,56 +18,82 @@ OUTPUT PARAMETER
1818
DESCRIPTION
1919
-----------
2020

21-
This routine cleans up all MPI states. Once this routine is called, no
22-
MPI routine (not even MPI_Init) may be called, except for
23-
:ref:`MPI_Get_version`, :ref:`MPI_Initialized`, and :ref:`MPI_Finalized`. Unless there has
24-
been a call to :ref:`MPI_Abort`, you must ensure that all pending
25-
communications involving a process are complete before the process calls
26-
:ref:`MPI_Finalize`. If the call returns, each process may either continue
27-
local computations or exit without participating in further
28-
communication with other processes. At the moment when the last process
29-
calls :ref:`MPI_Finalize`, all pending sends must be matched by a receive, and
30-
all pending receives must be matched by a send.
31-
32-
:ref:`MPI_Finalize` is collective over all connected processes. If no processes
33-
were spawned, accepted, or connected, then this means it is collective
34-
over MPI_COMM_WORLD. Otherwise, it is collective over the union of all
35-
processes that have been and continue to be connected.
21+
This routine finalizes the MPI world model. If the MPI world model
22+
has been initialized in an MPI process, it *must* be finalized exactly
23+
once by invoking this routine during the lifetime of that MPI process.
24+
This is different than the MPI session model, which can be initialized
25+
and finalized multiple times in an MPI process. See
26+
:ref:`MPI_Session_init` and :ref:`MPI_Session_finalize`.
27+
28+
Unless there has been a call to :ref:`MPI_Abort`, you must
29+
ensure that all pending communications in the MPI world model
30+
involving a process are complete before the process calls
31+
:ref:`MPI_Finalize`. If the call returns, each process may either
32+
continue local computations or exit without participating in further
33+
communication with other processes in the MPI world model. At the
34+
moment when the last process calls :ref:`MPI_Finalize`, all pending
35+
sends in the MPI world model must be matched by a receive, and all
36+
pending receives in the MPI world model must be matched by a send.
37+
38+
See `MPI-5.0:11.4.1 <https://www.mpi-forum.org/>`_ for a list of MPI
39+
functionality that is available (e.g., even when the MPI
40+
world model has not yet initialized or has already been finalized).
41+
42+
:ref:`MPI_Finalize` is collective over all connected processes. If no
43+
processes were spawned, accepted, or connected, then this means it is
44+
collective over ``MPI_COMM_WORLD``. Otherwise, it is collective over
45+
the union of all processes that have been and continue to be
46+
connected.
3647

3748
NOTES
3849
-----
3950

40-
All processes must call this routine before exiting. All processes will
41-
still exist but may not make any further MPI calls. :ref:`MPI_Finalize`
42-
guarantees that all local actions required by communications the user
43-
has completed will, in fact, occur before it returns. However,
44-
:ref:`MPI_Finalize` guarantees nothing about pending communications that have
45-
not been completed; completion is ensured only by :ref:`MPI_Wait`, :ref:`MPI_Test`, or
46-
:ref:`MPI_Request_free` combined with some other verification of completion.
47-
48-
For example, a successful return from a blocking communication operation
49-
or from :ref:`MPI_Wait` or :ref:`MPI_Test` means that the communication is completed
50-
by the user and the buffer can be reused, but does not guarantee that
51-
the local process has no more work to do. Similarly, a successful return
52-
from :ref:`MPI_Request_free` with a request handle generated by an :ref:`MPI_Isend`
53-
nullifies the handle but does not guarantee that the operation has
54-
completed. The :ref:`MPI_Isend` is complete only when a matching receive has
55-
completed.
56-
57-
If you would like to cause actions to happen when a process finishes,
58-
attach an attribute to MPI_COMM_SELF with a callback function. Then,
59-
when :ref:`MPI_Finalize` is called, it will first execute the equivalent of an
60-
:ref:`MPI_Comm_free` on MPI_COMM_SELF. This will cause the delete callback
61-
function to be executed on all keys associated with MPI_COMM_SELF in an
62-
arbitrary order. If no key has been attached to MPI_COMM_SELF, then no
63-
callback is invoked. This freeing of MPI_COMM_SELF happens before any
64-
other parts of MPI are affected. Calling :ref:`MPI_Finalized` will thus return
65-
"false" in any of these callback functions. Once you have done this with
66-
MPI_COMM_SELF, the results of :ref:`MPI_Finalize` are not specified.
51+
The MPI session model is different than the MPI world model, and has
52+
different scopes of availability for MPI functionality. See
53+
:ref:`MPI_Session_init` and :ref:`MPI_Session_finalize`.
54+
55+
All processes that initialized the MPI world model must call this
56+
routine before exiting. All processes will still exist but may not
57+
make any further MPI calls in the MPI world model. :ref:`MPI_Finalize`
58+
guarantees that all local actions required by communications in the
59+
MPI world model that the user has completed will, in fact, occur
60+
before it returns. However, :ref:`MPI_Finalize` guarantees nothing
61+
about pending communications in the MPI world model that have not been
62+
completed; completion is ensured only by the :ref:`MPI_Wait` and
63+
:ref:`MPI_Test` variants, or :ref:`MPI_Request_free` combined with
64+
some other verification of completion.
65+
66+
For example, a successful return from a blocking communication
67+
operation or from one of the :ref:`MPI_Wait` or :ref:`MPI_Test`
68+
varients means that the communication is completed by the user and the
69+
buffer can be reused, but does not guarantee that the local process
70+
has no more work to do. Similarly, a successful return from
71+
:ref:`MPI_Request_free` with a request handle generated by an
72+
:ref:`MPI_Isend` nullifies the handle but does not guarantee that the
73+
operation has completed. The :ref:`MPI_Isend` is complete only when a
74+
matching receive has completed.
75+
76+
If you would like to cause actions to happen when a process finalizes the MPI
77+
world model, attach an attribute to ``MPI_COMM_SELF`` with a callback
78+
function. Then, when :ref:`MPI_Finalize` is called, it will first
79+
execute the equivalent of an :ref:`MPI_Comm_free` on
80+
``MPI_COMM_SELF``. This will cause the delete callback function to be
81+
executed on all keys associated with ``MPI_COMM_SELF`` in an arbitrary
82+
order. If no key has been attached to ``MPI_COMM_SELF``, then no
83+
callback is invoked. This freeing of ``MPI_COMM_SELF`` happens before
84+
any other parts of the MPI world model are affected. Calling
85+
:ref:`MPI_Finalized` will thus return ``false`` in any of these
86+
callback functions. Once you have done this with ``MPI_COMM_SELF``,
87+
the results of :ref:`MPI_Finalize` are not specified.
6788

6889
ERRORS
6990
------
7091

7192
.. include:: ./ERRORS.rst
7293

73-
.. seealso:: :ref:`MPI_Init`
94+
.. seealso::
95+
* :ref:`MPI_Finalized`
96+
* :ref:`MPI_Init`
97+
* :ref:`MPI_Initialized`
98+
* :ref:`MPI_Session_init`
99+
* :ref:`MPI_Session_finalize`

docs/man-openmpi/man3/MPI_Finalized.3.rst

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,39 @@ MPI_Finalized
55

66
.. include_body
77
8-
:ref:`MPI_Finalized` |mdash| Checks whether MPI has been finalized
8+
:ref:`MPI_Finalized` |mdash| Checks whether the MPI world model has been finalized
99

1010
.. The following file was automatically generated
1111
.. include:: ./bindings/mpi_finalized.rst
1212

1313
OUTPUT PARAMETER
1414
----------------
1515

16-
* ``flag`` : True if MPI was finalized, and false otherwise (logical).
16+
* ``flag`` : True if the MPI world model was finalized, and false
17+
otherwise (logical).
1718
* ``ierror`` : Fortran only: Error status (integer).
1819

1920
DESCRIPTION
2021
-----------
2122

22-
This routine may be used to determine whether MPI has been finalized. It
23-
is one of a small number of routines that may be called before MPI is
24-
initialized and after MPI has been finalized (:ref:`MPI_Initialized` is
25-
another).
23+
This routine may be used to determine whether the MPI world model has
24+
been finalized. A different routine |mdash| :ref:`MPI_Initialized`
25+
|mdash| is used to indicate whether the MPI world model has been
26+
initialized.
27+
28+
See `MPI-5.0:11.4.1 <https://www.mpi-forum.org/>`_ for a list of MPI
29+
functionality that is available (e.g., even when the MPI
30+
world model has not yet initialized or has already been finalized).
2631

2732
ERRORS
2833
------
2934

3035
.. include:: ./ERRORS.rst
3136

32-
.. seealso:: :ref:`MPI_Init`
37+
.. seealso::
38+
* :ref:`MPI_Init`
39+
* :ref:`MPI_Init_thread`
40+
* :ref:`MPI_Finalize`
41+
* :ref:`MPI_Finalized`
42+
* :ref:`MPI_Session_init`
43+
* :ref:`MPI_Session_finalize`

docs/man-openmpi/man3/MPI_Init.3.rst

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ MPI_Init
66

77
.. include_body
88
9-
:ref:`MPI_Init` |mdash| Initializes the MPI execution environment
9+
:ref:`MPI_Init` |mdash| Initializes the MPI world model
1010

1111
.. The following file was automatically generated
1212
.. include:: ./bindings/mpi_init.rst
@@ -23,35 +23,53 @@ OUTPUT PARAMETER
2323
DESCRIPTION
2424
-----------
2525

26-
This routine, or :ref:`MPI_Init_thread`, must be called before most other MPI
27-
routines are called. There are a small number of errors, such as
28-
:ref:`MPI_Initialized` and :ref:`MPI_Finalized`. MPI can be initialized at most once;
29-
subsequent calls to :ref:`MPI_Init` or :ref:`MPI_Init_thread` are erroneous.
26+
This routine, or :ref:`MPI_Init_thread`, initializes the MPI world
27+
model. Either of these routines must be called before MPI
28+
communication routines are called within the MPI world model. The MPI
29+
world model can be initialized at most exactly once in the lifetime of
30+
an MPI process. This is different than the MPI session model, which
31+
can be initialized and finalized multiple times in an MPI process.
32+
See :ref:`MPI_Session_init` and :ref:`MPI_Session_finalize`.
3033

31-
All MPI programs must contain a call to :ref:`MPI_Init` or :ref:`MPI_Init_thread`.
32-
Open MPI accepts the C *argc* and *argv* arguments to main, but neither
33-
modifies, interprets, nor distributes them:
34+
See `MPI-5.0:11.4.1 <https://www.mpi-forum.org/>`_ for a list of MPI
35+
functionality that is available (e.g., even when the MPI
36+
world model has not yet initialized or has already been finalized).
37+
38+
Open MPI's :ref:`MPI_Init` and :ref:`MPI_Init_thread` both accept the
39+
C *argc* and *argv* arguments to main, but neither modifies,
40+
interprets, nor distributes them:
3441

3542
.. code-block:: c
3643
37-
/* declare variables */
38-
MPI_Init(&argc, &argv);
39-
/* parse arguments */
40-
/* main program */
41-
MPI_Finalize();
44+
#include <mpi.h>
45+
46+
int main(int argv, char *argv[]) {
47+
MPI_Init(&argc, &argv);
48+
/* ...body of main MPI pogram... */
49+
MPI_Finalize();
50+
return 0;
51+
}
4252
53+
By default, :ref:`MPI_Init` is effectively equivalent to invoking
54+
:ref:`MPI_Init_thread` with a *required* value of
55+
``MPI_THREAD_SINGLE``. However, if the ``OMPI_MPI_THREAD_LEVEL``
56+
environment variable is set to a valid value when :ref:`MPI_Init` is
57+
invoked, it is equivalent to invoking :ref:`MPI_Init_thread` with
58+
*required* set to the corresponding value of the ``OMPI_MPI_THREAD_LEVEL``
59+
environment variable. See :ref:`MPI_Init_thread` for more details.
4360

4461
NOTES
4562
-----
4663

4764
The Fortran version does not have provisions for *argc* and *argv* and
4865
takes only IERROR.
4966

50-
The MPI Standard does not say what a program can do before an :ref:`MPI_Init`
51-
or after an :ref:`MPI_Finalize`. In the Open MPI implementation, it should do
52-
as little as possible. In particular, avoid anything that changes the
53-
external state of the program, such as opening files, reading standard
54-
input, or writing to standard output.
67+
The MPI Standard does not specify what a program using the MPI world
68+
model can do before invoking :ref:`MPI_Init` or :ref:`MPI_Init_thread`
69+
or after invoking :ref:`MPI_Finalize`. In the Open MPI implementation,
70+
it should do as little as possible. In particular, avoid anything that
71+
changes the external state of the program, such as opening files,
72+
reading standard input, or writing to standard output.
5573

5674

5775
ERRORS
@@ -64,3 +82,5 @@ ERRORS
6482
* :ref:`MPI_Initialized`
6583
* :ref:`MPI_Finalize`
6684
* :ref:`MPI_Finalized`
85+
* :ref:`MPI_Session_finalize`
86+
* :ref:`MPI_Session_init`

0 commit comments

Comments
 (0)