HP C Programmer's Guide (92434-90009)

Chapter 4 107
Optimizing HP C Programs
Parallel Execution
Parallel Execution
This section provides information on parallel execution.
Transforming Eligible Loops for Parallel Execution (+Oparallel)
The +Oparallel option causes the compiler to transform eligible loops for parallel
execution on multiprocessor machines.
If you link separately from the compile line and you compiled with the +Oparallel option,
you must link with the cc command and specify the +Oparallel option to link in the right
startup files and runtime support.
When a program is compiled with the +Oparallel option, the compiler looks for
opportunities for parallel execution in loops and generates parallel code to execute the loop
on the number of processors set by the MP_NUMBER_OF_THREADS environment variable
discussed below. By default, this is the number of processors on the executing machine.
For a discussion of parallelization, including how to use the +Oparallel option, see
"Parallelizing C Programs" below. For more detail on +Oparallel, see the description in
"Controlling Specific Optimizer Features" earlier in this chapter.
Executing Serially within a Parallel Environment (+Oparallel_env)
The +Oparallel_env option causes cc to compile all source files specified on the command
line to execute serially (that is, on a single processor) within a parallel execution
environment. The +Oparallel_env option ensures a consistent execution environment for
all files in a parallel-executing program.
If you link separately from the compile line and you compiled with the +Oparallel_env
option, you must link with the cc command and specify the +Oparallel option to link in
the right startup files and runtime support.
Environment Variables for Parallel Programs
Two environment variables are available for use with parallel programs:
MP_NUMBER_OF_THREADS
MP_HEAP_MBYTES
MP_NUMBER_OF_THREADS
The MP_NUMBER_OF_THREADS environment variable enables you to set the number of
processors that are to execute your program in parallel. If you do not set this variable, it
defaults to the number of processors on the executing machine.
On the C shell, the following command sets MP_NUMBER_OF_THREADS to indicate that
programs compiled for parallel execution can execute on two processors:
setenv MP_NUMBER_OF_THREADS 2
If you use the Korn shell, the command is: