Using DistributedMake |
1 |
![]() |
Basic Concepts
DistributedMake (DMake) allows you to concurrently distribute the process of building large projects, consisting of many programs, over a number of workstations and, in the case of multiprocessor systems, over multiple CPUs. DMake parses your makefiles and:
To understand DMake, you should know about the following:
Build Server Configuration File
The /etc/opt/SPROdmake/dmake.conf file is in the file system of build servers. It is used to specify the maximum total number of DMake jobs that can be distributed to it by all DMake users. See "The Build Server" on page 7 for more information.
The DMake Host
DMake searches for a runtime configuration file to know where to distribute jobs. Generally, this file must be in your home directory on the DMake host and is named .dmakerc. DMake searches for the runtime configuration file in these locations and in the following order:
# My machine. This entry causes dmake to distribute to it. falcon { jobs = 1 } hawk eagle { jobs = 3 } # Manager's machine. She's usually at meetings heron { jobs = 4 } avocet |
You can also construct groups of build servers in the runtime configuration file. This provides you with the flexibility of easily switching between different groups of build servers as circumstances warrant. For instance you may define a different group of build servers for builds under different operating systems, or on groups of build servers that have special software installed on them.
Note - This list of build servers includes falcon which is also the DMake host. The DMake host can also be specified as a build server. If you do not include it in the runtime configuration file, no DMake jobs are distributed to it.
The following is an example of a runtime configuration file that contains groups of build servers:
jobs: 8 |
Note - If the /etc/opt/SPROdmake.conf file does not exist on a build server, no DMake jobs will be allowed to run on that server.
What You Should Know About DMake Before You Use It
To use DMake, you use the executable file (dmake) in place of the standard make utility. You should understand the Solaris make utility before you use DMake. If you need to read more about the make utility see the Programming Utilities Guide in the Solaris 2.5 Software Developer AnswerBook documentation set. If you use the make utility, the transition to DMake requires little if any alteration. DMake's Impact on Makefiles
The methods and examples shown in this section present the kinds of problems that lend themselves to solution with DMake. This section does not suggest that any one approach or example is the best. Compromises between clarity and functionality were made in many of the examples. Using Makefile Templates
If you use a makefile template from the outset of your project, custom makefiles that evolve from the makefile templates will be:
When given a target to build, DMake checks the dependencies associated with that target, and builds those that are out of date. Building those dependencies may, in turn, entail building some of their dependencies. When distributing jobs, DMake starts every target that it can. As these targets complete, DMake starts other targets. Nested invocations of DMake are not run concurrently by default, but this can be changed (see "Restricting Parallelism" on page 12 for more information).
Since DMake builds multiple targets concurrently, the output of each build is produced simultaneously. To avoid intermixing the output of various commands, DMake collects output from each build separately. DMake displays the commands before they are executed. If an executed command generates any output, warnings, or errors, DMake displays the entire output for that command. Since commands started later may finish earlier, this output may be displayed in an unexpected order.
Limitations on Makefiles
Concurrent building of multiple targets places some restrictions on makefiles. Makefiles that depend on the implicit ordering of dependencies may fail when built concurrently. Targets in makefiles that modify the same files may fail if those files are modified concurrently by two different targets. Some examples of possible problems are discussed in this section. Dependency Lists
When building targets concurrently, it is important that dependency lists be accurate. For example, if two executables use the same object file but only one specifies the dependency, then the build may cause errors when done concurrently. For example, consider the following makefile fragment:
all: prog1 prog2 prog1: prog1.o aux.o $(LINK.c) prog1.o aux.o -o prog1 prog2: prog2.o $(LINK.c) prog2.o aux.o -o prog2 |
When built serially, the target aux.o is built as a dependent of prog1 and is up-to-date for the build of prog2. If built in parallel, the link of prog2 may begin before aux.o is built, and is therefore incorrect. The .KEEP_STATE feature of make detects some dependencies, but not the one shown above.
Explicit Ordering of Dependency Lists
Other examples of implicit ordering dependencies are more difficult to fix. For example, if all of the headers for a system must be constructed before anything else is built, then everything must be dependent on this construction. This causes the makefile to be more complex and increases the potential for error when new targets are added to the makefile. The user can specify the special target .WAIT in a makefile to indicate this implicit ordering of dependents. When DMake encounters the .WAIT target in a dependency list, it finishes processing all prior dependents before proceeding with the following dependents. More than one .WAIT target can be used in a dependency list. The following example shows how to use .WAIT to indicate that the headers must be constructed before anything else.
all: hdrs .WAIT libs functions |
You can add an empty rule for the .WAIT target to the makefile so that the makefile is backward-compatible.
Concurrent File Modification
You must make sure that targets built concurrently do not attempt to modify the same files at the same time. This can happen in a variety of ways. If a new suffix rule is defined that must use a temporary file, the temporary file name must be different for each target. You can accomplish this by using the dynamic macros $@ or $*. For example, a .c.o rule which performs some modification of the .c file before compiling it might be defined as:
.c.o: awk -f modify.awk $*.c > $*.mod.c $(COMPILE.c) $*.mod.c -o $*.o $(RM) $*.mod.c |
Concurrent Library Update
Another potential concurrency problem is the default rule for creating libraries that also modifies a fixed file, that is, the library. The inappropriate .c.a rule causes DMake to build each object file and then archive that object file. When DMake archives two object files in parallel, the concurrent updates will corrupt the archive file.
.c.a: $(COMPILE.c) -o $% $< $(AR) $(ARFLAGS) $@ $% $(RM) $% |
.c.a: $(COMPILE.c) -o $% $< lib.a: lib.a($(OBJECTS)) $(AR) $(ARFLAGS) $(OBJECTS) $(RM) $(OBJECTS) |
Multiple Targets
Another form of concurrent file update occurs when the same rule is defined for multiple targets. An example is a yacc(1) program that builds both a program and a header for use with lex(1). When a rule builds several target files, it is important to specify them as a group using the + notation. This is especially so in the case of a parallel build.
y.tab.c y.tab.h: parser.y $(YACC.y) parser.y |
This rule is actually equivalent to the two rules:
y.tab.c: parser.y $(YACC.y) parser.y y.tab.h: parser.y $(YACC.y) parser.y |
y.tab.c + y.tab.h: parser.y $(YACC.y) parser.y |
Restricting Parallelism
Sometimes file collisions cannot be avoided in a makefile. An example is xstr(1), which extracts strings from a C program to implement shared strings. The xstr command writes the modified C program to the fixed file x.c and appends the strings to the fixed file strings. Since xstr must be run over each C file, the following new .c.o rule is commonly defined:
.c.o: $(CC) $(CPPFLAGS) -E $*.c | xstr -c - $(CC) $(CFLAGS) $(TARGET_ARCH) -c x.c mv x.o $*.o |
.NO_PARALLEL: $(OBJECTS) |
.NO_PARALLEL: .PARALLEL: $(LIB_OBJECT) |
Nested Invocations of DistributedMake
When DMake encounters a target that invokes another DMake command, it builds that target serially, rather than concurrently. This prevents problems where two different DMake invocations attempt to build the same targets in the same directory. Such a problem might occur when two different programs are built concurrently, and each must access the same library. The only way for each DMake invocation to be sure that the library is up-to-date is for each to invoke DMake recursively to build that library. DMake only recognizes a nested invocation when the $(MAKE) macro is used in the command line.
How to Use DMake
You execute dmake on a DMake host and distribute jobs to build servers. You can also distribute jobs to the DMake host, in which case it is also considered to be a build server. DMake distributes jobs based on makefile targets that DMake determines (based on your makefiles) can be built concurrently. You can use any machine as a build server that meets the following requirements:
demo% rsh build_server which dmake /opt/SUNWspro/bin/dmake |
demo% rsh build_server which dmake /opt/SUNWspro/bin/dmake |
Note - If you access DMake from the GUI (Building) use the online help to know how to specify your build servers and jobs. If you access DMake from the CLI see the DMake man page (dmake.1).
demo% twconfig &
![]() | To access the manual page for information on how to use DMake from the
CLI, enter the following. The manual page gives information on all
command-line options, variables, and macros necessary to use DMake.
|