Contents
Overview
Most C/C++ development environments depend on some version of the
make utility to manage the build process, yet many engineers
don't take advantage of its parallel capabilities to reduce compile
times. This article will explain how to use this feature and
provide explanations and solutions for the most common pitfalls.
Introduction
Unlike the procedural programming languages we typically use (that is, C++,
perl, and Java), the dataflow language of In more sophisticated development environments, parallel builds can be distributed across multiple machines or even multiple networks (which are sometimes distinguished as distributed rather than a parallel builds). This may require non-trivial preparation (that is, setting up a grid) which is normally addressed by an administrator or a build master so that each engineer doesn't need to be aware of the fine details of the implementation. Here we'll address the simpler case where there is an existing serial build environment, on a single machine, and you just want to decrease your build times. Note, however, that most of the issues discussed for this simpler situation must also be addressed for the more general environment as well. Rationale
On a multiprocessor machine, the advantage of parallel Putting It into Practice
While most
A parallel build with
The invocation syntax to specify the number of jobs may differ
for other parallel Your results will vary based on the particular compiler, options, and language being compiled, as well as whether the sources are local or remote. A common rule-of-thumb is to request the number of parallel jobs to be approximately 1.5 times the number of available CPUs on the machine. If this initial invocation works (and usually, it will), then you should start seeing reduced build times on uniprocessor machines and even more of a reduction on multiprocessor machines. However, if it does not work, then the following sections may help explain some problems that are specific to parallelization, how to recognize them, and how to fix them. Problem 1: Implicit Dependencies
Possibly the most common failure is caused by an unstated dependency that has inadvertently been introduced in the Makefile (that is, a Makefile bug). These can go unnoticed for serial builds, but will cause a parallel build to fail.
For example, consider an application where a module implementing the menus
for a user interface is automatically generated by scanning the other object
files, looking for functions matching a particular naming convention.
The offending
The subtlety here is that for a serial build,
To make matters worse, the failure may be intermittent. Because this
is a parallel You can recognize this situation because a serial build will succeed, but a parallel build will fail (with the specific failure being that some dependencies are not created). If you retry the build, it will then succeed.
Out of frustration, some engineers resort to using the
compound command "
Problem 2: Reuse of Temporary Files
Another common problem can arise from the reuse of intermediate
files. For example, consider an application which uses
This problem becomes even more subtle when using the default
In either case, this works without any problem for a serial build
because the intermediate file,
This particular example is easy to fix because
Problem 3: Resource Exhaustion
If your machine is under-configured to handle the amount of parallelism that you've requested, you may run out of either virtual or physical memory. In the first case, you'll see the message:
And in the second, you will see a significant slowdown in compile speed (because the compiler is being forced to page to disk). In both cases, the solution is to reduce the amount of parallelism (or add memory).
A slightly different, but related, situation is when your parallel build
consumes more than your fair share of a multi-user machine. In that case,
Problem 4: Serial Tools
In some cases, the compiler itself can inhibit parallel builds. In particular, older versions of the Sun C++ compiler serialize when accessing the template cache. The fix for this problem is to avoid using the template cache by:
Problem 5: Old Versions of gmake and NFS
Very old versions of
However, if you manually inspect the directory using
To fix this problem, install a more recent version of Summary
This optimization is usually easy to implement and should noticeably
reduce build times on a uniprocessor and dramatically reduce them on a
multiprocessor. The cleanup usually does not complicate the Makefile
and is a necessary first step for more sophisticated distributed
builds.
Resources
| ||||||||||||||||||||||||||||
Oracle is reviewing the Sun product roadmap and will provide guidance to customers in accordance with Oracle's standard product communication policies. Any resulting features and timing of release of such features as determined by Oracle's review of roadmaps, are at the sole discretion of Oracle. All product roadmap information, whether communicated by Sun Microsystems or by Oracle, does not represent a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. It is intended for information purposes only, and may not be incorporated into any contract.
|
| ||||||||||||