Jflow: Practical Refactorings for Flow-Based Parallelism

Jflow: Practical Refactorings for Flow-Based Parallelism

View metadata, citation and similar papers at core.ac.uk brought to you by CORE provided by Illinois Digital Environment for Access to Learning and Scholarship Repository JFlow: Practical Refactorings for Flow-based Parallelism Nicholas Chen, Ralph E. Johnson Department of Computer Science University of Illinois at Urbana-Champaign nchen, rjohnson @illinois.edu f g Abstract—Emerging applications in the domains of recognition, coupling between different parts of the software, making it mining and synthesis (RMS); image and video processing; data easier to maintain and evolve each part independently. warehousing; and automatic financial trading admit a particular A compelling way to leverage flow-based parallelism is style of parallelism termed flow-based parallelism. To help devel- opers exploit flow-based parallelism, popular parallel libraries to refactor existing sequential code to use the constructs of such as Groovy’s GPars, Intel’s TBB Flow Graph and Microsoft’s a parallel library such as Groovy’s GPars [4], Intel’s TBB TPL Dataflow have begun introducing many new and useful Flow Graph [5] or Microsoft’s TPL Dataflow [6]. Our prior constructs. However, to reap the benefits of such constructs, work examined the constructs in an older version of Intel’s developers must first use them. This involves refactoring their TBB and found them expressive enough to address many existing sequential code to incorporate these constructs – a manual process that overwhelms even experts. To alleviate this of the common idioms found in applications [7]. We found burden, we introduce a set of novel analyses and transformations using such constructs to be more advantageous compared to targeting flow-based parallelism. We implemented these ideas direct parallelizing with low-level threads. Firstly, programs in JFlow, an interactive refactoring tool integrated into the written using parallel constructs were more succinct and easier Eclipse IDE. We used JFlow to parallelize seven applications: four to evolve because the library provides useful constructs for from a previously known benchmark and three from a suite of large open source projects. Our evaluation on these applications adding/removing nodes or edges to a computation graph. Sec- demonstrates that JFlow, with some minimal interaction from ondly, in some cases, code parallelized using library constructs the developer, can successfully parallelize applications from the were faster than code parallelized directly with low-level aforementioned domains with good performance (offering up to threads because the library has better support for managing 3.45x speedup on a 4-core machine) and is fast enough to be and coordinating threads through a thread pool. used interactively as part of a developer’s workflow. To refactor their code to use such constructs, developers face two overwhelming tasks: analysis and transformation of I. INTRODUCTION their sequential code. First, a developer has to partition the The term “flow-based parallelism” is coined after Morri- original sequential code into a computation flow graph with son’s Flow-Based Programming: A New Approach to Appli- nodes and edges. She must scrutinize each node to ensure that cation Development [1]. Flow-based parallelism is a parallel no data races exist. Given a large and unfamiliar code base, programming paradigm that partitions an expensive computa- this is hard even for experts. Second, once she is convinced tion into a directed graph, i.e., a computation flow graph. Each that there are no data races, she still has to meticulously write node in the graph embodies part of the original computation repetitive, boilerplate code to create the nodes and link the and the edges between nodes represent dependencies. Data edges between nodes. Given a large computation graph, there flow between nodes. Nodes perform their computation when all could be many nodes and edges, and manually writing code their data dependencies are available. Parallelism is achieved to describe them is tedious. How can we assist developers in when nodes can operate concurrently. Examples of flow- analyzing and transforming their sequential programs? based parallelism include pipeline parallelism, event-based Parallelizing compilers attempt to relieve the burden of coordination and the wavefront pattern [2], [3]. The structure analyzing and transforming the code in an entirely automated of the graph is usually simple, e.g., in the case of pipeline manner, without involving the developer. While appealing, parallelism but could also be more complex, e.g., in the case even the most advanced static analysis in the compiler are of wavefront computations. frequently confounded by common programming idioms that Flow-based parallelism offers many advantages. It is well- abound in typical object-oriented programs, forcing the com- suited for parallelizing emerging applications in the domains piler to be overly pessimistic and precluding many paralleliza- of recognition, mining and synthesis (RMS); image and video tion opportunities. Kim et al. [8] tested two commercial C/C++ processing; data warehousing; and automatic financial trading compilers on the OmpSCR benchmarks [9] and found that, (SectionIV). Using flow-based parallelism not only improves at best, the compilers could only automatically parallelize 4 the performance of such applications but also their modular- out of 13 loops although loop parallelism had been studied ity. By partitioning the computation into nodes of a graph since the first parallelizing compilers [10]. They attributed that communicate via explicit parameters, we can reduce the the reasons for failure to pointer based accesses, complex control flow and insufficient cost-benefit analysis. Even state readable source code to describe the computation flow graph. of the art static analysis for object-oriented program [11]– The ideas behind our analyses and transformations are general [13] have trouble reasoning about many best practice idioms. and can be adapted for different languages and frameworks. For instance, in the applications we evaluated, we found that Second, we incorporated our analyses and transformations into the use of static factory methods, logging constructs and, in our interactive tool, JFlow. JFlow works with Java applications general, the use of fairly standard library APIs confuse the and targets the constructs from Groovy’s GPars parallel library. static analysis and force it to be safe but overly conservative. We evaluated JFlow on seven applications from different Common techniques for increasing the precision of static emerging domains. We report the parallel speedups and discuss analysis (at the expense of memory and running time) e.g., the user interactions necessary for each application. increasing k for k-object sensitivity [14] or n for call-string- The source code for JFlow and the applications that we sensitivity [15], do not help. evaluated are available at http://vazexqi.github.io/JFlow/. While it is difficult for static analysis to reason about such idioms, it is easier for a human. Thus, we propose a practical II. MOTIVATING EXAMPLE approach that combines static analysis with human interaction. Consider LIRe (16K SLOC), an open source Java content- Our approach actively engages the developer, i.e., the domain based image retrieval (CBIR) library [17]. LIRe takes a query expert in the parallelization process. We adapt ideas from image, extracts features from it and, based on those features, human automation and divide the tasks between developer retrieves similar images from a database of candidate images. and tool such that each performs what each excels at [16]. Typical features that are extracted using computer vision The developer performs the high-level reasoning task that tools techniques include color histograms, shapes and textures. have problems with — identifying which parts of the original In LIRe, the main bottlenecks to performance are the computation to partition — whereas the tool handles the low- indexing and retrieval stages. This example focuses on the level analysis task that developers find tedious — analyzing if indexing stage. In the indexing stage, a set of images is the partitions have data races and generating the parallel code. analyzed to build the database of candidate images. During This combination is effective. It enables us to parallelize many the analysis, features are extracted from the images and stored more applications than would have been possible through static in the database. Because there isn’t a single feature that works analysis alone. across all images, multiple features are usually extracted and We implemented this interactive approach in our tool, JFlow. stored in the database. The bottleneck in the indexing stage JFlow statically analyzes the code and reports back to the comes from the number of features extracted and the number developer. As a tool, JFlow has high utility and is useful of images that need to be analyzed (typically in the hundreds in many scenarios. When the analyses are successful, the of thousands for a decent size database). tool performs the transformation, generating source code that Figure1 shows the indexing loop for LIRe with four feature targets the constructs of a parallel library. Even when the extractors. Consider a developer who decides to parallelize analyses fail, the tool is useful — it pinpoints and reports the this loop using flow-based parallelism. She decides to partition problems. This allows the developer to either fix the problems each feature extractor into its own node. The flow graph for and retry, or proceed with the transformation directly if she such a partition, i.e., a pipeline, is shown on the right hand side deems the reported problems innocuous (e.g., as determined by of the figure. How could she make use of JFlow to parallelize her suite of test cases). JFlow can even be used exploratorily: her code? Three steps: annotate, extract nodes and invert loop. if the developer wishes to inspect for data races, she could First, she would need to annotate her desired partitioning; use the tool to analyze the code, view the results and forego we use simple comments for now. While there have been prior the transformation step.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    11 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us