5.1 Scripting Languages

The Linux shell scripting languages provide simple but effective ways of managing parallelism. For example, suppose that you had a program compute_it that you needed to run twice with two different sets of arguments. This can be accomplished as follows:



  1 compute_it 1 > compute_it.1.out &
  2 compute_it 2 > compute_it.2.out &
  3 wait
  4 cat compute_it.1.out
  5 cat compute_it.2.out


Figure: Execution Diagram for Parallel Shell Execution
\resizebox{3in}{!}{\includegraphics{toolsoftrade/shellparallel}}

Lines 1 and 2 launch two instances of this program, redirecting their output to two separate files, with the & character directing the shell to run the two instances of the program in the background. Line 3 waits for both instances to complete, and lines 4 and 5 display their output. The resulting execution is as shown in Figure [*]: the two instances of compute_it execute in parallel, wait completes after both of them do, and then the two instances of cat execute sequentially.

Quick Quiz 5.1: But this silly shell script isn't a real parallel program! Why bother with such trivia??? End Quick Quiz

Quick Quiz 5.2: Is there a simpler way to create a parallel shell script? If so, how? If not, why not? End Quick Quiz

For another example, the make software-build scripting language provides a -j option that specifies how much parallelism should be introduced into the build process. For example, typing make -j4 when building a Linux kernel specifies that up to four parallel compiles be carried out concurrently.

It is hoped that these simple examples convince you that parallel programming need not always be complex or difficult.

Quick Quiz 5.3: But if script-based parallel programming is so easy, why bother with anything else? End Quick Quiz

Paul E. McKenney 2011-12-16