File: MPI_Init_thread.3.rst

package info (click to toggle)
openmpi 5.0.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 201,956 kB
  • sloc: ansic: 614,602; makefile: 42,354; sh: 11,194; javascript: 9,244; f90: 7,052; java: 6,404; perl: 5,192; python: 1,862; lex: 740; fortran: 61; cpp: 20; tcl: 12
file content (233 lines) | stat: -rw-r--r-- 7,174 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
.. _mpi_init_thread:


MPI_Init_thread
===============

.. include_body

:ref:`MPI_Init_thread` |mdash| Initializes the MPI world model


SYNTAX
------


C Syntax
^^^^^^^^

.. code-block:: c

   #include <mpi.h>

   int MPI_Init_thread(int *argc, char ***argv,
   	int required, int *provided)


Fortran Syntax
^^^^^^^^^^^^^^

.. code-block:: fortran

   USE MPI
   ! or the older form: INCLUDE 'mpif.h'
   MPI_INIT_THREAD(REQUIRED, PROVIDED, IERROR)
   	INTEGER	REQUIRED, PROVIDED, IERROR


Fortran 2008 Syntax
^^^^^^^^^^^^^^^^^^^

.. code-block:: fortran

   USE mpi_f08
   MPI_Init_thread(required, provided, ierror)
   	INTEGER, INTENT(IN) :: required
   	INTEGER, INTENT(OUT) :: provided
   	INTEGER, OPTIONAL, INTENT(OUT) :: ierror


INPUT PARAMETERS
----------------
* ``argc``: C only: Pointer to the number of arguments.
* ``argv``: C only: Argument vector.
* ``required``: Desired level of thread support (integer).

OUTPUT PARAMETERS
-----------------
* ``provided``: Available level of thread support (integer).
* ``ierror``: Fortran only: Error status (integer).

DESCRIPTION
-----------

This routine, or :ref:`MPI_Init`, initializes the MPI world
model.  Either of these routines must be called before MPI
communication routines are called within the MPI world model.  The MPI
world model can be initialized at most exactly once in the lifetime of
an MPI process.  This is different than the MPI session model, which
can be initialized and finalized multiple times in an MPI process.
See :ref:`MPI_Session_init` and :ref:`MPI_Session_finalize`.

See `MPI-5.0:11.4.1 <https://www.mpi-forum.org/>`_ for a list of MPI
functionality that is available (e.g., even when the MPI
world model has not yet initialized or has already been finalized).

The MPI world model can be initialized at most once; subsequent calls
to :ref:`MPI_Init` or :ref:`MPI_Init_thread` are erroneous.

Alternatively, instead of the MPI world model, MPI applications can
use the sessions model; see :ref:`MPI_Session_init`.

Upon return, the level of thread support available to the program is
set in *provided*. In Open MPI, the value is dependent on how the
library was configured and built. Note that there is no guarantee that
*provided* will be greater than or equal to *required*.

Open MPI accepts the C *argc* and *argv* arguments to main, but
neither modifies, interprets, nor distributes them:

.. code-block:: c

   #include <mpi.h>

   int main(int argv, char *argv[]) {
       int provided;
       MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE, &provided);
       /* ...body of main MPI pogram... */
       MPI_Finalize();
       return 0;
   }


:ref:`MPI_Init_thread` has both a direct and an indirect mechanism to
request a specific level of thread support.  :ref:`MPI_Init` only has
an indirect mechanism to request a specific level of thread support.

Direct request of thread level
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

:ref:`MPI_Init_thread` has the *required* parameter, which can be set
to any one of the following constants (from ``mpi.h``):

* ``MPI_THREAD_SINGLE``: Indicating that only one thread will execute.

* ``MPI_THREAD_FUNNELED``: Indicating that if the process is
  multithreaded, only the thread that called :ref:`MPI_Init_thread`
  will make MPI calls.

* ``MPI_THREAD_SERIALIZED``: Indicating that if the process is
  multithreaded, only one thread will make MPI library calls at one
  time.

* ``MPI_THREAD_MULTIPLE``: Indicating that if the process is
  multithreaded, multiple threads may call MPI at once with no
  restrictions.

The values of these constants adhere to the following relationships:

.. math::
   :nowrap:

   \begin{eqnarray}
       MPI\_THREAD\_SINGLE     & < & MPI\_THREAD\_FUNNELED \\
       MPI\_THREAD\_FUNNELED   & < & MPI\_THREAD\_SERIALIZED \\
       MPI\_THREAD\_SERIALIZED & < & MPI\_THREAD\_MULTIPLE \\
   \end{eqnarray}

Indirect request of thread level
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Both :ref:`MPI_Init_thread` and :ref:`MPI_Init` support an indirect
method of indicating the required thread level: setting the
``OMPI_MPI_THREAD_LEVEL`` environment variable:

* If the ``OMPI_MPI_THREAD_LEVEL`` environment variable is set at the
  time :ref:`MPI_Init` is invoked, it behaves as if
  :ref:`MPI_Init_thread` was invoked with the corresponding
  ``MPI_THREAD_*`` constant value passed via the *required* parameter.

* If the ``OMPI_MPI_THREAD_LEVEL`` environment variable is set at the
  time :ref:`MPI_Init_thread` is invoked, the ``MPI_THREAD_*``
  constant value corresponding to the environment variable value
  overrides the value passed via the *required* parameter.

The ``OMPI_MPI_THREAD_LEVEL`` environment variable can be set to any
of the values listed below.

.. list-table::
   :header-rows: 1

   * - Value that Open MPI uses
     - Allowable values (case-insensitive)

   * - ``MPI_THREAD_SINGLE``
     - ``MPI_THREAD_SINGLE``, ``SINGLE``, 0

   * - ``MPI_THREAD_FUNNELED``
     - ``MPI_THREAD_FUNNELED``, ``FUNNELED``, 1

   * - ``MPI_THREAD_SERIALIZED``
     - ``MPI_THREAD_SERIALIZED``, ``SERIALIZED``, 2

   * - ``MPI_THREAD_MULTIPLE``
     - ``MPI_THREAD_MULTIPLE``, ``MULTIPLE``, 3

.. note:: In Open MPI v5.0.8 and prior, only the integer values 0 through
          3 were acceptable values for the ``OMPI_MPI_THREAD_LEVEL``
          environment variable.

          Starting with Open MPI v5.0.9, the Open MPI community
          recomends using one of the string name variants.

NOTES
-----

The Fortran version does not have provisions for ``argc`` and ``argv`` and
takes only ``REQUIRED``, ``PROVIDED``, and ``IERROR``.

It is the caller's responsibility to check the value of ``provided``, as
it may be less than what was requested in ``required``.

The MPI Standard does not specify what a program using the MPI world
model can do before invoking :ref:`MPI_Init` or :ref:`MPI_Init_thread`
or after invoking :ref:`MPI_Finalize`. In the Open MPI implementation,
it should do as little as possible. In particular, avoid anything that
changes the external state of the program, such as opening files,
reading standard input, or writing to standard output.


MPI_THREAD_MULTIPLE Support
^^^^^^^^^^^^^^^^^^^^^^^^^^^

``MPI_THREAD_MULTIPLE`` support is included if the environment in which
Open MPI was built supports threading. You can check the output of
:ref:`ompi_info(1) <man1-ompi_info>` to see if Open MPI has
``MPI_THREAD_MULTIPLE`` support:

.. code-block:: bash

   shell$ ompi_info | grep "Thread support"
             Thread support: posix (MPI_THREAD_MULTIPLE: yes, OPAL support: yes, OMPI progress: no, Event lib: yes)
   shell$

The ``MPI_THREAD_MULTIPLE: yes`` portion of the above output indicates
that Open MPI was compiled with ``MPI_THREAD_MULTIPLE`` support.

Note that there is a small performance penalty for using
``MPI_THREAD_MULTIPLE`` support; latencies for short messages will be higher
as compared to when using ``MPI_THREAD_SINGLE``, for example.


ERRORS
------

.. include:: ./ERRORS.rst

.. seealso::
   * :ref:`MPI_Init`
   * :ref:`MPI_Initialized`
   * :ref:`MPI_Finalize`
   * :ref:`MPI_Finalized`
   * :ref:`MPI_Session_finalize`
   * :ref:`MPI_Session_init`