@@ -6,7 +6,7 @@ MPI_Init_thread
6
6
7
7
.. include_body
8
8
9
- :ref: `MPI_Init_thread ` |mdash | Initializes the MPI execution environment
9
+ :ref: `MPI_Init_thread ` |mdash | Initializes the MPI world model
10
10
11
11
.. The following file was automatically generated
12
12
.. include :: ./bindings/mpi_init_thread.rst
@@ -25,64 +25,137 @@ OUTPUT PARAMETERS
25
25
DESCRIPTION
26
26
-----------
27
27
28
- This routine, or :ref: `MPI_Init `, must be called before most other MPI routines
29
- are called. There are a small number of exceptions, such as
30
- :ref: `MPI_Initialized ` and :ref: `MPI_Finalized `. MPI can be initialized at most once;
31
- subsequent calls to :ref: `MPI_Init ` or :ref: `MPI_Init_thread ` are erroneous.
28
+ When using the MPI world model, this routine, or
29
+ :ref: `MPI_Init_thread `, must be called before most other MPI routines
30
+ are called. There are a small number of routines that can be invoked
31
+ before :ref: `MPI_Init ` or :ref: `MPI_Init_thread `, such as
32
+ :ref: `MPI_Initialized ` and :ref: `MPI_Finalized `.
32
33
33
- :ref: ` MPI_Init_thread `, as compared to :ref: ` MPI_Init `, has a provision to request a
34
- certain level of thread support in * required *:
34
+ The MPI world model can be initialized at most once; subsequent calls
35
+ to :ref: ` MPI_Init ` or :ref: ` MPI_Init_thread ` are erroneous.
35
36
36
- MPI_THREAD_SINGLE
37
- Only one thread will execute .
37
+ Alternatively, instead of the MPI world model, MPI applications can
38
+ use the sessions model; see :ref: ` MPI_Session_init ` .
38
39
39
- MPI_THREAD_FUNNELED
40
- If the process is multithreaded, only the thread that called
41
- :ref: `MPI_Init_thread ` will make MPI calls.
40
+ Upon return, the level of thread support available to the program is
41
+ set in *provided *. In Open MPI, the value is dependent on how the
42
+ library was configured and built. Note that there is no guarantee that
43
+ *provided * will be greater than or equal to *required *.
42
44
43
- MPI_THREAD_SERIALIZED
44
- If the process is multithreaded, only one thread will make MPI
45
- library calls at one time.
45
+ Open MPI accepts the C *argc * and *argv * arguments to main, but
46
+ neither modifies, interprets, nor distributes them:
46
47
47
- MPI_THREAD_MULTIPLE
48
- If the process is multithreaded, multiple threads may call MPI at
49
- once with no restrictions.
48
+ .. code-block :: c
50
49
51
- The level of thread support available to the program is set in
52
- *provided *. In Open MPI, the value is dependent on how the library was
53
- configured and built. Note that there is no guarantee that *provided *
54
- will be greater than or equal to *required *.
50
+ #include <mpi.h>
55
51
56
- Also note that calling :ref: `MPI_Init_thread ` with a *required * value of
57
- MPI_THREAD_SINGLE is equivalent to calling :ref: `MPI_Init `.
52
+ int main(int argv, char *argv[]) {
53
+ int provided;
54
+ MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE, &provided);
55
+ /* ...body of main MPI pogram... */
56
+ MPI_Finalize();
57
+ return 0;
58
+ }
58
59
59
- All MPI programs must contain a call to :ref: `MPI_Init ` or :ref: `MPI_Init_thread `.
60
- Open MPI accepts the C *argc * and *argv * arguments to main, but neither
61
- modifies, interprets, nor distributes them:
62
60
63
- .. code-block :: c
61
+ :ref: `MPI_Init_thread ` has both a direct and an indirect mechanism to
62
+ request a specific level of thread support. :ref: `MPI_Init ` only has
63
+ an indirect mechanism to request a specific level of thread support.
64
+
65
+ Direct request of thread level
66
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
67
+
68
+ :ref: `MPI_Init_thread ` has the *required * parameter, which can be set
69
+ to any one of the following constants (from ``mpi.h ``):
70
+
71
+ * ``MPI_THREAD_SINGLE ``: Indicating that only one thread will execute.
72
+
73
+ * ``MPI_THREAD_FUNNELED ``: Indicating that if the process is
74
+ multithreaded, only the thread that called :ref: `MPI_Init_thread `
75
+ will make MPI calls.
76
+
77
+ * ``MPI_THREAD_SERIALIZED ``: Indicating that if the process is
78
+ multithreaded, only one thread will make MPI library calls at one
79
+ time.
80
+
81
+ * ``MPI_THREAD_MULTIPLE ``: Indicating that if the process is
82
+ multithreaded, multiple threads may call MPI at once with no
83
+ restrictions.
84
+
85
+ The values of these constants adhere to the following relationships:
86
+
87
+ .. math ::
88
+ :nowrap:
89
+
90
+ \begin {eqnarray}
91
+ MPI\_THREAD\_SINGLE & < & MPI\_THREAD\_FUNNELED \\
92
+ MPI\_THREAD\_FUNNELED & < & MPI\_THREAD\_SERIALIZED \\
93
+ MPI\_THREAD\_SERIALIZED & < & MPI\_THREAD\_MULTIPLE \\
94
+ \end {eqnarray}
95
+
96
+ Indirect request of thread level
97
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
98
+
99
+ Both :ref: `MPI_Init_thread ` and :ref: `MPI_Init ` support an indirect
100
+ method of indicating the required thread level: setting the
101
+ ``OMPI_MPI_THREAD_LEVEL `` environment variable:
102
+
103
+ * If the ``OMPI_MPI_THREAD_LEVEL `` environment variable is set at the
104
+ time :ref: `MPI_Init ` is invoked, it behaves as if
105
+ :ref: `MPI_Init_thread ` was invoked with the corresponding
106
+ ``MPI_THREAD_* `` constant value passed via the *required * parameter.
107
+
108
+ * If the ``OMPI_MPI_THREAD_LEVEL `` environment variable is set at the
109
+ time :ref: `MPI_Init_thread ` is invoked, the ``MPI_THREAD_* ``
110
+ constant value corresponding to the environment variable value
111
+ overrides the value passed via the *required * parameter.
112
+
113
+ The ``OMPI_MPI_THREAD_LEVEL `` environment variable can be set to one
114
+ of several different values:
115
+
116
+ .. list-table ::
117
+ :header-rows: 1
118
+
119
+ * - Value that Open MPI uses
120
+ - Allowable values (case-insensitive)
121
+
122
+ * - ``MPI_THREAD_SINGLE ``
123
+ - ``MPI_THREAD_SINGLE ``, ``THREAD_SINGLE ``, ``SINGLE ``, 0
124
+
125
+ * - ``MPI_THREAD_FUNNELED ``
126
+ - ``MPI_THREAD_FUNNELED ``, ``THREAD_FUNNELED ``, ``FUNNELED ``, 1
127
+
128
+ * - ``MPI_THREAD_SERIALIZED ``
129
+ - ``MPI_THREAD_SERIALIZED ``, ``THREAD_SERIALIZED ``,
130
+ ``SERIALIZED ``, 2
131
+
132
+ * - ``MPI_THREAD_MULTIPLE ``
133
+ - ``MPI_THREAD_MULTIPLE ``, ``THREAD_MULTIPLE ``, ``MULTIPLE ``, 3
64
134
65
- /* declare variables */
66
- MPI_Init_thread(&argc, &argv, req, &prov);
67
- /* parse arguments */
68
- /* main program */
69
- MPI_Finalize();
135
+ .. note :: Prior to Open MPI v6.0.0, only the integer values 0 through
136
+ 3 were acceptable values for the ``OMPI_MPI_THREAD_LEVEL ``
137
+ environment variable.
70
138
139
+ Starting with Open MPI v6.0.0, the Open MPI community
140
+ recomends using one of the string name variants so that it
141
+ can be correctly mapped to the corresponding Open MPI ABI
142
+ value or the MPI Standard ABI value, as relevant.
71
143
72
144
NOTES
73
145
-----
74
146
75
147
The Fortran version does not have provisions for ``argc `` and ``argv `` and
76
- takes only ``IERROR ``.
148
+ takes only ``REQUIRED ``, `` PROVIDED ``, and `` IERROR ``.
77
149
78
150
It is the caller's responsibility to check the value of ``provided ``, as
79
151
it may be less than what was requested in ``required ``.
80
152
81
- The MPI Standard does not say what a program can do before an
82
- :ref: `MPI_Init_thread ` or after an :ref: `MPI_Finalize `. In the Open MPI
83
- implementation, it should do as little as possible. In particular, avoid
84
- anything that changes the external state of the program, such as opening
85
- files, reading standard input, or writing to standard output.
153
+ The MPI Standard does not specify what a program using the MPI world
154
+ model can do before invoking :ref: `MPI_Init ` or :ref: `MPI_Init_thread `
155
+ or after invoking :ref: `MPI_Finalize `. In the Open MPI implementation,
156
+ it should do as little as possible. In particular, avoid anything that
157
+ changes the external state of the program, such as opening files,
158
+ reading standard input, or writing to standard output.
86
159
87
160
88
161
MPI_THREAD_MULTIPLE Support
@@ -93,7 +166,7 @@ Open MPI was built supports threading. You can check the output of
93
166
:ref: `ompi_info(1) <man1-ompi_info >` to see if Open MPI has
94
167
``MPI_THREAD_MULTIPLE `` support:
95
168
96
- ::
169
+ .. code-block :: bash
97
170
98
171
shell$ ompi_info | grep " Thread support"
99
172
Thread support: posix (MPI_THREAD_MULTIPLE: yes, OPAL support: yes, OMPI progress: no, Event lib: yes)
@@ -117,3 +190,5 @@ ERRORS
117
190
* :ref: `MPI_Initialized `
118
191
* :ref: `MPI_Finalize `
119
192
* :ref: `MPI_Finalized `
193
+ * :ref: `MPI_Session_finalize `
194
+ * :ref: `MPI_Session_init `
0 commit comments