A tool supporting C code parallelization Ilona Bluemke, Joanna Fugas Institute of Computer Science, Warsaw University of Technology Nowowiejska 15/19, 00-665 Warsaw, Poland
[email protected] Abstract - In this paper a tool, called ParaGraph, supporting C code parallelization is presented. ParaGraph is a plug-in in Eclipse IDE and enables manual and automatic parallelization. A parallelizing compiler inserts automatically OpenMP directives into the outputted source code. OpenMP directives can be also manually inserted by a programmer. ParaGraph shows C code after parallelization. Visualization of parallelized code can be used to understand the rules and constraints of parallelization and to tune the parallelized code as well.
I.
INTRODUCTION
Parallel programming has been attracting programmers and researchers attention for many years. At the beginning parallel code was simultaneously executed on processors of a supercomputer. Currently many cores are present even in modern PC so they can be used to run parallel code as well. Sequential program code can be parallelized and simultaneously executed on multiple cores. Parallelization is a very difficult task and may cause many runtime errors so some methods and tools facilitating this process are necessary. Parallel code can be prepared by a programmer or automatically by some compilers. As both approaches have advantages and disadvantages, some of them are mentioned in section II, it seems that a tool enabling for manual and automatic parallelization can be very useful in the production of fast programs. Many tools have been built to support automatic or/and manual code parallelization. SUIF Explorer [1] combines static and dynamic compiler analysis with indications given by programmer. In compiler of Fortran 77 Polaris [2] directives introduced by user are used in the process of translating code into parallel dialect of Fortran. ParaWise [3] is able to generate parallel code for distributed or for multiprocessor system. HTGviz [4] also enables manual and compiler parallelization. The result is a program in the same source language with inserted OpenMP directives. Additionally visualization tool shows the static control flow graph of the program, with data dependences. At the Institute of Computer Science Warsaw University of Technology a tool, called ParaGraph, was designed and implemented. In ParaGraph code in C programming language can be manually, as well as automatically, parallelized and presented in a graphical form. To our best knowledge there are no similar tools dedicated to C programming language. Usually
programmers have difficulties writing code which can be highly parallelizable so code visualization may be very useful in teaching how to built easily parallelizable program. ParaGraph was designed as a tool which can be used in compiler construction course. The presence of back-end information was identified by Binkley et al. in Feedback compiler [5] as very important in teaching compiler construction. ParaGraph is platform independent, it is a plug-in in Eclipse IDE. The organization of this paper is as follows. The main approaches to parallelization are briefly presented in section II. Section III contains the description of ParaGraph. In section IV examples showing the usage of our tool and its advantages are given. Section V contains some conclusions. II.
CODE PARALLELIZATION
Code of a program can be parallelized automatically by a parallelizing compiler or a programmer can identify all parallelizable fragments and implement the parallel code. OpenMP [6] is an environment in which programmer is able to decide where to insert parallelizing directives indicating the parallel code. The compiler then uses platform specific mechanisms to make the program executable in parallel on multiple processors. Programmer, knowing the implemented algorithm, can precisely indicate code suitable for parallelization and accelerate the execution of the algorithm. On the other hand an inexperienced programmer can slow down the execution of a program, make it unstable or even introduce some races. A parallelizing compiler works automatically, is not driven by user, so the parallelization is very limited. Compilers, which are independent of the platform, usually perform only static analysis and are able to efficiently parallelize loops. If in a loop there are no data dependences between loop iterations, it can be easily parallelized. Otherwise a synchronization of data is needed thus decreasing the efficiency of generated program. Furthermore, loops which are parallelized automatically usually contain only few instructions, so the parallelization granularity is fine and the speedup in execution time is not very convincing. Finding data dependence constraints is the basic step in detecting loop level parallelism in a program [7]. Briefly, the data dependence determines whether two references to the same array within a nest of loops may reference to the
same element of that array. Many algorithms have been proposed to solve the problem by analyzing the linear equations formed by a pair of array references. Data dependence test, which is very important in automatic parallelization, is applied to array accesses in a loop. Compiler can only determine dependences between a pair of affine (linear) accesses. Examples of affine and non affine accesses are given in listing 1.
operation is presented in figure 1. An external compiler is used to generate parallelized code and a file containing the control flow graph of compiled program. The graph is shown in a graphical editor, with textual information accessible in “properties view” (Fig. 4). A direct link from blocks on the graph, to the source code after parallelization, is kept to help the programmer access the fragment of code, which seems interesting to her/him.
1. 2. 3. 4. 5. 6.
for( i = 0; i