Totally Asynchronous Linear Equation-System Solvers for Unsteady CFD VI International Conference on Computational Methods in Marine Engineering MARINE 2015 F. Salvatore, R. Broglia and R. Muscari (Eds) CHAOTIC LINEAR EQUATION-SYSTEM SOLVERS FOR UNSTEADY CFD JAMES N. HAWKES1,2, STEPHEN R. TURNOCK1, GUILHERME VAZ2, SIMON J. COX1AND ALEX B. PHILLIPS3 University of Southampton 1 Boldrewood Campus, Southampton, United Kingdom e-mail:
[email protected] Maritime Institute Netherlands (MARIN) 2 Wageningen, Netherlands National Marine Facilities 3 National Oceanography Centre, United Kingdom Key words: Computational Methods, Computational Fluid Dynamics, Linear Solvers, Totally Asynchronous Methods, Chaotic Iterative Methods, PETSc, ReFRESCO. Abstract. A Chaotic Iterative Method, which is a form of totally asynchronous linear equation-system solver, is implemented within an open-source framework. The solver is similar to simple Jacobi or Gauss-Seidel methods, but is highly optimized for massivelyparallel computations. Processes or threads are free to run computations regardless of the current state of other processes, iterating individual equations with no limitations on the state of the variables which they use. Each individual iteration may pull variables from the same iteration, the previous iteration, or indeed any iteration. This effectively removes all synchronization from the Jacobi or Gauss-Seidel algorithm, allowing computations to run efficiently with high concurrency. The trade-off is that the numerical convergence rate of these simple algorithms is slower compared to the classical Krylov Subspace methods, which are popular today. However, unique features of the computational fluid dynamics algorithm work in favour of Chaotic methods, allowing the fluid dynamics field to exploit these algorithms when other’s cannot. The results of the Chaotic solver are presented, verifying the numerical results and benchmarking performance against the Generalized Minimal Residual (GMRES) solver and a Pipelined GMRES solver. The results show that, under certain circumstances, Chaotic methods could be used as a standalone solver due to their superior scalability. The potential to use Chaotic methods as a pre-conditioner or hybrid solver is also revealed. 1 931
James N. Hawkes, Stephen R. Turnock, Guilherme Vaz, Alex B. Phillips and Simon J. Cox 1 INTRODUCTION One of the major objectives in high performance computing for computational fluid dynamics is to enable complex unsteady simulations. Whilst these computations benefit from concurrency in three spatial dimensions, time-stepping is strictly serial; and unsteady computations become bottle-necked by the amount of parallelism that can be utilized in the spatial dimensions. Combined with this, the architecture of modern supercomputers is changing rapidly, causing scientific applications to adapt to a many-core era. Figure 1.a shows the history of the Top 500 supercomputers over the last 20 years. At current rates, it is expected that the first computer capable of 1018 floating-point- operations-per-second (1 ExaFLOPS) could be built in 2020. Its capability will be limited by electrical power consumption, rather than pure hardware speed, and this will lead to two significant architecture changes [9, 11, 14]. Firstly, core clock rates must decrease to save power, and total computing power must be improved by dramatically increasing the total number of cores. Secondly, inter-nodal networks must be reduced due to their relatively large power consumption. Overall, this means a huge growth in concurrency within nodes. This trend can already be seen in modern ‘many-core’ systems featuring GPUs or co-processors. The current most powerful computer, Tianhe-2 [15], capable of 33 PFlops, consists of 3,120,000 cores. By contrast, the first exascale machine will be 30-times more powerful and 300-times more parallel. Whilst Tianhe-2 already consists of nodes with O(100) cores, using co-processors; an exascale machine is likely to feature O(1k-10k) cores per node. In earlier work [6] the strong scalability of a typical CFD code (ReFRESCO) was assessed, to discover which parts of the algorithm required improvement for this paradigmshift in architecture. Figure 1.b shows the breakdown of the code, which is based on the SIMPLE algorithm, into its key parts. Figure 1.c shows that theassembly (discretization, orthogonality & eccentricity corrections, and final assembly of the matrix structure) and gradient computations scale well, and figure 1.d shows that these routines account for a small proportion of the overall run-time. The solve routines, responsible for solving the linear-equation systems that have been assembled, exhibit poor scalability and take considerable amounts of total runtime. Similarly, the exchange routines (responsible for sharing of cell-values and gradient values across ghost cells) are a cause for concern, dominating total run-time when inter-nodal communication becomes large. Considerable work is being performed to improve the exchange routines, primarily by overlapping communication with computation more efficiently or reducing global communications; and by utilizing a hybrid parallelization scheme. Cooperatively, the solve routines must be improved with the same goals. In this paper, a ‘Chaotic’ iterative solver is proposed as a solution to the strong scalability problem of the solve routines. In the following sections, a brief background is given, followed by the theory and implementation of a Chaotic solver. Finally, the Chaotic solver is verified and benchmarked against existing solvers. 2 932
James N. Hawkes, Stephen R. Turnock, Guilherme Vaz, Alex B. Phillips and Simon J. Cox Figure 1: (a) Total floating-point operation (FLOP) rate of the Top500 supercomputers, showing the #1 machine, the #500, and the sum of the top 500. (b) An illustration of the SIMPLE algorithm, with colour-coding relating the various sections of the code. (c) Scalability breakdown of a typical simulation showing the parallel speed-up of the code compared to its serial operation and (d) the proportions of execution time spent in the various routines [6]. 2 BACKGROUND TO LINEAR EQUATION-SYSTEM SOLVERS The task of the linear equation-system solver, for each transport equation in each nonlinear loop, is to solve Ax =b, where xis the unknown solution vector, Ais an n-by-n sparse coefficient matrix created by the assembly routines, bis the constant right-hand- side (RHS) vector, and nis the number of elements. It is possible to solve this system directly, but for large matrices this is expensive. For CFD, the equation systems can be solved iteratively: xk=−D−1(L+U)xk−1+D−1b(1) where Dis the diagonal of A, and L/Uare the lower- and upper-triangles respectively. kis the iteration number. This is the Jacobi method, and the matrix D−1(L+U) is the iteration matrix, M. Numerically, the Jacobi method, or its derivatives such as Gauss-Seidel or Successive Over-Relaxation methods, are weak. Their convergence rate is limited by the spectral 3 933
James N. Hawkes, Stephen R. Turnock, Guilherme Vaz, Alex B. Phillips and Simon J. Cox radius of the iteration matrix, ρ(M), which is dependent on the matrix size and stiffness. For CFD, this means the pressure equation is hardest to solve, as it is close to singular [7] and the spectral radius is close to unity. It is possible to add a form of ‘memory’ to these solvers, where some information about the solution path is stored in a vector subspace, known as the Krylov Subspace (KSP). For example, in the popular (Bi-)Conjugate Gradient Squared (BCGS) algorithm, the solver remembers the previous gradients that it followed, to prevent it from going back on itself. In the GMRES (Generalized Minimal Residual Method) the subspace is based on the Arnoldi iteration, and is used to find an approximate solution based on the minimal residual of these vectors. See Barrett et al. [2] for more information on a variety of iterative solvers. There is an initial grace period where high frequency errors can be reduced more quickly than the spectral radius would normally allow, using the simpler methods, but KSP solvers typically over-power the simpler solvers when lower frequencies must also converge. Though numerically powerful, the KSP methods are computationally inefficient on a larger number of cores due to certain communication patterns. Figure 2 shows an illustration of a GMRES iteration. Two significant communication patterns are required, with very different scaling characteristics. Firstly, the sparse-matrix-vector-multiplication (SpMV) requires neighbour-to-neighbour communication to obtain boundary data from other processors. This communication pattern is highly scalable, as different neighbours can communicate in parallel. The second communication pattern is a global reduction (and associated broadcast). Many small messages are sent down a hierarchical tree in a non-concurrent manner. The time for a reduction increases as the number of cores increases, whereas every other routine receives a speed-up from increasing the number of cores. In the GMRES or BCGS algorithm there are two global reductions per iteration. As the number of cores rises and the scalable routines reduce to a small proportion of overall time, these reductions dominate wall-time and prevent the KSP solvers from scaling. Improvements have been made to GMRES, in the form of ‘pipelined’ GMRES (P-GMRES) which attempt to overlap the first reduction with serial computations [5] – results show better scalability than GMRES, especially when the so-called ‘latency-factor’ is large, but as the cells-per-core ratio decreases global reduction latency will once again dominate. Compared to other applications, where solving linear equation systems to machine accuracy is important (for example, solving Markov chains for risk analysis), CFD is not so strict. As the ‘real’ problem is a non-linear one, much of the work done in the linear loops is discarded as under-relaxation is applied to the non-linear iteration. In fact, for many cases, it is possible to reach non-linear convergence with a relative convergence factor of the linear system as high as 60%, although this is not usually beneficial. It highly depends on the problem and the type of non-linear iterative process; and is only worthwhile if the non-linear iterative process is efficient, as many more non-linear iterations are required. With this in mind, it may be possible to take advantage of the initial ‘grace period’ of the simpler solvers such as Jacobi or Gauss-Seidel; however, to compete with a well- 4 934
James N. Hawkes, Stephen R. Turnock, Guilherme Vaz, Alex B. Phillips and Simon J. Cox Figure 2: Illustrative parallel trace of a GMRES iteration, showing the computation and communication patterns when utilizing 8 cores. Note that as the serial computations and SpMV become small, the reduction dominates the total wall-time. Not to scale. preconditioned GMRES solver there must be a significant computational benefit. 3 THEORY AND IMPLEMENTATION OF A CHAOTIC SOLVER The Jacobi solver is particularly poor numerically, using old values of the solution vector in each iteration rather than using newly-computed variables from the current iteration. By contrast, Gauss-Seidel is stronger numerically as it uses newly-computed variables; but is impossible to parallelize. Forms of Block Gauss-Seidel exist, which are a good compromise; but both Jacobi and Block Gauss-Seidel can be improved computationally. The Jacobi or Block Gauss-Seidel methods have no reduction routines, using purely an SpMV to perform the iterations. This is a huge benefit to scalability, and should allow these solvers to scale far higher than KSP methods. However, the Jacobi/Block G-S routine still has room for improvement. In these methods, the k+1 th iteration cannot start until the kth iteration is complete. This means that the whole solution can only proceed as fast as the slowest core. A core may be slow due to background operatingsystem load, poor load-balancing, heterogeneity in the hardware, irregular communication times or Non-Uniform Memory Access (NUMA). These irregularities are likely to be more of a concern in the many-core era, and will significantly slow down computations when trying to utilize thousands of cores. In 1969, Chazan & Miranker [3] proposed the concept of Chaotic Relaxation whereby several processes never synchronize. Instead, the processes freely pull values of off-diagonal xfrom memory whenever they are required, and push new values for the diagonal xi whenever they have been relaxed. By exploiting data races in this way, each relaxation uses the values of xfrom the latest iteration that is available – this could be several iterations behind (s= 1, ..., k), or even ahead of it (s<0): xk=−D−1(L+U)xk−s+D−1b(2) In the average case, this scheme should produce numerical convergence similar to that of Gauss-Seidel. 5 935
James N. Hawkes, Stephen R. Turnock, Guilherme Vaz, Alex B. Phillips and Simon J. Cox In previous work [7] it was shown that the strict convergence criteria for Chaotic methods are met by all CFD equations, which prompts the implementation and testing of a Chaotic solver, as follows. The solver is written in a hybrid MPI + OpenMP (Open Multi-Processing – a multithreading standard) environment, using PETSc (Portable, Extensible Toolkit for Scientific Computation) [1] as a platform. The MPI processes and OpenMP threads are split in a NUMA-friendly manner, with one MPI process per socket and one thread per core within each socket. The test machine is Iridis 4, the University of Southampton’s latest supercomputer, which consists of 750 compute nodes - each with 2 Intel Xeon E5-2670 Sandybridge processors (8 cores, 2.6 Ghz). Within each MPI process one thread is dedicated to halo-data communication and the remaining seven perform the chaotic matrix-vector multiplications. In the following sections, the results of the Chaotic solver will be verified by comparing the solutions produced by them against KSP methods, and the performance (in terms of scalability and absolute wall-time) will be assessed. 4 VERIFICATION The solution produced by the Chaotic solver was compared against the solution produced by GMRES (with a restart of 3, 30 and 100), P-GMRES and BCGS. Pre-conditioners were not used and there was no attempt to compare performance, these tests were performed purely to compare the absolute solution and verify the implementation. The solvers were required to iterate until a desired absolute residual in the l2-norm. Three analytical matrices from the matrix marketplace [4] were tested (pde225, pde900 and orsirr 1), along with a pressure equation matrix extracted from a 14.4k-cell lid-driven cavity flow simulation (LDCF). The results for the smallest case (pde225) are shown in figure 3. The results were similar for all cases and a range of convergence tolerances from 10−1to 10−7(not shown). There are no concerns for any of the solvers, although there are some differences in the solution vector. There is a tendency for the Chaotic solver to produce a much lower l1-norm, presumably as the stiffer equations in the system require many iterations to solve, the easier equations can progress much more quickly, whereas the KSP methods have more inter-dependency between the equations. Due to the squared-weighting of the l2-norm this has little effect on the reliability of the solution, and differences in the overall flow field are likely to be negligible. 5 PERFORMANCE TESTING The aim of Chaotic solvers is to improve scalability, and it is expected that at lower core-counts that KSP solvers will out-perform the Chaotic methods. In order to predict how these solvers will perform on many-core machines, scalability tests are the main focus of the following tests. It should be possible to predict the break-even point of Chaotic methods, where their worse numerical performance overtakes the KSP solvers based on improved scalability. 6 936
James N. Hawkes, Stephen R. Turnock, Guilherme Vaz, Alex B. Phillips and Simon J. Cox Figure 3: Full verification results from the pde225 case, with a requested absolute l2-norm of 10−6. [Top] A plot of the raw residual vector (r=Ax −b). [Bottom-Left] Statistical Distribution of the residual vector, showing the mean, upper/lower quartiles, and minimum/maximum values. [Bottom- Right] Spectral analysis of the residual vector, with peaks corresponding to frequencies of error in the converged system. The dotted lines in the results mark the mean value of the residual required in order to satisfy the l2-norm. This line divides the elements of the residual that positively or negatively contribute to the l2-norm. A number of benchmark cases are used in order to capture a range of problem sizes: •KVLCC2 Tanker (half-body, single-phase) on three-dimensional, multi-block structured grids (317k, 1.11m, 2.67m, 5.99m, 10.0m & 15.8m elements), using a twoequation κ-ωSST turbulence [12]. See [6]. •Lid-Driven Cavity Flow (LDCF) on 2D structured grids (14.4k & 1m elements). No turbulence model. See [10]. •NACA0015C hydrofoil (15◦angle-of-attack) on a two-dimensional multi-block structured grid (28k elements), using a κ-ωSST turbulence model, and a Sauermodified cavitation model. See [8]. •Dambreak, a homogeneous two-phase, three-dimensional problem with a simple structured grid (16k cells) and a volume-fraction equation. No turbulence model. 7 937
James N. Hawkes, Stephen R. Turnock, Guilherme Vaz, Alex B. Phillips and Simon J. Cox See [16]. •Cylinder at a low Reynold’s number. An unsteady simulation (10 non-linear iterations per timestep) on a structured grid (4.3k elements) with a poor initial flow estimation. No turbulence model. See [13]. A large number of core-counts are tested, beginning from 32 cores, to which the scalability graphs are normalized: Scalability =Time(32-cores) Time(n-cores) (3) The linear system convergence tolerance is set to 60% and 50 non-linear iterations are performed. Chaotic solvers were compared against GMRES and P-GMRES, both with a restart of 30. The respective solver was applied to every equation (i.e. momentum, pressure, turbulence, volume-fraction and cavitation), and their average taken for each case. It was necessary to use pre-conditioning on the GMRES solvers in order to realize their true potential. Unfortunately these solvers then base their convergence on the preconditioned residual P−1(Ax −b) which is not proportional to the true residual. If the pre-conditioner is not smooth, and the matrix is close to singular (as in the pressure equation) a 10% relative convergence tolerance in the preconditioned residual may be equivalent to a 50% or higher convergence tolerance in the true residual. To test fairly, the pre-conditioner was limited to a simple diagonal scaling (Jacobi) and the equivalent residual was computed in the Chaotic solver. This is not the best-case scenario for the KSP solver, as pre-conditioning can drastically change their performance. However, there is some overhead in the Chaotic solver in computing the diagonally-scaled residual, so it seems the best compromise. Regardless, the effects of pre-conditioning should not have a huge impact on the scalability results, especially given that Jacobi pre-conditioning is highly scalable compared to more complex pre-conditioners. Figure 4 shows the performance results for each solver. Firstly, the tabular results show the absolute wall-time comparison on 32-cores and 256-cores. The Chaotic solvers are expectedly slower on all reasonably-sized test cases and up to 6.88 times slower than GMRES in the largest test case. The differences between GMRES and Chaotic solvers in terms of absolute time mostly depend on the convergence tolerance (tolerances of 40% and 20% were partially tested – not shown), however, scalability is mostly unchanged. P-GMRES performs approximately 50% slower where strong scalability is not a concern. The scaling graphs require more careful analysis. There are three factors at play: (1) the cells-per-core ratio, which governs how much serial work and scalable ghost-cell exchange each process/thread performs; (2) the absolute number of processes, which governs how much time is spent performing reductions; and (3) cache effects. The combination of all three, and their relativity to each other, determines scalability. The cells-per-core ratio is dominant in terms of scalability, since it changes most dramatically with the number of cores (doubling the number of cores halves the time due to factor (1)); whereas doubling the number of cores has little change on factor (2), as 8 938
James N. Hawkes, Stephen R. Turnock, Guilherme Vaz, Alex B. Phillips and Simon J. Cox the reduction time increases at a rate of log2(cores). Cache effects (3) occur when the main parts of an algorithm fit into a high-speed memory buffer, located on the CPU. The cache is responsible for the super-linear scalability demonstrated by each solver. Its effect is more qualitative, as one could do extensive cache-optimization for each solver and each CPU to obtain the best results. No such optimization was performed for these solvers, and one can make the argument that the Chaotic solver more na¨ıvely exploits the cache, leading to performance benefits at the intra-node level, where memory contention is a bottleneck. For the Chaotic solver, it is possible to see the point where the working memory fits into cache (≈20k-30k cells-per-core). The scalability of GMRES and P-GMRES collapses when a certain cells-per-core ratio is reached - typically around 10k cells-per-core. Chaotic solvers continue to scale beyond this point. For example, with the KVLCC2-1.11m case on 512 cores, the scalability of the Chaotic solver is a factor of 601 compared to GMRES at 104. In absolute terms, the Chaotic solver is approximately twice as fast at ≈2.2k cells-per-core. This scalability does not continue indefinitely, as demonstrated by the very small test cases. This is due to the expense of setting up the 8 OpenMP threads each time the solver is called, as well as a few other serial bottlenecks in the initialization, finalization and interface with PETSc’s data structures; there is also some ‘lag’ involved with the residual computations which can cause over-convergence of very small equations. The reduction required to compute the residual also blocks the SpMV MPI communications, which is not ideal. Some scalability is also lost due to the MPI communications themselves, which, although asynchronous with the computations, ultimately proceed in lock-step with each other. This means two MPI processes cannot benefit from faster communication between themselves. The scalability of P-GMRES is lacklustre for this application. It is suspected that the very lax convergence tolerance prevents P-GMRES from showing its true benefit (since the number of total iterations is very small and more time is spent in setting up the solver), and very na¨ıve pre-conditioning is used. It is also known that the scalability can be improved by increasing the l-factor of the solver, and this could be further investigated [5]. It is important to note that the results show the average of all the equation systems, although the pressure equation dominates the others in terms of total wall-time. Splitting the analysis between each equation individually is important, but the relative comparison between solvers is virtually unchanged in these cases. 6 CONCLUSION The results show that the Chaotic solver provides a correct solution and that the scalability is better than a typical Krylov solver. The comparison of absolute wall-time is subjective - utilizing such high convergence tolerance of the linear equation system may not be viable, depending on the non-linear iterative process, the particular test case, and the efficiency of the non-linear iteration. Furthermore, more effective pre-conditioning 9 939