• No results found

Discontinuous Galerkin shallow water solver on Cuda architectures

N/A
N/A
Protected

Academic year: 2021

Share "Discontinuous Galerkin shallow water solver on Cuda architectures"

Copied!
8
0
0

Bezig met laden.... (Bekijk nu de volledige tekst)

Hele tekst

(1)

9th International Conference on Hydroinformatics HIC 2010, Tianjin, CHINA

DISCONTINUOUS GALERKIN SHALLOW WATER SOLVER ON

CUDA ARCHITECTURES

D. SCHWANENBERG

Operational Water Management, Deltares, Rotterdamseweg 185 Delft, 2600 MH, The Netherlands

S. HORSTEN, S. ROGER

Institute of Hydraulic Engineering and Water Resources Management RWTH Aachen University, Hydraulic Laboratory Kreuzherrenstraße 7

Aachen, 52056 Aachen, Germany

We discuss the implementation of a Runge Kutta Discontinuous Galerkin (RKDG) scheme for solving the two-dimensional depth-averaged shallow water equations on a graphical processing unit (GPU) using the CUDA API. Due to the compact formulation of the scheme it is well suited for parallelization and hardware acceleration by general purpose GPUs. The performance of the code is compared twice, on the one hand against a standard serial code, and on the other hand against parallelization on multi-core CPUs. Furthermore, we discuss the speed-up benefit from the point of view of practical engineering applications and compare it against the effort of conducting the code parallelization.

INTRODUCTION

Standard Galerkin finite element methods provide unsatisfactory results for advection-dominated flows. Since continuous finite elements imply energy conservation, the numerical solution shows oscillations in advection-dominated parts of the solution and at shocks [1]. One breakthrough was achieved by the introduction of a streamline upwind (SU) weighted test function by Hughes & Brooks [6] and its application to shallow water flows by Katopodes [7]. The upwinded test function produces a sufficient amount of dissipation to dampen the oscillations and decrease the energy head at jumps. A major difficulty of SU methods is to restrict the use of this dissipation to non-smooth regions of the solution, in order to prevent decreases in accuracy in the smooth regions. Most SU methods use implicit time integration. An explicit formulation seems to be useful only for very unsteady flows requiring a CFL number close to 1, in order to obtain sufficient accuracy in time [8]. However, the explicit application of the SU method seems to be inefficient compared to that of the finite volume methods because the latter require the solution of a linear equation system at every time step for decoupling the mass matrix.

In this paper, we present a scheme based on a Discontinuous Galerkin (DG) finite element method for spatial discretization [3]. The discrete variables on the nodes of the

(2)

inter-cell boundaries are shared by two elements. For a discontinuous discretization each element has its own discrete variable at the inter-cell boundary forming a discontinuity. A main advantage of the DG method over continuous finite element methods with explicit time integration is the completely decoupled mass matrix obtained by using orthogonal shape functions. This avoids the solution of linear equation systems to invert the mass matrix while using an explicit Runge Kutta (RK) time integration. Furthermore, the computation of a numerical flux at the inter-cell boundaries introduces upwinding into the scheme while keeping the Galerkin test function in the element. The DG method was originally implemented to the shallow water equations (SWE) by Schwanenberg & Köngeter [13]. Schwanenberg & Harms [14] and Roger et al. [11][12] present applications to inundation modeling and dam-break flows. Further examples are shown in Ghostine et al. [5], Bunya et al. [2] and Ern et al. [4].

Recently, the developments in computer hardware move away from increasing clock speed towards providing many computational cores that operate in parallel. This is true for general purpose central processing units (CPUs), but in particular for general purpose graphics processing units (GPGPUs). Recent work on the parallelization of the DG scheme for Maxwell’s equations for GPGPUs [9] show the computational potential of the scheme on massive parallel hardware. Keeping in mind the time intensive computations for large scale inundation and dam-break simulations, we investigate the parallel efficiency of the DG method in application to the SWE. Focusing on typical engineering applications applied by small and medium-size consultants, we concentrate on computers with multi-core CPUs and / or additional GPGPUs, and neglect computational clusters. This limits the parallelization methods to OpenMP and special toolkits for accelerator cards such as the CUDA API. Typical techniques for clusters such as domain decomposition with message passing are not considered in our research. The reader is referred to Neal et al. [10] for a more general overview about parallelization techniques in inundation modeling.

HYDRAULIC MODEL

The mathematical description of a depth-averaged incompressible fluid is given by the 2D depth-averaged shallow water equations in the form

) ( )) ( ), ( (F U GU S U U t (1) where

(3)

q p h U , ( ) ² 1 ² 2 p p gh h pq h F U , ( ) ² 1 ² 2 q pq h q gh h G U , (2) ) ² ² ² ( ) ² ² ² ( 0 ) ( 3 / 10 3 / 10 h q p q n z gh h q p p n z gh b y b x U S (3)

in which h = water depth; p, q = unit discharge in x and y-directions; g = acceleration due to gravity; = fluid density; and zb = channel bed elevation. Bed roughness is approximated by the empirical Manning formula with Manning’s roughness coefficient n.

The weak finite-element formulation of the equations is given by

( ) ( , ) h h x y h h h K K K K d v dK n n v d v dK v dK dt U F G F G S (4)

Here, nK = (nx, ny)T is the unit vector outward normal to the element boundary of the finite-element K, vh is an arbitrary smooth test function, and Uh is the approximation of U. Since the RKDG method allows for variables at the element edges to be discontinuous, the inter-cell flux depends on the values Uh in each of the two elements. It is therefore not uniquely defined and is replaced by a numerical flux H. The approximated variable Uh can be expressed as a sum over the products of discrete variables Ul and shape functions l,

l l l

h(x,y) U (x,y)

U (5)

Using the standard Galerkin approach, shape functions and test functions are identical. Rewriting equation (4), the DG space discretization can be summarized by a system of ordinary differential equations as

( )

h h h d

dtMU L U , (6)

where M is the mass matrix and Lh is an operator describing the spatial discretization. By using orthogonal shape functions, the mass matrices M in the linear equation system (6)

(4)

become diagonal. For triangular elements, a linear shape function can be obtained by choosing a function that takes the value of 1 at the mid-point mi of the i-th edge of a triangle, and the value of 0 at the midpoints of the other two edges. Thus, the diagonal mass matrix can be expressed as follows:

1 1 1 ( 3, 3, 3) K diag

M (7)

The integrals are approximated by a three mid-point rule for the triangles and a two-point Gauss integration for the line integrals.

The equations (6) are integrated in time as follows by using the following second-order two-step TVD Runge Kutta method for a linear space discretization,

1 1 1 1 1 1 1

( ), 2 2 2 ( )

n n n n

h h t h h h h h t h h

U U L U U U U L U (8)

A slope limiter is applied on each step of the Runge Kutta scheme for achieving TVD properties of the scheme, for details see Schwanenberg & Harms [14].

PARALLEL IMPLEMENTATION

The coding of the RKDG method is straightforward, following the set of equations defined above. Due to the orthogonal shape functions and the explicit Runge Kutta time stepping, the code becomes a sequence of loops on edges for computing the numerical fluxes and elements for computing the spatial discretization, updating the states, and applying the slope limiter (Figure 1).

1 time loop { 2

3 element loop {

4 check for minimum time step;

5 }

6

7 apply boundary condition; % 1st Runge Kutta step

8 edge loop {

9 compute numerical flux H;

10 }

11 element loop {

12 compute spatial discretization Lh, compute U1;

13 }

14 element loop {

15 apply slope limiter on U1;

16 }

17

18 apply boundary condition; % 2nd Runge Kutta step

19 ...

20 }

(5)

From our point of view, the code parallelization should meet the following two main demands: i) keep as possible the same code both for serial and parallel code versions of the solver aiming at simple maintenance, ii) minimize the work input for parallelization. Therefore, we first of all rely on pragma-based optimization techniques such as OpenMP for parallelizing the code for multi-core CPUs. The same concept was originally intended for the GPU using PGI-compiler specific pragma-directives. However, the approach didn’t work to our full satisfaction related to indirect addressing and the incapacity of the compiler to identify the corresponding allocated memory for copying it from CPU to GPU and vice versa. Therefore, we applied the CUDA API which resulted in small code changes, mainly applied to the administration of the parallel loops.

Having a look at the pseudo code in more detail, the element loop in line 3 is not parallelized for the time being, because of being responsible for only a small percentage of CPU time less than 0.3% of the total execution time. Furthermore, the execution time for the assignment of boundary conditions in line 7 is proportional to the square root of the number of elements and therefore also not parallelized. The edge loop in line 8 is parallelized. It includes some indirect addressing for reading element data into the edges and writes numerical fluxes back into the elements. The next element loop in line 11 is completely local. The limiter loop in line 15 includes read-only access to mean values of neighboring elements, and is local otherwise.

Profiling of the application on a single core shows that the proportion P of the program made parallel by the steps above is larger than 99.5%. We use Amdahl’s law for estimating the maximum parallel speedup that can be achieved by using N processors

1 speedup

(1 P) P N

, (9)

and get a theoretical speedup of 200 for an infinite number of processors. Taking into account the 240 processing units available on a Tesla C-1060 GPU we get a maximum speedup of about 110.

Furthermore, the parallel efficiency is defined as the quotient of speedup and N. This analysis neglects other potential bottlenecks such as memory bandwidth and I/O bandwidth, if they do not scale with the number of processors.

RESULTS

Performance tests on the parallel speedup of the solver are performed on a number of typical hardware environments (Table 1). The first one is a typical notebook, worth about € 800, being used by the first author for simulations when being abroad. The second system represents a common server with two Quad Core XEON CPUs, representing a value of about € 6000. The third and last system is a dedicated computer for performing numerical simulation (€ 1500) including a TESLA C-1060 GPU for about € 1000.

(6)

Table 1 Test environment (hardware and software framework)

Hardware OS / Compiler

1 Intel Core2 Duo

T7300 @ 2.00GHz, 1.96 GB RAM

Windows XP (32-Bit)

MS Visual C++ 2008, VC++ 9.0 2 Intel XEON

2x E5440 @ 2.83 GHz, 8.00 GB RAM

Windows 2003 Server (32-Bit) MS Visual C++ 2008, VC++ 9.0 3 Intel XEON 2x E5504 @ 2.00GHz, 8.00 GB RAM Nvidia Tesla C-1060 Ubuntu Linux 9.10 x86_64 PGI 10.1

We selected three test cases in order to get a representative picture of the parallel performance of the solver (Table 2). The first one is a typical riverine application with a fully wet domain. The second one is a dam-break application, in which most of the domain is dry in the beginning, being flooded partially in the course of the computation. The test is included to check the ability of the code for load balancing within the loops taking into account that dry elements require significantly less computational effort. Test case 3 is an academic exercise with a square domain of different sizes for checking the scaling of the solver due to different numbers of elements.

Table 2 Test cases Number of points / number of elements

Description

1 13821 / 27000 river section with groyne field, completely wet domain 2 13541 / 26041 Malpasset dam-break simulation according to

Schwanenberg & Harms [14], partially dry domain 3a 63001 / 125000 square area with 250m x 250m,

2 triangles per square meter, completely wet domain 3b 251001 / 500000 square area with 500m x 500m, otherwise like 3a 3c 1002001 / 2000000 square area with 1000m x 1000m, otherwise like 3a Table 3 Execution times and parallel efficiency

(preliminary projected GPU results based on CUDA code coverage of about 60% of total code) Test case

execution time / (time step * element) [micro s], parallel efficiency [-]

1 2 3a 3b 3c 3.062 1.448 3.022 3.012 2.955 1 x2 1.721 0.89 0.907 0.80 1.772 0.85 1.712 0.88 1.711 0.86 2.263 1.326 2.319 2.309 2.293 1.380 0.82 0.803 0.83 1.283 0.90 1.277 0.90 1.260 0.91 0.876 0.65 0.569 0.58 0.859 0.68 0.817 0.71 0.794 0.72 2 x2 x4 x8 0.571 0.50 0.475 0.35 0.592 0.49 0.573 0.50 0.560 0.51 3.705 1.689 4.095 4.005 4.020 1.952 0.95 0.976 0.87 2.151 0.95 2.167 0.92 2.095 0.96 1.081 0.86 0.670 0.63 1.193 0.86 1.149 0.87 1.151 0.87 0.712 0.65 0.541 0.39 0.753 0.68 0.630 0.79 0.618 0.81 Te st enviro nm ent 3 x2 x4 x8 GPU 0.203 - 0.323 - 0.197 - 0.194 - 0.194

(7)

-The results of the tests for the combination of test environment and test case are summarized in Table 3. For comparison purposes, we provide the execution time per time step and element in micro seconds as well as the parallel efficiency for a different number of cores.

Not surprisingly, the theoretical parallel efficiency of slightly less than 1.0 on multi-core CPUs is not achieved in any of the test cases. The maximum parallel efficiency on multi-core CPUs with a value of 0.96 is achieved with 2 cores on the largest test case. The efficiency is decreasing with the number of cores to a level of about 0.5 - 0.8 for 8 cores depending on the size of the test case and the OS / compiler combination. To our best guess, this decrease is related to bottlenecks in the memory bandwidth in combination with indirect addressing. The efficiency of the test case with a partially dry domain is less than the one in the other test cases, but still on an acceptable level between 0.87 (best result on 2 cores) and 0.35 (worst result on 8 cores).

The execution time on the GPU is 5 – 21 times faster compared to that of single thread execution on the CPU of test system 3. The speedup is smaller by a factor of 1.7, if comparing it to the faster CPU of test system 2. Related to the 8 core execution on test system 2, the GPU is about 1.5 times faster for the small test problem 2. For the larger test problems 1, 3a-c the speedup is converging to 3.

Focusing on the larger test problems and taking into account hardware costs, the GPU is the most cost effective option for performing simulations. It is followed by the low budget simulation PC (3) and the notebook system (1) with a dual-core CPU. Using the product of execution time and costs as a performance measure, these systems lack behind by a factor of about 5 and 7, respectively. The worst cost efficiency is achieved by the server system (3) with 8 processing units and factors of about 18.

CONCLUSIONS

The code parallelization of the DG scheme turned out to be easy for OpenMP. It was finalized within a couple of days. The effort for the GPU parallelization using the CUDA API is moderate and took about one to two weeks, mainly related to some training on the language extension and optimization of memory allocation and administration.

The application of a dedicated GPU turns out to be the most cost effective option for performing large scale inundation and dam-break simulations. It is therefore recommen-ded, if frequent or time critical simulations have to be performed. In other cases, the OpenMP code version offers an attractive option for exploiting available multi-core CPU resources.

ACKNOWLEDGEMENT

The authors thank Mike Walsh and NVIDIA Ltd for providing hardware for development and testing.

(8)

REFERENCES

[1] Berger, R. C., and Carey, C. F. (1998). “Free-Surface Flow over Curved Surfaces, Part I: Pertubation Analysis“, Int. J. Numer. Meth. Fluids, 28, 191-200

[2] Bunya, S., Kubatko, E.J., Westerink, J.J., Dawson, C. (2009). “A wetting and drying treatment for the Runge-Kutta discontinuous Galerkin solution to the shallow water equations”, Comp. Meth. in applied Mech. and Eng., 198(17-20), 1548-1562 [3] Cockburn, B. (1999). “Discontinuous Galerkin methods for convection-dominated

problems” Lecture Notes in Computational Science and Engineering 9, 69-224. Springer, Berlin.

[4] Ern, A., Piperno, S., Djadel, K. (2008). “A well-balanced Runge-Kutta discontinuous Galerkin method for the shallow-water equations with flooding and drying” Int. J. Num. Meth. in Fluids, 58(1), 1-25

[5] Ghostine, R., Kesserwani, G., Mose, R., Vazquez, J., Ghenaim, A., Gregoire, C. (2009). “A confrontation of 1D and 2D RKDG numerical simulation of transitional flow at open-channel junction” J. Num. Meth. in Fl., 61(7), 752-767

[6] Hughes, T. J. R., and Brooks, A. N. (1982). “A Theoretical Framework for Petrov-Galerkin Methods with Discontinuous Weighting Functions: Application to the Streamline-Upwind Procedure”, Finite Elements in Fluids, Vol. 4 (Eds. R. H. Gallagher et al.), London

[7] Katopodes, N. D. (1984). “A Dissipative Galerkin Scheme for Open-Channel Flow“, ASCE J. Hydr. Engrg, 110(4), 450-466

[8] Katopodes, N. D., and Wu, C.-T. (1986). “Explicit Computation of Discontinuous Channel Flow“, ASCE J. Hydr. Engrg., 112(6), 456-475

[9] Klöckner, A., Warburton, T., Bridge, J., Hesthaven, J. (2009) “Nodal Discontinuous Galerkin Methods on Graphics Processors,” J. of Comp. Physics, 228 (2009) 7863– 7882

[10] Neal, J.C., Fewtrell, T.J., Bates, P.D., Wright, N.G., “A comparison of three parallelisation methods for 2D flood inundation models”, Environmental Modelling & Software 25 (2010) 398–411

[11] Roger, S., Büsse, E., Köngeter, J. 2006. “Dike-break induced flood wave

propagation” Proc. 7th Int. Conf. on Hydroinformatics, Nice, France, 2, 1131-1138 [12] Roger, S., Dewals, B. J., Erpicum, S., Schwanenberg, D., Schüttrumpf, H., Köngeter,

J., Pirotton, M. (2009) “Experimental and numerical investigations of dike-break induced flows”, IAHR J. Hydr. Res., 47(3), 349-359

[13] Schwanenberg, D., Köngeter, J. (2000) “A discontinuous Galerkin method for the shallow water equations with source terms” Lecture Notes in Computational Science and Engineering 11, 419-424. Springer, Berlin.

[14] Schwanenberg D., Harms, M. (2004) “Discontinuous Galerkin Finite-Element Method for Transcritical Two-Dimensional Shallow Water Flows”, ASCE J. Hydr. Engrg., 130(5), 412-421

Referenties

GERELATEERDE DOCUMENTEN

Grouping the visitors to Aardklop by means of the above-mentioned segmentation methods can help festival organisers understand the current market better (by means

In dit gebiedsplan moeten aanvullende landschappelijke, ruimtelijke en energetische maatregelen en voorzieningen worden geïntegreerd, die proportioneel zijn in verhouding tot de

De toenmalige registratiehouder van cysteamine met vertraagde afgifte (Procysbi®) heeft de aanvraag voor opname in het GVS teruggetrokken na het uitbrengen van ons advies, vanwege

In de vergelijking met de andere cycli kan hij vervolgens het beeld van de compilatie nog wat scherper stellen: de eigenheid van elke cyclus wordt immers niet bepaald door de

De mate van self-efficacy hangt positief samen met inzetbaarheid maar versterkt de positieve invloed van fysieke en mentale gezondheid op inzetbaarheid niet.. Ook

There is no minimum of 33% caused by words with only one or two forms (like we see in the.. lexicostatistical results); there is no conceivable maximum like you’d have in a

 Cooperative systems – a mass of vehicular information that could be useful for better simulation model development (e.g., core functionality development – archived driving

In het eerste deel zouden dan de gewenste algebraïsche vaardigheden centraal moeten staan, het tweede deel zou een soort mengvorm kunnen zijn waarvoor de huidige opzet model