OpenMP: Difference between revisions

Jump to navigation Jump to search
(Basic content on OpenMP taken from the Calcul Québec page on this topic.)
 
Line 148: Line 148:


== Environment ==
== Environment ==
The following four environment variables influence the execution of an OpenMP program. Depending on the command shell that is used, they can be modified using the UNIX command "export VariableName=value", or "setenv", etc.
There are four environment variables influence the execution of an OpenMP program:
 
<pre>
<pre>
OMP_SCHEDULE
OMP_SCHEDULE
Line 156: Line 155:
OMP_NESTED
OMP_NESTED
</pre>
</pre>
They can be set and modified using the UNIX command
{{command|export OMP_NUM_THREADS{{=}}12}}
for example. In most cases, you want to use set <tt>OMP_NUM_THREADS</tt> to the number of reserved processors per machine though this could be different for a hybrid OpenMP/MPI application.


In most cases, you want to use ''OMP_NUM_THREADS = ppn'' where ppn is the number of reserved processors per machine. This could be different for a hybrid OpenMP/MPI application.
The second most important environment variable is probably <tt>OMP_SCHEDULE</tt>. This one controls how loops (and, more generally, parallel sections) are distributed. The default value depends on the compiler, and can be put into the source code. Possible values are
 
The second most important environment variable is probably OMP_SCHEDULE. This one controls how loops (and, more generally, parallel sections) are distributed. The default value depends on the compiler, and can be put into the source code. Possible values are
''static,n'', ''dynamic,n'', ''guided,n'' or ''auto''. For the first three cases, ''n'' corresponds to the number of iterations managed by each thread. For the ''static'' case, the number of iterations is fixed, and iterations are distributed at the beginning of the parallel section. For the ''dynamic'' case, the number of iterations is fixed, but the they are distributed during execution, as a function of the time required by each thread to execute its iterations. For the ''guided'' case, ''n'' corresponds to the minimal number of iterations. The number of iterations is first chosen to be "large", but dynamically shrinks gradually as the remaining number of iterations diminishes. For the ''auto'' mode, the compiler and the library are free to choose what to do.
''static,n'', ''dynamic,n'', ''guided,n'' or ''auto''. For the first three cases, ''n'' corresponds to the number of iterations managed by each thread. For the ''static'' case, the number of iterations is fixed, and iterations are distributed at the beginning of the parallel section. For the ''dynamic'' case, the number of iterations is fixed, but the they are distributed during execution, as a function of the time required by each thread to execute its iterations. For the ''guided'' case, ''n'' corresponds to the minimal number of iterations. The number of iterations is first chosen to be "large", but dynamically shrinks gradually as the remaining number of iterations diminishes. For the ''auto'' mode, the compiler and the library are free to choose what to do.


Line 167: Line 167:
Other environment variables are also available. Certain variables are specific to a compiler whereas others are more generic. For an exhaustive list for the Intel compiler, please see [http://software.intel.com/sites/products/documentation/doclib/stdxe/2013/composerxe/compiler/cpp-lin/GUID-E1EC94AE-A13D-463E-B3C3-6D7A7205F5A1.htm the following web site], and for the GNU compilers, see [http://gcc.gnu.org/onlinedocs/libgomp/Environment-Variables.html this one].
Other environment variables are also available. Certain variables are specific to a compiler whereas others are more generic. For an exhaustive list for the Intel compiler, please see [http://software.intel.com/sites/products/documentation/doclib/stdxe/2013/composerxe/compiler/cpp-lin/GUID-E1EC94AE-A13D-463E-B3C3-6D7A7205F5A1.htm the following web site], and for the GNU compilers, see [http://gcc.gnu.org/onlinedocs/libgomp/Environment-Variables.html this one].


Environment variables specific to the Intel compiler start with ''KMP_'' whereas those specific to Gnu start with ''GOMP_''. For optimal performance regarding memory access, it is important to set the
Environment variables specific to the Intel compiler start with <tt>KMP_</tt> whereas those specific to Gnu start with <tt>GOMP_</tt>. For optimal performance regarding memory access, it is important to set the
OMP_PROC_BIND variable
<tt>OMP_PROC_BIND</tt> variable as well as the affinity variables, <tt>KMP_AFFINITY</tt> for Intel, and <tt>GOMP_CPU_AFFINITY</tt> for GNU compilers. This prevents the movement of OpenMP threads between processors by the operating system. This is particularly important in a [http://en.wikipedia.org/wiki/Non_Uniform_Memory_Access NUMA] architecture as can be found on most modern computers.
 
as well as the affinity variables,  
 
  KMP_AFFINITY
 
for Intel, and
 
  GOMP_CPU_AFFINITY
 
for GNU compilers. This prevents the movement of OpenMP threads between processors by the operating system. This is particularly important in a [http://en.wikipedia.org/wiki/Non_Uniform_Memory_Access NUMA] architecture as can be found on most modern architectures.
Bureaucrats, cc_docs_admin, cc_staff
2,306

edits

Navigation menu