• Aucun résultat trouvé

Algorithmic Skeletons Using Template Metaprogramming

N/A
N/A
Protected

Academic year: 2021

Partager "Algorithmic Skeletons Using Template Metaprogramming"

Copied!
4
0
0

Texte intégral

(1)

HAL Id: hal-02573826

https://hal.archives-ouvertes.fr/hal-02573826v2

Submitted on 18 Dec 2020

HAL is a multi-disciplinary open access

archive for the deposit and dissemination of

sci-entific research documents, whether they are

pub-lished or not. The documents may come from

teaching and research institutions in France or

abroad, or from public or private research centers.

L’archive ouverte pluridisciplinaire HAL, est

destinée au dépôt et à la diffusion de documents

scientifiques de niveau recherche, publiés ou non,

émanant des établissements d’enseignement et de

recherche français ou étrangers, des laboratoires

publics ou privés.

Algorithmic Skeletons Using Template

Metaprogramming

Alexis Pereda, David R.C. Hill, Claude Mazel, Bruno Bachelet

To cite this version:

Alexis Pereda, David R.C. Hill, Claude Mazel, Bruno Bachelet. Algorithmic Skeletons Using

Tem-plate Metaprogramming. 14th International Student Conference on Advanced Science and Technology

(ICAST), Nov 2019, Kumamoto, Japan. pp.204-205. �hal-02573826v2�

(2)

Algorithmic skeletons using template metaprogramming

Alexis Pereda*, David R.C. Hill, Claude Mazel, Bruno Bachelet

Université Clermont Auvergne, CNRS, LIMOS, Clermont-Ferrand, France

{alexis.pereda, david.hill, claude.mazel, bruno.bachelet}@uca.fr

Abstract

Algorithmic skeletons, introduced by Cole, were designed to ease the development of parallel software. This article presents a way to represent and implement algorithmic skeletons using bones – atomic elements – to build struc-tures, and data flow graphs to link the structures.

We design and implement a library relying on Template Metaprogramming (TMP) to describe and use both skele-tons and links to produce automatically either a sequential or a parallel implementation of the algorithm, aiming slight to no run-time overhead compared to handwritten imple-mentations.

Performance results of this library, applied to metaheuris-tics in Operations Research (OR), are presented to that this approach induces negligible run-time overhead.

Keywords: algorithmic skeletons, parallelization,

tem-plate metaprogramming.

1

Introduction

Most computers having multiple cores, developing parallel software has become necessary in order to make full use of the available hardware. This has led to the development of numerous tools to ease the implementation of parallel programs, from low level techniques (e.g. specific compilers) to more high level abstractions (e.g. generic libraries).

Our objective is to propose a new parallelization tool that is usable in existing projects (i.e. no new language or specific compiler is needed) and yet not inducing an avoid-able run-time overhead when compared to a handwritten implementation. Additionally, we want this tool to provide a clean interface, not requiring to pollute the domain code with parallelization details. This last point oriented our solution towards algorithmic skeletons which enable sepa-ration of domain code and parallelization implementation. The advantage of libraries over most low level techniques is their portability. However, this usually comes with a cost: an abstraction layer producing a less efficient binary than the equivalent handwritten code, which a compiler would be able to produce. Metaprogramming can be seen as an intermediary approach because it makes it possible to produce code without rewriting a full-fledged compiler. Specifically, the C++ language offers Template Metapro-gramming (TMP) allowing metaproMetapro-gramming at library

level.

This paper presents our proposal for a new algorithmic skeleton library in C++, using an example application from Operations Research (OR), a Greedy Randomized Adap-tive Search Procedure (GRASP) described in algorithm 1. Its goal is to find the best solution S, given a problem P . It is done by generating and improving multiple indepen-dent solutions, making it suitable for parallelization.

Algorithm 1 GRASP function GRASP(P ) for i = 1..N do Si← constructiveHeuristic(P ) Si← localSearch(P, Si) end for S← select({S1, S2, ..., SN}) return Send function

2

Algorithmic skeletons

Algorithmic skeletons were designed by Cole [3] to ease the development of parallel software by providing patterns to be used to describe an algorithm so that it will then be automatically parallelized. Numerous tools based on this concept exist, Skandium [6] in Java, working at run-time, Quaff [5] and Muesli [2] in C++, based on TMP, and SkePU 2 [4] which also makes use of TMP but relies on a pre-compilation step. None of these implementations per-mit the complete representation of an algorithm, including its sequential parts. This effectively reduces the possible code coverage of these algorithmic skeleton tools. Being able to get all this information in a single skeleton enables better results when making decisions about how tasks must be orchestrated.

2.1

Structure

An algorithmic skeleton represents an algorithm whose overall structure is known, but some details can be defined in a later step. This structure must be described by the developer. For this purpose, we provide atomic elements, called bones, each one implementing a specific sequential or parallel pattern such as a sequence of tasks or a farm [1].

(3)

Both bones and compound structures can be used to build new structures.

Algorithm 1 presents an algorithm, GRASP, whose struc-ture is composed of a loop, repeating a sequence of 2 tasks (a constructive heuristic (CH), to build a random solution, followed by a local search (LS) that improves the solu-tion), then a sequential instruction that selects (Sel) the best solution. Figure 1 is a representation of this GRASP structure.

CH ... CH

LS ... LS

Sel

Figure 1: GRASP structure

2.2

Muscles

The circles in figure 1 are slots for tasks yet to be defined. These are called muscles in algorithmic skeleton termi-nology and are comparable to functions. For our library, these are implemented by regular C++ functions. This demonstrates the separation between domain code, written in muscles, and the parallelization details, written in bones and used through skeletons (i.e. structure and links). It also allows existing code to be easily used with our library.

2.3

Links

Apart from structure, our library requires the developer to define the data flow graph, that we named links, which de-scribe how data is transferred between all tasks executions. This part is usually automatically done by the libraries, however this implies less flexibility and add constraints when defining tasks. In addition, having links explicitly defined enables potential optimizations through TMP and helps producing better implementations (e.g. by avoiding copies).

A task to execute can be either a muscle or a skeleton, in both cases it behaves as a callable. For that reason, links are described using function signatures, which contain the return type and the parameter list. Our library provides placeholder types to make the links. For example, it is

10 20 30 40 50 60 70 80 90 5 10 15 20 25 30 Time (seconds)

Number of GRASP Iterations Handwritten

Automated

Figure 2: Execution time depending on the number of iterations

possible to write that a muscle accepts as first parameter the return value of its predecessor, or the second argument of its caller. This type is then replaced by the corresponding actual type.

3

Performance results

We used Template Metaprogramming (TMP) in order to avoid inducing run-time overhead when compared to a handwritten implementation. To validate that objective, we ran performance measures on two versions of an al-gorithm to solve Travelling Salesman Problem (TSP) in-stances: a handwritten one and another generated by our library. The algorithm is a Greedy Randomized Adaptive Search Procedure (GRASP) whose local search is imple-mented by an Evolutionary Local Search (ELS), named GRASPxELS. It offers two distinct parallelizable levels. These tests have been performed on an Intel Xeon CPU E5-2670 v2 at 2.50 GHz with 20 physical cores and compiled using g++ 8.2.0 with the O2 optimization flag activated. All figures result of means of 20 runs, where seeds for the random number generation were controlled to ensure repeatability (i.e. that every run, independently of the number of threads allocated, performs the same amount of operations and provides the same result).

Figure 2 shows the comparison between handwritten and automatically generated GRASPxELS for a sequen-tial implementation, with a varying number of iterations from 5 to 30 for the outer GRASP loop. No significant run-time overhead is noticeable. Figure 3 also results of the comparison between handwritten and automatically generated GRASPxELS but for a parallel implementation, with a fixed number of iterations and a varying number of allotted cores. Similarly, no significant run-time overhead was measured.

Based on these measures, we conclude that we achieved an implementation of algorithmic skeletons that performs

(4)

2 4 6 8 10 12 14 16 18 20 2 4 6 8 10 12 14 16 18 20 Time (seconds) Number of Cores Handwritten Automated

Figure 3: Execution time depending on the number of cores

as well as a handwritten solution. It enables developers to describe their algorithms entirely, sequential as well as parallelizable parts, and to define how the data is trans-ferred between tasks. The described skeletons can then be completed by providing simple functions whose signatures correspond to the slot they try to fill. The knowledge the library has got, thanks to these algorithmic skeletons, enables compile-time algorithm analysis and more suited implementations.

References

[1] Duncan K. G. Campbell. Towards the Classification

of Algorithmic Skeletons. YCS 276. University of York

department of computer science YCS, 1996 (cit. on p. 1).

[2] Philipp Ciechanowicz, Michael Poldner, and Herbert Kuchen. “The Münster Skeleton Library Muesli - a Comprehensive Overview”. In: (2009) (cit. on p. 1). [3] Murray Cole. “Bringing Skeletons out of the Closet:

A Pragmatic Manifesto for Skeletal Parallel Pro-gramming”. In: Parallel Computing 30.3 (Mar. 2004), pp. 389–406. issn: 01678191. doi: 10.1016/j.parco. 2003.12.002 (cit. on p. 1).

[4] August Ernstsson, Lu Li, and Christoph Kessler. “SkePU 2: Flexible and Type-Safe Skeleton Program-ming for Heterogeneous Parallel Systems”. In:

Inter-national Journal of Parallel Programming 46.1 (Feb.

2018), pp. 62–80. issn: 0885-7458, 1573-7640. doi: 10.1007/s10766-017-0490-5 (cit. on p. 1).

[5] J. Falcou, J. Sérot, T. Chateau, and J. T. Lapresté. “Quaff: Efficient C++ Design for Parallel Skeletons”. In: Parallel Computing. Algorithmic Skeletons 32.7 (Sept. 2006), pp. 604–615. issn: 0167-8191. doi: 10. 1016/j.parco.2006.06.001 (cit. on p. 1).

[6] Mario Leyton and José M. Piquer. “Skandium: Multi-Core Programming with Algorithmic Skeletons”. In:

2010 18th Euromicro Conference on Parallel, Dis-tributed and Network-Based Processing. 18th

Euromi-cro International Conference on Parallel, Distributed and Network-Based Processing (PDP 2010). Pisa: IEEE, Feb. 2010, pp. 289–296. isbn: 978-1-4244-5673-4. doi: 10.1109/PDP.2010.26 (cit. on p. 1).

Figure

Figure 1: GRASP structure
Figure 3: Execution time depending on the number of cores

Références

Documents relatifs

This work shows that the overhead of reflective operations and metaobject protocols can be eliminated based on a generalized no- tion of polymorphic inline caches called

At the same time, how- ever, the RO approach also tempers the AO here: because there is an objective reality underlying the concepts of the domain experts, there is room for critique

The Diagram Type Agent consists of the developer-written code and is in charge of creating elements of the Pictogram Model that provide a graphical representation of elements of

We built a miniature model of a production line that implements such a sys- tem using modern standards for distributed industrial control systems, IEC 61499 and OPC-UA.. We show

To do so, we leveraged the metamodeling capabilities provided by MDE environments, which allowed us to design a DEVS metamodel, but also to automate many operations

support of good scientific research, formulation compliant with the domain, allowing for any kind of agents and any kind of approximators, interoperability of components (the Q

Et n'est-il pas raisonnable de dire que dans cette ruche où la colonie trouve plus d'hygiène, plus de con- fort, elle doit être plus vigoureuse et donner un meilleur

Gabarro-Lopez, S & Meurant, L 2014, 'When nonmanuals meet semantics and syntax: towards a practical guide for the segmentation of sign language discourse', 6th Workshop on