• No results found

Parallel for Loop and Parallel Reduction: An SMP Comparison of four Languages

N/A
N/A
Protected

Academic year: 2021

Share "Parallel for Loop and Parallel Reduction: An SMP Comparison of four Languages"

Copied!
6
0
0

Loading.... (view fulltext now)

Full text

(1)

Procedia Computer Science 46 ( 2015 ) 900 – 905

1877-0509 © 2015 The Authors. Published by Elsevier B.V. This is an open access article under the CC BY-NC-ND license (http://creativecommons.org/licenses/by-nc-nd/4.0/).

Peer-review under responsibility of organizing committee of the International Conference on Information and Communication Technologies (ICICT 2014) doi: 10.1016/j.procs.2015.02.160

ScienceDirect

International Conference on Information and Communication Technologies (ICICT 2014)

Parallel for loop and parallel reduction: an SMP comparison of four

languages

Tomsy Paul

a,

*, Sheena Mathew

b

aRajiv Gandhi Institute of Technology, Kottayam, Kerala,686501, India

bSchool of Engineering, Cochin University of Science and Technology, Kerala, 682022, India

Abstract

Parallel for loop, a typical example of task parallelism assigns different iterations of the loop to different tasks. In combination with parallel reduction, it is a handy, yet powerful construct for the programmer. We give a joint evaluation of these constructs, under four recent parallel processing languages / libraries on a Symmetric Multi-Processing (SMP) system. The problem used for benchmarking is the evaluation of Pi (π) using trapezoidal rule on the derivative of arc tangent. OpenMP, one of the de-facto standards for shared memory multiprocessing, is found to be the best, on a quad core 64-bit processor on Linux platform. © 2014 The Authors. Published by Elsevier B.V.

Peer-review under responsibility of organizing committee of the International Conference on Information and Communication Technologies (ICICT 2014).

Keywords: Task parallelism;OpenMP;Cilk Plus;Chapel;UPC;parallel for loop;parallel reduction

1. Introduction

Task parallelism1 is a form of parallel processing in which multiple program units (tasks) are executed

simultaneously. The size of a task ranges from lightweight, for example thread, to heavy weight, for example, process. Tasks may share code, data and stack of the program.

* Corresponding author. Tel.: +91-481-2507763.

E-mail address: [email protected]

© 2015 The Authors. Published by Elsevier B.V. This is an open access article under the CC BY-NC-ND license (http://creativecommons.org/licenses/by-nc-nd/4.0/).

Peer-review under responsibility of organizing committee of the International Conference on Information and Communication Technologies (ICICT 2014)

(2)

Parallel for loop is a parallel variant of the common for loop, where different iterations of the loop are automatically assigned to a number of tasks. Although the exact semantics is language dependent, the number of tasks is generally decided by the number of processing elements available, for example, the number of cores in a microprocessor. Reduction is the aggregation of a set of values into a single value, like the summation of an array. Parallel reduction is the same performed in a parallel manner.

Most of the popular Languages for parallel processing are investigated for the said constructs to select the candidates for the comparison. Java2, although very popular, is rejected due to interpreting that could affect the

performance. Scala3 a derivative of Java, additionally do not support parallel for loop. Ada 20124, C#5 and Coarray

FORTRAN6 are also rejected due to the lack of supporting either or both of these constructs. Four parallel

processing Languages viz., OpenMP7,8, Intel Cilk Plus9, Unified Parallel C10,11,12 and Cray Chapel13, that support

both the constructs are identified. All of them except Chapel are extensions to existing languages, mainly C. The compilers of all the four languages are available in the license free and open source realm. All of them are official / third party derivatives of gcc14, and are easily available. The major requirement in the problem selection is the ability

to exploit Task Parallelism, yet avoiding Data Parallelism, to ensure strict evaluation of the former. Array problems are immediately dropped due to the data parallel nature. Another criterion is the naturalness in combining the two parallel constructs under consideration. The evaluation of π using trapezoidal rule on the derivative of arc tangent meets the requirements and has the additional advantage of easy programmability.

The rest of the paper is organized as follows: section 2 provides a brief account of the selected languages consisting of the details of the developers, the history and the salient features. Section 3 gives the algorithm, section 4, the experimental setup, and section 5, the result. Finally section 6 concludes the paper.

2. The languages / libraries 2.1. OpenMP

OpenMP (Open Multi-Processing) is an Application Programmer Interface to incorporate Shared Memory parallel processing into C, C++ and FORTRAN programs. It is a collection of compiler directives, library routines and environment variables. Designed by the Architecture Review Board, a consortium of major hardware and software vendors, OpenMP has been playing a vital role in attracting conventional programmers to parallel programming, since the first version released in 1997, to the latest in July 2013.

OpenMP is designed as an extension to the C / C++ / FORTRAN language. If the OpenMP directives in a program are commented out, a program in the parent language is obtained. In C / C++, the OpenMP directives, characterized by the keyword 'omp', are implemented with the #pragma directive of the compiler. These directives are kept in separate lines so that commenting them out is much easier compared with other parallel extensions of C like UPC and Cilk.

The specification of parallelism is the sole responsibility of the programmer – OpenMP implementations do not bother about race conditions, deadlocks, dependencies, etc.

2.2. Cilk Plus

Originally developed at MIT, Cilk15,16 is now part of Intel. Cilk and Cilk Plus are the extension of C and C++

languages respectively, for multi-threaded parallelism. The most attracting feature of Cilk is that it uses just three keywords to introduce task parallelism. The removal of these three keywords always results in a valid, serial C version of the original program.

Cilk Plus scheduler, as in the case of OpenMP, is based on work stealing that ensures optimal load balancing. Vector instructions unleash the power of multi core processors. Hyper-objects ease concurrent programming by abstracting locks from the programmer.

(3)

2.3. UPC

Unified Parallel C is yet another parallel extension to C Language, the C99 standard. It uses the Partitioned Global Address Space (PGAS) memory model which has the advantages of both shared memory and message passing models. In PGAS, a global address space is partitioned into local addresses. For example a shared array declared with size 100 might spread across 10 threads, each storing 10 elements. The access to the local elements will be faster compared with non-local access.

The first version of UPC, known as version 0.9, was published in May of 1999 as technical report at the Institute for Defense Analyses Center for Computing Sciences. The latest version is 1.3 released in November 2013.

2.4. Chapel

Chapel is a new programming language being developed at Cray Inc. The main design objective is parallel programmability for devices ranging from desktops to super computers. Like UPC, using PGAS model, its scalability and performance is comparable to any parallel language. It also provides Object Orientation, Generic programming support and new generation, non-C programming style built on a reasonably good general purpose language.

Chapel, initially called Cascade, is one of the three languages developed under High Productivity Computing Systems program of DARPA started in 2002., the others being IBM X10 and Sun Fortress. The latest version of Chapel is 1.9.0 released on April 17, 2014.

3. The algorithm

π (3.141592653589793...) is an irrational real number giving the ratio of a circle to its diameter. The value of π has been found out accurately to more than twelve trillion (ͳʹ ൈ ͳͲଵଶ) digits17. A number of algorithms to find the

value of π exist, but we use the trapezoidal rule applied toͳ ሺͳ ൅ ݔΤ, the derivative of–ƒିଵݔ, in the interval 0 to

1. Although this algorithm and its implementation in the languages under consideration are very poor in performance as compared with state of the art techniques to evaluate π, we use it here since this algorithm is typical to illustrate the selected parallel constructs. We give the trapezoidal rule which approximates the integral to a summation.

3.1. Trapezoidal rule - the approximation

Using trapezoidal rule, the integral, which is the area under the curve can be approximated to sum of areas of small rectangular strips. The finer the width of the strip, the better the accuracy is. So the interval between 0 and 1 is finely divided into a large number of rectangular strips, say݊. The width of the strips isͳȀ݊. Now the function ͳ ሺͳ ൅ ݔΤ is evaluated at ݔ ൌ ͲǤͷ ݊Τ ǡ ͳǤͷ ݊Τ ǡ ǥ ǡ ሺ݊ െ ͲǤͷሻ ݊Τ which give the heights of the strips measured at the

middles. It is then multiplied by 4 times the width of the strips and summed up to get the value of π. i.e., ߨ ൌ σሺ௡ି଴ǤହሻȀ௡ͳȀሺͳ ൅ ݔଶ

௫ୀ଴ǤହȀ௡ , approximately.

4. Experimental setup

We do not use state of the art systems, since the objective is to make a comparison of performance. The programs will surely execute faster in a better hardware, but the relative ordering obtained here would be maintained. The programs are developed and executed on an Intel based Linux system – Intel Core i3 3220 @ 3.30 GHz, Quad Core processor with 2 GB RAM on Ubuntu 13.10, 64 bit OS.

(4)

4.1. Compiler setup and program building 4.1.1. OpenMP

gcc supports OpenMP, by default, since version 4.2. We use gcc version 4.6.3. Compiling C programs with OpenMP support is done by adding the flag -fopenmp to the command line argument to gcc.

4.1.2. Cilk Plus

There are two branches of gcc, based on gcc 4.8 and 4.9 that support Cilk Plus. We use the snapshot of gcc 4.9 source code. The compiler is built with the usual procedure of configure, make and make install with GNU make utility. Although the compiler is built for Cilk Plus, the support is not enabled by default. The -fcilkplus flag is required. The runtime environment of Cilk Plus, cilkrts is supplied as a shared library.

4.1.3. UPC

In order to build a UPC application, we need both the UPC runtime environment and the UPC compiler. They can be installed in four different ways. We use the gcc based package available from a third party18, to keep

uniformity with gcc based compilers of the other languages. This package also contains the scheduler, upcrun and the associated runtime environment. The building of the compiler is done in the normal gcc way. The performance of UPC is severely affected by runtime creation of threads. Using the compiler option -fupc-threads-N for static creation of threads results in nearly 8 times faster execution than using the -n option of upcrun.

4.1.4. Chapel

The source code of Chapel compiler is available from the project web page19. The installation is based on GNU

make utility. The runtime environment should be set, but shell scripts are provided for that.

4.2. Programming & time measurement

To have uniformity, parallel for loops in all the four programs have 109 iterations. The reduced result is stored in

a variable of type long double or equivalent. The serial and parallel versions of the program is created and executed. The program execution time is measured, and it gives more or less the same time for executing the for loop and reduction, ignoring the negligible time for execution of other parts of the program. The time is measured using the time command of the shell.

All programs are optimized for speed and / or memory requirements. On gcc back ends, optimization level 3,-O3, is used. For Chapel, the option --fast is used. It may be mentioned that optimization had a very significant impact on the speed of all languages. In the case of Chapel it is more apparent, due to the presence of runtime checks for program correctness, automatically included by the Chapel compiler into the executable, unless optimization is specified.

5. Summary of results

The results are summarized in Table 1, where all times are in seconds. The time for execution of the serial programs are given followed by the time for the parallel and optimized parallel versions.

Table 1. Time of execution to calculate π.

Language / Library Serial (Time in Seconds) Parallel (Time in Seconds) Optimized parallel (Time in Seconds) OpenMP 7.241 3.193 2.747 Cilk Plus 7.044 12.712 6.932 UPC 7.320 13.910 4.506 Chapel 23.742 36.920 3.235

(5)

The results are pictorially given in Fig. 1. where X – axis shows the four languages / libraries and Y – axis shows time in seconds.

OpenMP has the best performance with 2.747 seconds for the parallel-optimized version and with a speed up factor of 2.636 on the Quad core processor. It has the best timings in the serial and parallel categories also. Chapel finished in the second place measuring 3.235 seconds.

All the programs written in, or using, the four languages / libraries find the value of π to an accuracy of 15 decimal digits on parallel versions. In the case of serial versions, Chapel program gives an accuracy of only 13 digits while all others give 15 digits accuracy.

All languages / libraries except OpenMP have worse timings for non-optimized parallel versions than that of corresponding serial versions. This may be explained by the fact that the basic parallel programming model of OpenMP is Shared Memory model whereas for others it is not - UPC and Chapel use PGAS while Cilk Plus use Message Passing Interface.

6. Conclusion

The speed of execution of programs written in four parallel languages / libraries, making use of the same parallel constructs, on a tightly coupled SMP system, are measured. OpenMP, the de-facto standard for shared memory processing has the best performance, with 2.747 seconds and with a speed up factor of 2.636. All languages / libraries except OpenMP have worse timings for non-optimized parallel versions than that of corresponding serial versions, which may be attributed to the differences in the default parallel architecture.

Acknowledgements

Sincere thanks to Tom MacDonald, Chapel Manager, Cray Inc. for his valuable suggestions that helped us a lot.

References

1. Quinn MJ. Parallel Programming in C with MPI and OpenMP. New York: McGraw-Hill Inc.; 2004. 2. Gosling J, Joy B, Steele G, Bracha G. The Java™ language specification. Addison-Wesley; 2005

3. Odersky M, Altherr P, Cremet V, Dragos I, Dubochet G, Emir B, McDirmid S, Micheloud S, Mihaylov N, Schinz M, Stenman E, Spoon L, Zenger M. An Overview of the Scala Programming Language, Technical Report LAMP-REPORT-2006-001, EPFL, Switzerland 2006.

(6)

4. Ada Reference Manual, ISO/IEC 8652:2012(E). Retrieved August 2014, from www.ada-auth.org/standards/12rm/RM-Final.pdf 5. C# Reference Manual, Version 4.0. http://msdn.microsoft.com/en-IN/library/618ayhy6.aspx,lastly accessed on 5/8/2014. 6. Numerich RW and Reid J. Co-array Fortran for parallel programming. SIGPLAN Fortran Forum, 1998; 17(2):1–31.

7. Dagum L and Menon R. OpenMP: An industry-standard API for shared-memory programming. IEEE Computational Science and

Engineering, January–March 1998;5(1):46–55.

8. Chandra R, Menon R, Dagum L, Kohr D, Maydan D, McDonald J. Parallel programming in OpenMP. Morgan Kaufmann; 2000. 9. McCool M, Reinders J, Robison A. Structured parallel programming: patterns for efficient computation. Morgan Kaufmann; 2012.

10. Carlson WW, Draper JM, Culler DE, Yelick K, Brooks E, Warren K. Introduction to UPC and language specification. Technical Report

CCS-TR-99-157, Center for Computing Sciences, Maryland, USA 1999.

11. El-Ghazawi T, Carlson W, Sterling T, Yelick K. UPC: Distributed shared-memory programming. Wiley-Interscience, 2005. 12. UPC Language Specification, version 1.3. Retrieved July 2014, from http://upc-lang.org.

13. Chamberlain BL, Callahan D, Zima HP. Parallel Programmability and the Chapel Language. IJHPCA, August 2007, 21(3): 291-312. 14. https://gcc.gnu.org/, lastly accessed on 5/7/2014.

15. Cilk 5.4.6 Reference Manual, MIT Laboratory for Computer Science. Retrieved July 2013 from supertech.csail.mit.edu/cilk/manual-5.4.6.pdf 16. Blumofe RD, Joerg CF, Kuszmaul BC, Leiserson CE, Randall KH, Zhou Y. Cilk: An Efficient Multithreaded Runtime System. Proc. of the

Fifth PPoPP 1995. p. 207–216.

17. http://www.numberworld.org/misc_runs/pi-12t/, lastly accessed on 12/7/2014. 18. http://www.gccupc.org/download, lastly accessed on 29/7/2014.

References

Related documents

Abstract: Limnological survey (October 2013 – September 2015) of Maghuri, Khamti Guali and No.11 floodplain lakes (beels) of the Dibru-Saikhowa Biosphere Reserve

Since our aim was to produce metal ion beams (especially from Gold and Calcium) with good stability and without any major modification of the source (for

Biohydrogen, which is another form of renewable energy also has been proven feasible to be produced from different types of organic wastes which include municipal solid waste

Put a check in Incl (Include) column next to each company to which you want to copy the report; then click the Next button. The system displays the Select

It is possible that colonial ties not only affect the level of food aid shipped from donor to recipient country, but also the responsiveness of aid to recipient needs.. This

UNCHS (Habitat) provides network support services for the sharing and exchange of information on, inter alia, good and best practices, training and human resources development,

If the exhaust valve is stuck in the closed position, either open the neck seal or a wrist seal to release air.When this emergency procedure is followed, some water will enter

DC Motor Drive Commercial and Residential Jackshaft Operators Parts