Vous êtes sur la page 1sur 9

Pattern-based Parallel Programming

S. Bromling, S. MacDonald, J. Anvik, J. Schaeffer, D. Szafron, K. Tan


Department of Computing Science, University of Alberta,
Edmonton, Alberta, Canada T6G 2E8
Email: fbromling,stevem,janvik,jonathan,duane,cavalierg@cs.ualberta.ca

Abstract riosities that are shunned by practitioners. There are two


main reasons for this (others are explored in [16]):
The advantages of pattern-based programming have
been well-documented in the sequential programming lit-  Performance. Generic tools generally produce generic
erature. However patterns have yet to make their way parallel code with disappointing parallel performance.
into mainstream parallel computing, even though several Unfortunately, most tools do not provide support for
research tools support them. There are two critical short- incremental code tuning (e.g., by making all the library
comings of pattern (or template) based systems for parallel code available in a usable form).
programming: lack of extensibility and performance. This
 Generality. The tools are usually suitable only for a
paper describes our approach for addressing these prob-
small class of applications. If an application is not di-
lems in the CO2 P3 S parallel programming system. CO2 P3 S
rectly supported by the capabilities of the tool, then the
supports multiple levels of abstraction, allowing the user to
developer cannot use the tool at all.
design an application with high-level patterns, but move to
lower levels of abstraction for performance tuning. Pat- For many developers, these are the main reasons why MPI
terns are implemented as parameterized templates, allow- and OpenMP are so popular: the user has complete control
ing the user the ability to customize the pattern to meet over the performance of their application and the tools are
their needs. CO2 P3 S generates code that is specific to the general enough to be usable for most applications.
pattern/parameter combination selected by the user. The This paper discusses the CO2 P3 S1 parallel programming
MetaCO2 P3 S tool addresses extensibility by giving users environment, designed specifically to address the perfor-
the ability to design and add new pattern templates to mance and generality problems of current parallel program-
CO2 P3 S. Since the pattern templates are stored in a system- ming tools [10, 11]. Three key features of CO2 P3 S con-
independent format, they are suitable for storing in a repos- tribute to solving these problems: parameterized frame-
itory to be shared throughout the user community. works, a model that supports multiple layers of abstraction,
Keywords: parallel programming environment, design pat- and a tool that supports the creation of new parallel design
terns, frameworks, meta-programming. pattern templates.
A CO2 P3 S user expresses an application’s concurrency
by selecting one or more parallel design pattern templates.
1 Introduction For each design pattern template, the user selects a series
Parallel programming is harder than sequential program- of parameter values that customizes the design pattern tem-
ming. Despite two decades of parallel tools research, many plate for a specific application. Parameters allow CO2 P3 S
of the ideas that have improved sequential programming to provide general enough design pattern templates to sup-
productivity have yet to make their way into production par- port a wide range of applications, while facilitating the
allel tools. Message passing libraries (e.g., MPI) and com- generation of a non-generic efficient code framework. All
piler directives (e.g., OpenMP) represent the state of the art. application-specific code is entered as sequential stubs that
There have been numerous attempts to develop high- are called by the framework.
level parallel programming tools that abstract away much Most high-level parallel programming tools use a pro-
of the parallel complexity. Several tools require the user to gramming model that suffers from a lack of “openness”
write sequential stubs, with the tool inserting all the parallel [16]. The code generated by these tools is often difficult
code [15, 18, 13, 4, 2]. Despite these (often large) efforts, 1 Correct Object-Oriented Pattern-based Parallel Programming System,

high-level parallel programming tools remain academic cu- pronounced “cops”.

Proceedings of the International Conference on Parallel Processing (ICPP’02)


0-7695-1677-7/02 $17.00 © 2002 IEEE
to tune for performance. In some cases, parts of the code manner, and stored in a central repository. We need “open-
are not available to the user. In other cases, all the code patterns” in addition to open-source code. Only in this way
is available, but it is not very human-readable. CO2 P3 S can the high-level parallel tools research community cre-
has an open and layered programming model. All of the ate a critical mass of patterns that will interest practitioners.
code is available to the user and it is organized into three CO2 P3 S and MetaCO2 P3 S is a step towards this vision.
layers to make the software architecture understandable at Section 2 presents a sample application that is used
three different levels of abstraction. Performance tuning throughout the paper. Section 3 describes CO2 P3 S and Sec-
proceeds from the simplest most abstract top layer to the tion 4 discusses MetaCO2 P3 S. Section 5 compares CO2 P3 S
more detailed lower layers. When sufficient performance is and MetaCO2 P3 S to other related systems. Conclusions and
obtained, no further code details need to be learned. This future work are presented in Section 6.
approach provides performance gains that are commensu-
rate with the effort expended. 2 Case Study: Genetic Sequence Alignment
Current academic tools only support a small number of Throughout this paper, we will use the sequence align-
patterns and, with only a few exceptions, do not allow the ment problem from computational biology to illustrate how
creation of new patterns. MetaCO2 P3 S is a graphical design CO2 P3 S uses design pattern templates to parallelize appli-
pattern template editor. It supports generality by allowing a cations. This problem is solved by finding an optimal align-
pattern designer to both edit existing CO2 P3 S pattern tem- ment (with respect to a given scoring function) for a pair
plates and to add completely new pattern templates. New of DNA or protein sequences [7]. Typical algorithms for
pattern templates are first class in that they are just as gen- sequence alignment construct a dynamic programming ma-
eral and powerful as the built-in CO2 P3 S patterns. In addi- trix with the sequences on the top and left edges. A score
tion, MetaCO2 P3 S stores pattern templates in an XML for- is propagated from the top left corner to the bottom right.
mat that is independent of CO2 P3 S so they can be used in The value of each entry in the matrix depends on three pre-
other parallel programming systems as well. MetaCO2 P3 S viously computed values — north or above, west or to the
also supports performance, by making it easy to design pat- left, and north-west or the above-left diagonal — as shown
tern templates with many parameters that can be used to in Figure 1(a). Once the algorithm has calculated all of the
generate efficient code. values in the matrix, the maximal cost path (optimal se-
This paper makes the following contributions to the evo- quence alignment) can be obtained by tracing backwards
lution of high-level parallel programming environments: through the matrix.
1. CO2 P3 S, a parameterized parallel application develop- This problem was given to a parallel programming ex-
ment tool that provides a layered programming model pert, who was then asked to parallelize the application using
with multiple user-accessible abstractions for writing CO2 P3 S. The expert quickly identified a Wavefront parallel
and tuning parallel programs. design pattern. The Wavefront pattern applies to problems
where a computation needs to sweep breadth-first through
2. MetaCO2 P3 S, a parallel design pattern development a tree, with child nodes having data dependencies on their
tool. MetaCO2 P3 S supports the development of parents. The term wavefront describes the edge separating
platform-independent pattern templates that can be im- the processed nodes at the top of the tree from the nodes
ported into CO2 P3 S. waiting to be processed. The dynamic programming prob-
lem is easily expressed as a wavefront due to the depen-
3. The first parallel programming system that supports dency of each matrix entry on three neighbors. Figure 1(b)
the creation and usage of tool-independent parallel de- shows how the data dependencies in Figure 1(a) can be
sign patterns. transformed to a wavefront computation. Blocks with the
The CO2 P3 S and MetaCO2 P3 S combination is unique in same number can be computed concurrently after the blocks
the parallel computing world. Building a pattern-based par- with smaller numbers that satisfy the data dependencies
allel programming system is already a difficult task. Ensur- have been computed. CO2 P3 S has been used to develop
ing that the same environment can support the addition of several wavefront-like parallel applications [1].
new patterns adds further complications. Our community
needs a meta-programming tool that enables the creation 3 CO2 P3 S
of new patterns and supports the modification of existing The parallel computing literature is replete with famil-
ones. However, we need more than this. If pattern-based iar parallel structures. Concepts such as a pipeline, master-
programming systems are going to be accepted by the paral- slave, work-queue, divide-and-conquer, and wavefront are
lel programming community, the patterns must be transfer- structures that are well-known to experienced parallel pro-
able and re-usable from system to system. This means that grammers. Each concept immediately conjures up a vision
the patterns must be expressible in a system-independent of the concurrency that it represents. A parallel programmer

Proceedings of the International Conference on Parallel Processing (ICPP’02)


0-7695-1677-7/02 $17.00 © 2002 IEEE
connect the framework to the sequential application code
needed to solve the problem.
Frameworks are similar to libraries in some respects.
However there is an important difference. When a library is
used, a programmer must define the structure of the applica-
tion and make calls to the library code. Conversely, a frame-
work defines the structure of an application and the pro-
grammer supplies code for specific application-dependent
routines. Frameworks allow the programmer to reuse the
(a) Score propagation. (b) Computation ordering.
overall design of an application, and capitalize on object-
oriented techniques such as encapsulation and code reuse.
Figure 1. Solving the sequence alignment We combine frameworks and design patterns by consid-
problem with a dynamic programming matrix. ering the application domain of the framework to be the
implementation of a pattern. For instance, consider the
description of a Wavefront design pattern. Most wave-
front algorithms share the same basic structure with only
who has used a master-slave structure to solve one applica-
a few application-dependent properties. We can encapsu-
tion will use that experience to significantly reduce the ef-
late this structure into a framework that implements a ba-
fort needed to implement another master-slave application.
sic wavefront. The structural code uses classes that define
In object-oriented computing, design constructs that can be
the application-dependent properties of a wavefront without
re-used between applications are often expressed as design
implementing them, such as the function that computes the
patterns [8], which capture design experience at an abstract
value of an element from the value of its predecessors. A
level. By their nature, design patterns are applicable to dif-
user of this wavefront framework supplies these properties
ferent problem domains, each with its own individual char-
by either providing subclasses that contain the needed im-
acteristics and concerns. A design pattern is a description of
plementation or by composing framework-supplied classes
a solution to a general design problem that must be adapted
that modify the basic structure to better fit the application.
for each use. Once a user elects to use a design pattern, most
of the basic structure of the application can be inferred. 3.2 Pattern Templates
CO2 P3 S uses object-oriented techniques to simplify par- It is non-trivial to generate a framework from a design
allel programming [10, 11]. Developers begin by identi- pattern. A design pattern actually represents a family of
fying the parallel design patterns that describe their appli- solutions to a set of related problems. For example, the se-
cation’s basic structure. CO2 P3 S takes advantage of this quence alignment wavefront problem has specific data de-
knowledge in a more concrete manner. Specifically, par- pendencies (left, above, and above-left) and the computa-
allel applications that use a similar pattern not only share tion shape is an entire rectangular matrix. Other problems
a design solution, but also have a considerable amount of can be solved using a Wavefront pattern with different de-
common code, with only details that vary between appli- pendencies and a different data shape. It is unreasonable
cations. CO2 P3 S supports the re-use of this common code to expect a single design pattern to generate a single code
by generating a framework of parallel structure code from framework that implements a solution to the entire family
the selected design pattern. Users then implement their of problems represented by the design pattern. There ap-
application-specific code within this automatically gener- pear to be only two options. One option is to specialize the
ated framework that hides the entire parallel infrastructure. generic design pattern into a series of design patterns that
solve specific kinds of problems. However, this approach
3.1 Frameworks fails to recognize and take advantage of the common de-
Frameworks are a set of classes that implement the basic sign and code that appears in the specialized patterns and
structure of a specific kind of application [9]. This structural frameworks. The other option is to require a single generic
code defines the classes in the application and the flow of design pattern to generate a single highly-abstracted code
control through these classes. In general, a user of a frame- framework that can be specialized at run-time using a series
work must subclass the framework classes to provide imple- of parameter values that describe the application. However,
mentations of key components and compose these classes this approach yields code that is complex and inefficient.
into an application. In CO2 P3 S, the framework generates The CO2 P3 S solution is to start with a design pattern
placeholders for sequential hook methods that are called by template instead of a design pattern. A design pattern tem-
the framework. These methods are the only interface be- plate is a design pattern that has been augmented by a series
tween the application-dependent code and the framework. of parameters whose values span the family of design solu-
The user need only implement the few hook methods to tions represented by the design pattern. For example, in the

Proceedings of the International Conference on Parallel Processing (ICPP’02)


0-7695-1677-7/02 $17.00 © 2002 IEEE
CO2 P3 S Wavefront design pattern template, two of the pa-
rameters are the dependency set and the data shape. This
allows the design pattern template to span a large set of ap-
plication programs while enabling it to generate efficient
framework code for each specific application.
CO2 P3 S generates correct framework code from a de-
sign pattern description of the program structure. The gen-
erated code is specific to the pattern/parameter combination
supplied by the user. In contrast, other systems provide the
ability to specify the structure with patterns but rely on the
user to write application code that matches the specification.
The implementation details of the framework are hidden
from the programmer. To change the parallel structure of a
program, the user changes a parameter for the pattern tem-
plate and regenerates the framework code. Although this
new framework may introduce additional hook methods that
need to be implemented, hooks that were previously imple- Figure 2. CO2 P3 S Wavefront pattern template.
mented are included in the regenerated framework automat-
ically. Alternately, to obtain larger structural changes, the
programmer may select a completely different design pat-
tern. In this case, the programmer will need to implement guage and are made available to the user. The user can mod-
different hook methods; application code will need to be ify the generated structure, write new application code, or
moved from the old hook methods to the new ones. tune the structure.
3.3 A Layered Programming Model At the Native Code Layer, the intermediate language is
transformed into code for a native object-oriented language
A key aspect of CO2 P3 S is its separation of parallel code (such as Java or C++). This code provides all libraries used
from user code. Communication and synchronization con- to implement the intermediate code from the previous layer.
structs are hidden from the user in the generated framework. The user can tailor the libraries for the application require-
This helps to prevent the user from writing an incorrect ments or for the execution environment.
parallel program, and greatly simplifies their implementa- The Patterns Layer can be used to quickly build a correct
tion effort. To ensure that parallelism hiding does not limit program. The user can then move down to the Intermediate
CO2 P3 S users, the programming model is “open”, exposing and Native Code Layers to tune the program, if necessary.
all components of the generated program. CO2 P3 S supports
three layers of abstraction, allowing the user to design at a 3.4 Wavefront Application
high-level, and move down to lower-levels for performance Figure 2 shows the main CO2 P3 S window with the
tuning (if needed). Wavefront pattern template selected [1]. Using the pattern
The Patterns Layer promotes the rapid development of window, a CO2 P3 S user can select parameters to customize
structurally correct parallel programs. The user selects a a pattern template instance so that it matches their applica-
parallel design pattern template from a palette of supported tion’s needs. The Wavefront supports three design parame-
templates. This template represents a family of frameworks ters and three performance parameters. The design param-
for a given design pattern. The user can select the member eters are:
of this family that is best suited for an application by speci- 1. The name for the the Wavefront element class.
fying application–dependent template parameters. Once the
parameters have been specified, the template is then used 2. The shape of the element matrix. The default choice is
to generate object–oriented framework code implementing a full matrix shape in which all elements of a rectangu-
the pattern indicated by the template. The result is a cor- lar matrix are computed. Also supported are triangular
rect, functional parallel program. The user supplies the and banded shapes.
application-dependent hook methods.
3. The dependency set for an element. Figure 1(a) illus-
The Intermediate Code Layer provides a high–level,
trated the dependency set for the sequence alignment
object–oriented, explicitly-parallel programming language,
application. The user interface prevents a programmer
a superset of an existing object-oriented language. 2 The
from selecting illegal dependency sets. On the right-
abstract structural classes are implemented using this lan-
hand side of Figure 2, the dependencies graph for the
2 Not to be confused with the intermediate code used by compilers. sequence alignment problem is shown.

Proceedings of the International Conference on Parallel Processing (ICPP’02)


0-7695-1677-7/02 $17.00 © 2002 IEEE
The performance parameters are: public void execute()f
this.initialize();
while(!queue.isEmpty())f
1. The notification method used to inform elements that a
/* “work” is a WavefrontElement */
dependency constraint has been satisfied. One choice work = queue.getWork();
is to push or pull the data. Figure 2 shows that the push if(work is the corner) /* First element – no neighbors */
parameter has been selected. work.operateCorner();
elsif(work is on top edge) /* Top row – one neighbor */
2. The data type of wavefront elements. work.operateTop(location, leftValue);
elsif(work is on left edge) /* Left column – one neighbor */
3. Whether the program needs access to non-neighboring work.operateLeft(location, aboveValue);
else /* Interior – three neighbors */
elements (not needed for sequence alignment). work.operateInterior(location, aboveValue,
leftValue, diagonalValue);
In Figure 2, the parameters have been set to the values used g
for the sequence alignment problem. this.reduce();
The design parameters show the flexibility of the ap- g
proach, since a large family of different parallel structures
Figure 3. Wavefront code skeleton.
can be built from one pattern template. The performance pa-
rameters show that the generated code is not generic; they
enable the the system to be more specific in the code that is
faster program. This change cannot be made in the Pat-
generated, avoiding unnecessary run-time overheads.
terns Layer of CO2 P3 S; the user cannot touch the wave-
After customizing the pattern template by selecting
front driver code. At the Native Code Layer, all the code is
the appropriate set of parameters, the user requests that
exposed to the user, who can then make whatever changes
the framework code be generated. The current pattern
are appropriate. Although this is a trivial example, it does
templates in CO2 P3 S are configured to generate shared-
illustrate the need for multiple layers of abstraction in the
memory Java code. At the heart of the wavefront imple-
programming model.
mentation is a (hidden) driver that represents the control
flow of the parallel code. Figure 3 shows an abstracted ver- From the pattern designer’s point of view, the wavefront
sion of the wavefront driver. The only class the user imple- can be implemented using a work queue, where nodes at
ments is the WavefrontElement class. This class has three the edge of the wavefront whose data dependencies have
responsibilities: providing an initialization method that is been satisfied are available. A user’s view into a wavefront
called for each wavefront element (initialize), implement- framework requires only that they provide the node process-
ing the wavefront operations on a wavefront element (oper- ing implementation. They need not know about the wave-
ateCorner, operateTop, operateLeft, operateInterior), and front driver and how it is implemented. The CO2 P3 S frame-
supplying a method to be used for reducing the matrix after work includes all the communication and synchronization
the computation is complete (reduce). The user is supplied needed by the application, and automatically divides the
with stubs for the appropriate hook methods depending on matrix into blocks to ensure reasonable granularity. All the
the parameters specified. The framework invokes the appro- user sees is their initialize, operate, and reduce routines for
priate method based on the location of the element. Each a single wavefront node.
method has appropriate dependent elements as arguments The Wavefront pattern template in CO2 P3 S was used
and returns the computed element. to implement the dynamic programming matrix algorithm
Users are prevented from modifying method signatures. for sequence alignment. Two sequences of 10,000 random
Instead, hyper-links are provided for user-modifiable loca- proteins each were used as test data. The sequential and
tions in the code. This is one of the features in the system parallel implementations of the algorithm were run using a
designed to reduce the chance of programming error. Java 1.3 VM on a four-processor shared-memory SGI O2.
In Figure 3, note that the generated code skeleton has The push and pull notification parameter settings were both
been specialized to take into account the computation de- used independently as a comparison. The parallel speedups
pendencies (above, left, above-left) ensuring that the differ- achieved are compared in Figure 4, where each data point
ent cases are called under the right conditions and with the is the average over 20 runs. Given a problem large enough
right parameters. This example is intended to emphasize to amortize the cost of having a lack of work to do at the
the point that each pattern/parameter combination results in beginning and end of a wavefront computation, one would
customized code. It also illustrates the need for different expect to see close to linear speedups.
layers of abstraction. For example, the code in Figure 3 Given a functional sequential sequence alignment pro-
is non-optimal in the sense that there are far more interior gram, a user was able to get the parallel version running
nodes in the matrix than there are corner nodes. Reorganiz- using CO2 P3 S in two hours. Of course, this time is not nec-
ing the if statements to reflect this will result in a (slightly) essarily representative of the cost of doing any application

Proceedings of the International Conference on Parallel Processing (ICPP’02)


0-7695-1677-7/02 $17.00 © 2002 IEEE
4

3
Speedup

Sequential
2 Push
Pull

0
0 1 2 3 4

Processors

Figure 4. Wavefront speedups.

in CO2 P3 S. Rather it shows that CO2 P3 S has a small learn-


ing curve, and that abstraction can have a major impact in
the cost of program development. We have performed a user
study that confirms these observations [11].
For this particular application, the push/pull choice did
not make a significant difference in performance. Was this
obvious in advance? The ability to change a fundamental
property of the parallelism – pushing versus pulling data – Figure 5. CO2 P3 S and MetaCO2 P3 S.
without the user having to write any additional code is a
powerful capability. The user can experiment with different
parameter combinations to find the settings that offer the
best performance. Once this is done, the user then can move learning an environment that may not meet their needs on
to the Intermediate or Native Code Layers of CO2 P3 S to future projects.
do further performance tuning (e.g., modifying the default
To address the extensibility problem, we created
blocking algorithm to improve the granularity).
MetaCO2 P3 S to enable parallel and object-oriented pro-
To summarize, compared to previous pattern-based par-
gramming experts, called pattern designers, to create new
allel programming efforts performance can be enhanced by:
pattern templates. The new pattern templates are first-class,
1. A layered programming model, with the appropriate meaning they are indistinguishable in form and equivalent
code exposed to the user at each level. This gives the in function to the pattern templates included with CO2 P3 S.
user the ability to design, develop, test, and experiment The tool simplifies the task of building pattern templates. In
at the highest level of abstraction, and move to lower particular, it facilitates the parameterization and code gen-
layers of abstraction (if needed) to make incremental eration for the templates.
improvements. It is the responsibility of the pattern designer to identify
2. Generalized patterns—pattern templates—that can be new design patterns. This involves isolating a recurring pat-
customized by parameters. The code generated by a tern and the various forms that it can take based on pattern
parameter setting is tailored to that particular setting, parameters, then creating a framework that hides the paral-
avoiding the overhead of generic code. lelism details. The designer should take note of the aspects
of the framework that are affected by different parameter
4 MetaCO2 P3 S settings. At this point, the pattern is ready to be formalized
Before the sequence alignment program could be im- as a pattern template using MetaCO2 P3 S. Analogous to the
plemented in CO2 P3 S a new parallel design pattern tem- manner in which CO2 P3 S makes it easier to write parallel
plate had to be added. MetaCO2 P3 S is a tool that sup- programs using pattern templates, MetaCO2 P3 S makes it
ports adding new pattern templates to CO2 P3 S. Any design- easier to write pattern templates for CO2 P3 S.
pattern-based tool will be limited by the set of patterns that
The following sections provide a summary of the pattern
it supports. With most of the parallel pattern-based tools
template creation process for CO2 P3 S. Figure 5 illustrates
in the literature, if a user’s application does not match the
the MetaCO2 P3 S design process and how this information
suite of patterns available in the tool, then the tool is ef-
is used in CO2 P3 S. A more thorough explanation of the pro-
fectively useless. Programmers are unlikely to invest effort
cess is available in [5].

Proceedings of the International Conference on Parallel Processing (ICPP’02)


0-7695-1677-7/02 $17.00 © 2002 IEEE
4.1 Pattern Template Creation with MetaCO2 P3 S  The pattern designer must select at least one frame-
MetaCO2 P3 S is launched from the CO2 P3 S GUI and work class that the CO2 P3 S user can use to add
guides the pattern designer through the pattern template cre- application-specific code. Annotations must be sup-
ation process. The pattern designer is required to supply plied to allow CO2 P3 S to generate a non-modifiable
three kinds of information to MetaCO2 P3 S: class names, version of the class, with hyper-links in the user modi-
parameters, and GUI configuration information. fiable locations.
For each class in the pattern template’s framework, a
placeholder class name must be supplied. Since multiple in- 4.3 Pattern Template Creation
stances of a single pattern template can be used in a CO2 P3 S The pattern descriptions created by MetaCO2 P3 S are
application, the placeholder names are replaced by unique in a system-independent XML format. Pattern designers
run-time names in framework instances. This is achieved by can also store partially completed pattern descriptions in
requiring that CO2 P3 S users provide at least one user class this format for later completion. A DTD file comes with
name for their pattern template instances. The remainder of CO2 P3 S that describes the format of the XML pattern de-
the framework classes are uniquely named by adding suf- scription file.
fixes or prefixes to the user-supplied class name. When a completed pattern description is imported into
There are three types of parameters that can affect the CO2 P3 S, the XML is converted into a compiled plug-in
framework implementation of a pattern template. Basic pa- module. XSL is used to transform the pattern description
rameters are the most common, and consist of an enumer- into a Java source file, which is subsequently compiled
ated list of choices supplied by the pattern designer. Ex- and loaded into CO2 P3 S. Since the XML file is system-
tended parameters deal with the less common case where independent, it can be used in template-based environments
the parameter value is of an arbitrary form. Extended list other than CO2 P3 S.
parameters handle the situation wherein the CO2 P3 S user Javadoc is a tool included with the Java distribution
supplies a list of values, which may in turn be basic or ex- whose original purpose was to generate API documentation
tended parameters. for Java libraries in HTML. Javadoc runs a modified Java
The user also has to supply the GUI configuration. Fig- compiler on Java source code files to parse the declarations
ure 2 shows a graphical representation of a CO2 P3 S pattern and specially formatted comments. Javadoc comments have
template. The GUI configuration section of MetaCO2 P3 S the following format:
simplifies the specification of what to display and where. /**
* A description
4.2 Framework Generation *
Given a pattern template and a specific parameterization, * @sampleTag a tag that is parsed by Javadoc
CO2 P3 S generates an appropriate object-oriented frame- */
public void sampleJavaDeclaration()
work instance. The pattern designer must create a frame-
Javadoc was eventually extended to allow pluggable do-
work template to define the code to be generated for the
clets. Doclets are Java programs that satisfy a contract al-
pattern template. It is the pattern designer’s responsibility
lowing them to receive the parsed data from a given Javadoc
to ensure that the framework template is set up correctly
execution. This data includes the declarations from each of
for code generation, and that the generated frameworks are
the parsed classes. Method bodies and field initializations
error-free. An annotated source code template must be writ-
are not provided, since Javadoc ignores them.
ten for each of the classes in the framework. The annota-
CO2 P3 S framework generation is a source code to source
tions supply the information needed to make the following
code transformation. There are two inputs to the process.
transformations during framework generation:
One is a set of Java source code files that have been anno-
 Placeholder class names in the annotated source files tated by the pattern designer for use by Javadoc. The other
must be replaced with the unique names that are sup- is the pattern template parameters selected by a CO2 P3 S
plied by the CO2 P3 S user. user. We have created special tags for the pattern de-
signer, to allow for each of the transformations mentioned
 Methods or variables may be selectively generated
in Section 4.2. Default method bodies are provided in sep-
based on the user’s basic parameter settings. The pat-
arate files, since they are not parsed by Javadoc. The output
tern designer must specify the combination of parame-
is a framework instance that has been specialized to match
ter settings that allow a given construct to be generated.
pattern template parameter settings.
 Portions of method bodies may be selectively gener- 4.4 Wavefront Revisited
ated based on the basic parameter settings.
Since no Wavefront pattern template was available in
 New methods or sections of method bodies may be CO2 P3 S for the sequence alignment problem, we had an op-
generated based on extended or list parameter settings. portunity to use MetaCO2 P3 S to create a new pattern tem-

Proceedings of the International Conference on Parallel Processing (ICPP’02)


0-7695-1677-7/02 $17.00 © 2002 IEEE
plate. Our parallel programming expert had no involvement the method signature. Portions of some methods were
in the research on MetaCO2 P3 S, which also made this ex- set apart to generate for a particular parameter setting.
ercise a test-bed for the usability of our tool. The following
At this point, the pattern template was completely spec-
section provides a detailed description of the steps taken by
ified. The pattern designer imported it into the CO2 P3 S
our expert to create the Wavefront pattern template.
environment, and tested the pattern template prior to im-
The first step was to specify the pattern description us- plementing the sequence alignment program. The pattern
ing MetaCO2 P3 S. After launching the tool, the pattern de- template creation took only a few hours.
signer named the new Wavefront pattern template and sup- To test the coverage and correctness of MetaCO2 P3 S, we
plied an icon to identify the pattern in CO2 P3 S. Next, the tried to regenerate each of the pattern templates from the
placeholder framework class names were supplied. One original CO2 P3 S. Every pattern template has been success-
of these, called WavefrontElement, was selected as a class fully regenerated, and the new standard CO2 P3 S distribu-
to be named by the user. Eight other framework classes tion is the one generated by MetaCO2 P3 S.
were defined, the names of which were made dependent on
WavefrontElement for their uniqueness, with prefixes and/or 4.5 Pattern Template Repository
suffixes added to indicate their role in the framework. The For CO2 P3 S (or any other pattern-based tool) to be ac-
placeholder class names defined in the pattern description cepted as a viable environment for writing parallel pro-
are used to supply run-time names to the code generator. grams, its pattern templates must cover a wide variety of
All the parameters that impact the generated code were parallel problems. If pattern-based programming is to have
specified through the MetaCO2 P3 S GUI. This was an it- the impact in the parallel world that it is having in the se-
erative process. Initially, a parameter set was chosen that quential world, then our community needs to have “open-
met the needs of a specific application (sequence alignment patterns” (analogous to open-source code). Only in this
in this case). Later on, as new applications arose that re- way can the high-level parallel tools research community
quired wavefront parallelism, the pattern was generalized create a critical mass of patterns that will interest practition-
by modifying existing parameters and adding new parame- ers. Since MetaCO2 P3 S enables the creation of new pattern
ters. MetaCO2 P3 S provides an interface that facilitates this templates, the coverage can be made arbitrarily wide. To
process, and reduces the likelihood of the pattern designer facilitate the sharing of pattern templates, we propose that
introducing an error. The result is a Wavefront pattern tem- a repository be created. Since the pattern templates consist
plate that has been used in three different applications [1]. only of XML and Java files, they are system-independent,
The last step in the pattern description process was pro- and can easily be packaged in a downloadable format for
viding a GUI configuration (the result is shown in Figure 2). distribution on the Internet.
At the top, a textual element is displayed that automatically Another advantage to a central repository is the ability
updates to display the user name for the WavefrontElement it provides for pattern templates to be refined as new prob-
class. In MetaCO2 P3 S, the pattern designer needed to pro- lems identify undiscovered parameters or implementation
vide the location for the text, and the framework class name possibilities. Our Wavefront pattern template went through
to display. Below the class name is an image of a wave- several such iterations as we applied it to additional applica-
front. The pattern designer provided the location and image tions. For example, when implementing the matrix product
name. The image below the wavefront and the text element chain application, we discovered the need to access non-
below that are both dynamic representations of the value of neighboring elements in the matrix [1]. Our original pattern
the notification parameter. Using MetaCO2 P3 S, the pattern template did not support this. The modification was accom-
designer defined the images to be used for push and pull to plished by adding a new parameter to the pattern template,
match the possible values of the parameter. and specifying the effect that this new parameter had on the
After providing the pattern description in MetaCO2 P3 S, generated framework code. The Wavefront pattern template
the pattern designer needed to provide annotated framework has also been copied and modified in the repository by a re-
source code for each of the defined classes. This was similar searcher to generate framework code that runs on a network
to writing normal Java source code, with a few exceptions: of workstations rather than a shared-memory machine.

 Some methods were tagged using Javadoc to be condi-


5 Related Work
tionally generated based on a parameter value. Although many research groups have studied parallel
template-based programming environments, few have ad-
 In the WavefrontElement class, some methods were dressed the need for extensibility. Most of these environ-
tagged to allow them to be edited by the CO2 P3 S user. ments are not suited for extension. One exception is the
DPnDP distributed message-passing programming environ-
 Since Javadoc does not parse method bodies, the pat- ment [17]. Like CO2 P3 S, DPnDP design patterns are modu-
tern designer saved them to separate files named after lar, and support a pluggable library. However, DPnDP does

Proceedings of the International Conference on Parallel Processing (ICPP’02)


0-7695-1677-7/02 $17.00 © 2002 IEEE
not provide a tool for creating new patterns, but rather spec- References
ifies a C++ framework under which patterns can be built.
Patterns created using DPnDP can have only a structural [1] J. Anvik, S. MacDonald, D. Szafron, J. Schaeffer, S. Brom-
specification; all behavioral aspects, such as communica- ling, and K. Tan. Generating parallel programs from the
tion and synchronization, must be supplied by the DPnDP wavefront design pattern. In HIPS’02, 2002. On CD-ROM.
user. However, the patterns supplied with DPnDP automat- [2] B. Bacci, M. Danelutto, S. Orlando, S. Pelagatti, and
M. Vanneschi. P 3 L: a Structured High–level Parallel Lan-
ically implement any pattern-specific behaviors. Therefore,
guage, and its Structured Support. Concurrency: Practice
new patterns may not have the same level of functionality
and Experience, 7(3):225–255, 1995.
and abstraction as those provided with DPnDP. [3] A. Bartoli, P. Corsini, G. Dini, and C. Prete. Graphical De-
Another environment that provides template extensibil- sign of Distributed Applications Through Reusable Compo-
ity is Tracs [3]. It provides a tool that allows pattern design- nents. Parallel & Distributed Technology, 3(1):37–51, 1995.
ers to define architectural models using a formal graph to [4] A. Beguelin, J. Dongarra, A. Geist, R. Manchek, and
specify task and communication structures. The architec- K. Moore. HeNCE: A Heterogeneous Network Comput-
tural model does not include a framework implementation. ing Environment. Technical Report UT-CS-93-205, Univ.
of Tenessee, 1993.
Automatic code generation has been studied by many [5] S. Bromling. Meta-programming with parallel design pat-
groups with different agendas. Given our parameterization terns. Master’s thesis, Dept. of Computing Science, Univ. of
needs and language choice, we took our inspiration from Alberta, 2001.
[12, 14]. Also, we studied the COGENT code generator [6], [6] F. Budinsky, M. Finnie, J. Vlissides, and P. Yu. Automatic
which uses macro expansion to generate framework code Code Generation from Design Patterns. IBM Systems Jour-
for sequential design patterns. nal, 35(2):151–171, 1996.
[7] K. Charter, J. Schaeffer, and D. Szafron. Sequence Align-
ment using FastLSA. In METMBS’2000, pages 239–245,
6 Conclusions 2000.
In this paper, two obstacles to the widespread acceptance [8] E. Gamma, R. Helm, R. Johnson, and J. Vlissides. Design
Patterns: Elements of Reusable Object-Oriented Software.
of high-level parallel programming tools are addressed. Al-
Addison-Wesley, 1995.
though this represents an important step forward towards [9] R. Johnson. Frameworks = (Components + Patterns). Com-
moving these tools from academia into practice, much work munications of the ACM, 40(10):39–42, Oct. 1997.
remains to be done. [10] S. MacDonald. From Patterns to Frameworks to Par-
Performance is an issue with every parallel tool, and allel Programs. PhD thesis, Dept. of Computing Sci-
this has been particularly acute with high-level parallel pro- ence, Univ. of Alberta, Nov. 2001. Available at
gramming models. CO2 P3 S resolves many of the perfor- 
www.cs.ualberta.ca/ systems.
[11] S. MacDonald, D. Szafron, J. Schaeffer, and S. Bromling.
mance issues through the use of parameterized parallel de-
From Patterns to Frameworks to Parallel Programs. Parallel
sign pattern templates, a layered model of abstraction, and a Computing, 2002. To appear.
tool to manage the complexities of creating/modifying pat- [12] F. Matthijs, W. Joosen, B. Robben, B. Vanhaute, and P. Ver-
terns. The performance will, in part, be constrained by the baeten. Multi–level Patterns. In Object–Oriented Technol-
quality of the code generated by the pattern template. If the ogy (ECOOP’97), volume 1357 of LNCS, pages 112–115.
ideas presented in this paper catch on, then the community Springer–Verlag, 1998.
can work towards highly optimizing this process to ensure [13] P. Newton and J. Browne. The CODE 2.0 Graphical Parallel
the best possible performance. Programming Language. In ACM International Conference
on Supercomputing, pages 167–177, 1992.
This paper discusses how extensibility, critically lack- [14] M. Pollack. Code Generation using Javadoc.
ing in all template-based systems, can be addressed. We http://www.javaworld.com/javaworld/jw-08-2000/ jw-
have created both a parallel pattern template builder and a 0818-javadoc p.html, Aug. 2000.
structure for framework templates. Our tool generates pat- [15] J. Schaeffer, D. Szafron, G. Lobe, and I. Parsons. The Enter-
tern templates that are first-class, and integrate seamlessly prise Model for Developing Distributed Applications. Par-
with CO2 P3 S. Through system-independence we have en- allel & Distributed Technology, 1(3):85–96, 1993.
abled the creation of a pattern template repository. The best [16] A. Singh, J. Schaeffer, and D. Szafron. Experience with Par-
chance for making pattern-based parallel programming a re- allel Programming Using Code Templates. Concurrency:
Practice & Experience, 10(2):91–120, 1998.
ality in practice rests upon whether the research community [17] S. Siu. Openness and Extensibility in Design–Pattern–Based
can work towards realizing the pattern repository vision, re- Programming Systems. Master’s thesis, Dept. of Electrical
gardless of whether CO2 P3 S or MetaCO2 P3 S is used. and Computer Engineering, Univ. of Waterloo, Aug. 1996.
[18] S. Siu, M. D. Simone, D. Goswami, and A. Singh. Design
Acknowledgments Patterns for Parallel Programming. In PDPTA’96, pages
230–240, 1996.
This research was supported by NSERC and iCORE.

Proceedings of the International Conference on Parallel Processing (ICPP’02)


0-7695-1677-7/02 $17.00 © 2002 IEEE

Vous aimerez peut-être aussi