HP C Programmer's Guide (92434-90009)

108 Chapter4
Optimizing HP C Programs
Parallel Execution
export MP_NUMBER_OF_THREADS=2
MP_HEAP_MBYTES
For this release, parallel programs have a fixed amount of heap storage. If your parallel
program allocates dynamic memory (or calls a program that does) and it runs out of
memory, use the MP_HEAP_MBYTES environment variable to increase the size (in
megabytes) of the data segment. For programs not compiled with the +Oparallel option,
the HP-UX kernel configuration parameter maxdsize sets the maximum size of the data
segment. MP_HEAP_MBYTES has a default value of 16.
Parallelizing C Programs
The following sections discuss how to compile C programs for parallel execution, inhibitors
to parallelization, and related diagnostic messages.
Compiling Code for Parallel Execution
If a program has one or more of its files compiled with the +Oparallel option, then the
remaining files must be compiled with the +Oparallel_env option. This requirement
ensures a consistent execution environment for all files in the program, including any that
you want to execute serially.
The following command lines compile (without linking) three source files: x.c, y.c, and
z.c. The files x.c and y.c are compiled for parallel execution. The file z.c is compiled for
serial execution, even though its object file will be linked with x.o and y.o.
cc +O4 +Oparallel -c x.c y.c
cc +O4 +Oparallel_env -c z.c
The following command line links the three object files, producing the executable file
para_prog:
cc +O4 +Oparallel -o para_prog x.o y.o z.o
As this command line implies, if you link and compile separately, you must use cc, not ld.
The command line to link must also include the +Oparallel option in order to link in the
right startup files and runtime support.
NOTE
To ensure the best performance from a parallel program, do not run more
than one parallel program on a multiprocessor machine at the same time.
Running two or more parallel programs simultaneously or running one
parallel program on a heavily loaded system, will slow performance.
The C compiler will issue warning 8007 if you attempt to compile a program with the
+Oparallel option and the program calls a system routine with any of the following
names: dial, exec, execl, execle, execlp, execv, execve, execvp, f77fork, fork,
f77vfork, grantpt, key_decryptsession, key_encryptsession, key_gendes,
key_setsecret, popen, syslog, system, vfork, wordexp, or wordfree.
The text of warning 8007 is: Call to system function
routine
may inhibit parallel
execution.
At runtime, compiler-inserted code performs a check to determine if the call is to a system