Full text
Journal of Supercomputing manuscript No. (will be inserted by the editor) Iteration-Fusing Conjugate Gradient for Sparse Linear Systems with MPI+OmpSs María Barreda ·José I. Aliaga ·Vicenç Beltran ·Marc Casas Received: date / Accepted: date Abstract In this paper we target the parallel solution of sparse linear systems via iterative Krylov subspace-based method enhanced with a block-Jacobi preconditioner on a cluster of multicore processors. In order to tackle largescale problems, we develop task-parallel implementations of the Preconditioned Conjugate Gradient (PCG) method that improve the interoperability between the MPI (message-pasing interface) and OmpSs programming models. Specifically, we progressively integrate several communication-reduction and iteration-fusing strategies into the initial code, obtaining more efficient versions of the method. For all these implementations, we analyze the communication patterns and perform a comparative analysis of their performance and scalability on a cluster consisting of 32 nodes with 24 cores each. The experimental analysis shows that the techniques described in the paper outperforms the classical method by a margin that varies between 6% and 48%, depending on the evaluation. Keywords Sparse linear systems ·Multicore processors ·Distributed systems ·Communication-reduction strategies · Iteration-fusing 1 Introduction Linear systems appear in a myriad of applications, including fundamental numerical simulations of physical phenomena as well as in recent methods for data analytics [11]. When the coefficient matrix of the linear system is large and sparse, iterative methods based on Krylov subspaces, enhanced with some sort of preconditioner, often provide an efficient means to solve these type of linear algebra problems, avoiding the fill-in memory issues of their direct counterparts [15]. The conventional formulations of Krylov subspace methods (KSMs) such as conjugate gradient (CG), biconjugate gradient (BiCG), biconjugate gradient stabilized (BiCGStab) and generalized minimal residual method (GMRES) [15] present several “synchronization points” per iteration. In consequence, as technological advances widen the gap between computational performance and communication costs of computer architectures [8,12], the performance of KSMs suffers as the data dependencies and the memory-bound nature restrict the communication overhead that can be hidden [17]. In response, in the last years there has been an intensive research aimed to reduce the negative impact of synchronization bottlenecks in KSMs. The result has been a number of communication-reduction techniques, hierarchical and “enlarged” reformulations of the solvers, iteration-fusing variants, s-step methods (“communicationavoiding”), pipelined schemes (“communication-hiding”), etc. An up-to-date source of references to these variants can be found in [6]. Our work builds upon a number of previous papers that address the task-parallel implementation of KSMs on multicore architectures and clusters of multicore processors. First, the authors of [1]; proposed a parallel implemen- María Barreda, José I. Aliaga Dpto. de Ingeniería y Ciencia de Computadores, Universidad Jaime I, 12.071–Castellón, Spain E-mail: {mvaya,aliaga}@uji.es Vicenç Beltran, Marc Casas 08034–Barcelona Supercomputing Center, Barcelona, Spain. E-mail: {vbeltran,casas}@bsc.es
2 María Barreda et al. tation of a CG solver, enhanced with a sophisticated ILUPACK preconditioner, that leverages MPI and OmpSs [13, 14] to improve the performance of a pure MPI-based solution; and this approach was then generalized to other types of incomplete LU (ILU)-based preconditioners and communication-reduced variants of CG in [2]. Independently, the authors of [18] presented an iteration-fusing variant of the pipelined CG [9], for multicore processors, that combines a task-parallel re-formulation of the method with a relaxation of the convergence test in order to break the strict barrier between consecutive iterations of the method. In this paper we extend the iteration-fusing techniques to carry over to an MPI+OmpSs implementation of the pipelined CG solver for clusters of multicore processors. Specifically, our work makes the following contributions: –We develop message-passing, task-parallel implementations of the CG method, preconditioned with a block-Jacobi (BJ) strategy, that exploit a “hybrid” programming solution which combines MPI and OmpSs. (We will refer to this method as BJCG hereafter.) –We integrate several strategies into the classical BJCG to reduce the number of synchronization points, increase task asynchronism, and diminish the communication overhead. In particular, our message-passing task-parallel implementation of the pipelined BJCG solver reduces the number of synchronization points to only two per iteration. Furthermore, it overlaps communications and computations, making possible to execute in paralel tasks from two consecutive iterations. –We examine in detail the communication and synchronization patterns, as well as the dependencies between tasks, appearing in these parallel implementations. –For all these implementations, we perform a comparative analysis of their weak scalability on a cluster consisting of 32 nodes, using a 24-core socket per node. The rest of the paper is structured as follows. Section 2 offers a brief review of the BJCG solver, and Section 3 presents an initial message-passing, task-parallel parallelization version of BJCG. In Section 4 we describe a number of variants of BJCG that increase the task asynchronism of the initial implementation. In Section 5, we analyze the performance and scalability of these different parallel versions. Finally, Section 6 summarizes our work and offers a few concluding remarks. 2 Preconditioned CG Solver Let us consider the linear system Ax =b, where the coefficient matrix A∈Rn×nis symmetric positive definite (s.p.d.) and sparse, with nznonzero entries; b∈Rnis the right-hand side vector; and x∈Rnis the sought-after solution vector. Figure 1 offers an algorithmic description of the iterative preconditioned CG method. The most timeconsuming operations in this algorithm are the computation of the preconditioner (before the iteration commences), the sparse matrix-vector product (SpMV) (at each iteration), and the application of the preconditioner (M) (also once per iteration). The remaining operations are scalar computations or simple vector kernels such as the dot product (dot) and axpy-type vector updates [4]. For simplicity, in our implementation of the CG method we integrate the Jacobi preconditioner [15]. In particular, consider a decomposition of the coefficient matrix Athat extracts its diagonal blocks into D= ( ˆ D1,ˆ D2,..., ˆ DS), where ˆ Ds∈Rms×ms,s= 1,2,...,S, and n=PS s=1 ms. (In the classical Jacobi preconditioner, ms= 1 for all s= 1,2,...,S, so that Donly contains the diagonal entries of A.) The block-Jacobi preconditioner defined by the block-diagonal matrix M=diag(D)∈Rn×nis particularly effective if the structural blocks ˆ Dsreflect the nonzero block-structure appearing in the coefficient matrix A, as it is the case for many linear systems that arise from a finite element discretization of a partial differential equation (PDE) [3]. To achieve this, we can leverage a supervariable agglomeration heuristic to determine the block diagonal structure of the block-Jacobi preconditioner [5]. This procedure captures the block structure of the coefficient matrix in the blocks of the preconditioner, with a given upper bound on the blocksize. An additional appealing property of the block-Jacobi preconditioner is that its computation can be realized via a straight-forward extraction of the structural blocks from the coefficient matrix A, followed by an explicitly independent inversion of each one of these blocks: M−1=diag(ˆ M1,ˆ M2,..., ˆ MS) = diag(ˆ D−1 1,ˆ D−1 2,..., ˆ D−1 S). The application of the preconditioner then boils down to a simple (dense) matrix-vector multiplication per block ˆ Ms. Alternatively, one can extract the structural blocks and then decompose each into the product of two triangular factors using, for example, the Cholesky factorization [10]: ˆ Ds=LsLT s, where Ls∈Rms×msis lower triangular. The application of the preconditioner then requires the solution of two triangular linear systems per block, with the factor Lsand its transpose LT s.
Iteration-Fusing Conjugate Gradient for Sparse Linear Systems with MPI+OmpSs 3 Compute preconditioner for A→M Set starting guess x(0) Initialize z(0), d(0), β(0), τ(0), l := 0 (iteration count) r(0) := b−Ax(0) τ0:=< r(0), r(0) > while (τ(l)> τmax) Step Operation Kernel S1 :w(l):= Ad(l)SpMV S2 :ρ(l):= β(l)/< d(l), w(l)>dot product S3 :x(l+1) := x(l)+ρ(l)d(l)axpy S4 :r(l+1) := r(l)−ρ(l)w(l)axpy S5 :z(l+1) := M−1r(l+1) Apply preconditioner S6 :β(l+1) := < z(l+1), r(l+1) >dot product S7 :d(l+1) := (β(l+1)/β(l))d(l)+z(l+1) axpy-like S8 :τ(l+1) := < r(l+1), r(l+1) >dot product l:= l+ 1 end while Fig. 1 Formulation of the preconditioned CG solver annotated with computational kernels. The threshold τmax is an upper bound on the relative residual for the computed approximation to the solution. In the notation, <·,·>computes the dot (inner) product of its vector arguments. For simplicity, hereafter we will drop the superindices that denote the iteration count in the variable names. Thus, for example, x(l)becomes x, where the latter stands for the storage space employed to keep the sequence of approximations x(0), x(1), x(2), . . ., computed during the iterations. 3 Parallel BJCG Solver 3.1 Message-passing BJCG solver In this subsection we perform a communication analysis of a basic message-passing implementation of the BJCG solver with the following considerations: 1. The parallel platform consists of np processes, denoted as P1,P2, . . . , Pnp. Without loss of generality, we will assume a message-passing algorithm that operates in a distributed-memory platform. (In the MPI context, the term process refers to an MPI rank.) 2. The coefficient matrix Ais decoupled (i.e., partitioned) into np blocks of rows (i.e., one row-block per process): A= A1 A2 . . . Anp , with the k-th distribution block Ak∈Rnk×nstored in Pk, and Pnp k=1 nk=n. This block-row distribution is particularly appealing when the sparse matrix is maintained in CSR (compressed sparse row) format [15]. 3. Unless otherwise stated, vectors are partitioned and distributed conformally with the block-row distribution of A. For example, the residual vector ris partitioned as r= [ r1r2. . . rnp ], and rk∈Rnkis stored in Pk. 4. The partitioning of Ainto np row-blocks also induces a conformal partitioning by blocks on the preconditioner: M= M1 M2 ... Mnp ,
4 María Barreda et al. where Mk∈Rnk×nkis stored in Pk. For simplicity, we assume that each one of the distribution blocks Mk contains an integer number of structural blocks of the preconditioner M=diag(ˆ D1,ˆ D2,..., ˆ DS). In other words, the entries of the structural block ˆ Dsare all mapped to a single distribution block Mk. Note that this can always be achieved by slightly adjusting the values of the distribution block sizes nk. 5. The scalars β, ρ, τ are replicated in all np processes. Let us next analyze the individual operations (or computational kernels) S1–S8 comprised by the loop body of a single BJCG iteration, as shown in Figure 1. Sparse matrix-vector product (S1)The input operands to this kernel are the coefficient matrix A, which is distributed by blocks of rows, and the vector d, which is partitioned and distributed conformally with A. Therefore, in order to compute this kernel, we first obtain a replicated copy of the distributed vector din all processes, denoted as d→e. (Vector eis the only array that is replicated in all processes. In contrast, the remaining vectors are all distributed.) After this communication stage, each process can then compute its local piece of the output vector wconcurrently: Pk:wk:= Ake. This kernel thus requires collecting the distributed pieces of dinto a single vector ethat is replicated in all processes (in MPI, for example via an MPI_Allgatherv). The computation can then proceed in parallel, yielding the result w in the expected distributed state with no further communication involved. At the end, each MPI rank owns a piece of w. dot products (S2,S6,S8)The next kernel in the loop body is the dot product S2 between the distributed vectors d and w. Here, it is easy to derive that a partial result can be first computed concurrently in each process: Pk:ρk:= < dk, wk>, after which, these intermediate values have to be reduced into a globally-replicated scalar ρ:= β/(ρ1+ρ2+· · ·+ρnp). The same idea applies to the dot products in S6 and S8, yielding a total of three process synchronizations due to dot products (in MPI, via MPI_Allreduce). axpy(-type) vector updates (S3,S4,S7)Consider now the axpy kernel in S3, which involves the distributed vectors x, d and the globally-replicated scalar ρ. All processes can perform their local parts of this computation to obtain the result without any communication: Pk:xk:= xk+ρ dk. The same applies to S4 and, given that β, β0are globally-replicated, also to S7. Application of the preconditioner (S5)The kernel in S5, where the input preconditioner Mis distributed by blocks of rows as A, and the input vector ris distributed conformally with the same matrix, can be performed concurrently in all processes, with Pk:zk:= M−1 krk. This kernel should exploit that Mkconsists of multiple structural blocks. Thus, assuming for example that M1= (ˆ D1,ˆ D2,ˆ D3,ˆ D4), with conformal partitionings r1= (ˆr1,ˆr2,ˆr3,ˆr4),z1= (ˆz1,ˆz2,ˆz3,ˆz4), the first process computes P1:z1:= M−1 1r1≡ˆzs:= ˆ D−1 sˆrs, s = 1,2,...,4. Summary The previous elaboration exposes several insights for the message-passing BJCG solver: 1. Prior to each SpMV, we need to gather a copy of the distributed vector dwithin all nodes, implying a process synchronization at the beginning of each iteration. 2. Each dot product requires a global reduction and, therefore, a process synchronization point. The loop body of the BJCG solve can be re-arranged so that S8 is pushed up next to S6. A simultaneous execution of these two reductions then decreases the number of process synchronizations, due to global reductions/dot products, from 3 to 2 per iteration in the loop body of the BJCG solver. 3. The axpy(-type) kernels and the application of the block-Jacobi preconditioner do not involve any sort of communication. 4. All (non-scalar) data is distributed among the processes, except for the replicated copy of vector din e. The reorganized algorithm and communications are summarized in Figure 2.
Iteration-Fusing Conjugate Gradient for Sparse Linear Systems with MPI+OmpSs 5 Compute preconditioner for A→M Set starting guess x Initialize z, d, β, τ, l := 0 r:= b−Ax,τ:=< r, r > while (τ > τmax) Step Operation Kernel Communication β0:= β– S1 : S1.1:d→e– All gather S1.2:w:= Ae SpMV – S2 :ρ:= β/< d, w > dot product All reduce S3 :x:= x+ρd axpy – S4 :r:= r−ρw axpy – S5 :z:= M−1rApply preconditioner – S6 :β:= < z, r > dot product Combined all reduce S8 :τ:= < r, r > dot product S7 :d:= (β/β0)d+zaxpy-like – l:= l+ 1 end while Fig. 2 Message-passing formulation of the BJCG solver annotated with communication. Note the reorganization of the code to enable the merge of S6 and S8. 3.2 Task-parallel BJCG solver When the target platform is a cluster of multicore processors, from the performance perspective it often pays off to expose an extra level of parallelism, which can then be exploited within each node of the cluster using, for example, OpenMP or OmpSs. This can be achieved by leveraging the loop-parallelism within the kernels S1–S8. Alternatively, the same goal can be pursued by explicitly dividing each kernel into a collection of finer-grain operations, or tasks, to then exploit this type of task-parallelism. This second option, analyzed in the iteration-fusing CG scheme presented in [18] and the ILU-preconditioned CG solver in [2], aims to avoid the introduction of a thread-synchronization point after each kernel, enabling a partially concurrent execution of two or more kernels, as explained next. In the following analysis we will only consider kernels S1–S2 and S4–S7 in the loop body of the BJCG solver (see Figure 2). For simplicity, we merge the execution of S3 with that of S4; and S8 with S6. The operations in the solver are then intertwined by a series of data dependencies which, in principle, dictate a strict order of execution: · · · −→ S6 β −→ S7 iteration l−1 d −→ S1 w −→ S2 ρ −→ S4 r −→ S5 z −→ S6 β −→ S7 iteration l d −→ S1 w −→ S2 ρ −→ · · · iteration l+1 (The name on top of each dependency arrow indicates the variable that generates the corresponding dependency.) However, as described next, exploiting task-parallelism enables a overlapped execution where some of these kernels can be (partially) computed concurrently (denoted with the symbol “k”), breaking the strict inter-kernel barriers due to the dependencies; in particular, we aim to attain a parallel execution where S1 kS2 and S4 kS5 kS6. Sparse matrix-vector product S1 kdot product S2 For the SpMV we can partition the operands local to process Pk as wk:= Ake≡ ˜w1 ˜w2 . . . ˜wI := ˜ A1,1˜ A1,2. . . ˜ A1,J ˜ A2,1˜ A2,2. . . ˜ A2,J . . .. . ..... . . ˜ AI,1˜ AI,2. . . ˜ AI,J e1 e2 ... eJ . Here, we can consider each one of the small SpMV operations ˜ Ai,jejas a fine-grain task, where the specific sparsity pattern of Akdetermines the dependencies between an output block ˜wiand the input e. This yields a global task dependency graph (TDG) for SpMV that reflects the sparsity pattern of A. Consider, for example, the SpMV in Figure 3, where I= 3 and J= 5 and there are 7 blocks with nonzero entries in Ak. Now, due to the particular nonzero block structure of Ak, we note that, for example, ˜w1=PJ j=1 ˜ A1,jej=˜ A1,1e1+˜ A1,4e4, yielding the dependencies {e1, e4} → ˜w1. Here we consider that each one of the matrix-vector products ˜ A1,1e1and ˜ A1,4e4can be
6 María Barreda et al. ˜w1 ˜w2 ˜w3 := ˜ A1,1˜ A1,4 ˜ A2,2˜ A2,3 ˜ A3,1˜ A3,3˜ A3,5 e1 e2 e3 e4 e5 e1e2e3e4e5 ~ w 1 ~ w 2 ~ w 3 Fig. 3 Example of sparsity pattern and dependencies for SpMV. The solid lines indicate data dependencies while the dashed ones specify serialized updates. annotated as a task, producing a partial result which finally have to be accumulated (in a serialized update) in order to obtain ˜w1. For the dot product S2, the computation local to Pkcan be decomposed into Itasks, which can be calculated in parallel by partitioning the input operands dk, wkinto Ipieces, with each task producing a partial result ˜ρi: ρk:= < dk, wk>≡˜ρi:= <˜ di,˜wi>, i = 1,2,...,I. (Note the difference between the partitioning of the full replicated vector e∈Rninto Jblocks, involved in the local SpMV, and that of the local piece of vector was wk= ( ˜w1˜w2. . . ˜wI)∈Rnkappearing in the previous dot product.) These partial results are then reduced to produce a single value local to the k-th node, ρk:= PI i=1 ˜ρi, and these local values are next further reduced across all np nodes to produce the globally replicated scalar ρ:= Pnp k=1 ρk. The key here is that, although there exists a strict dependency S1 →S2, by breaking these two operations into fine-grain tasks, the execution of some tasks of the second kernel can commence as soon as the corresponding results of the former one are available, yielding a partially-concurrent execution of these two tasks. Unfortunately, the global reduction required at the end of S2 imposes a task/process synchronization point that impedes to extend this idea beyond that point. axpy vector update S4 kpreconditioner application S5 kdot product S6 A similar division of the three kernels S4–S6 into fine-grain tasks permits their concurrent execution, but again a task/process synchronization appears right after S6. axpy vector update S7 and SpMV S1 (subsequent iteration) The convergence test together with the need to perform the replication d→e, at the beginning of each iteration, introduces a process synchronization that prevents the parallel execution of the local tasks corresponding to these two kernels. 3.3 Implementation using MPI+OmpSs Once we have analyzed the parallelism that the application offers, in this subsection we describe how to exploit it via a combination of two parallel programming interfaces: MPI and OmpSs. Following the OmpSs programming model [14], in our task-parallel implementations tasks are annotated with the directive #pragma oss task, using clauses to specify the operands’ directionality as input (in), output (out) or both (inout). For example, the routine for a dot product, calculating α:= xTy,x, y ∈Rq, is annotated as #pragma oss task in(x[0;n], y[0;n]) out(alpha) ddot (int q, double *x, int incx, double *y, int incy, double alpha); while, for a routine calculating the axpy y:= y+αx, we have #pragma oss task in(alpha, x[0;n]) inout(y[0;n]) daxpy (int q, double alpha, double *x, int incx, double *y, int incy); As already hinted during the presentation of the message-passing task-parallel BJCG solver, the replication of vector dinto eis performed across the processes using the MPI collective MPI_Allgatherv. To ensure that an updated version of dis fed into the MPI collective, we introduce a task barrier, using the OmpSs directive #pragma
Iteration-Fusing Conjugate Gradient for Sparse Linear Systems with MPI+OmpSs 7 ~ w 1 ~ w 2 ~ w 3 Iteration l r2 ~r3 ~ r1 ~ z1 ~z2 ~z3 ~ Iteration l−1 S5. Apply precond. Process P k ρ ~ 1ρ ~ 2ρ ~ 3 1 β ~ βk β ~ 3 ~ β2 . . . . . . Iteration l+1 ρ Σρk ρk e1e2e3e4e5 d eMPI_Allgather 1 d ~ 2 d ~ 3 d ~ e1e2e3e4e5 d eMPI_Allgather 1 d ~ 2 d ~ 3 d ~ S1.2 SpMV S2. DOT S6. DOT S4. AXPY ρ S7. AXPY β (and S8) (and S3) MPI_Allreduce #pragma omp task wait on β Σβk updates Atomic Atomic updates MPI_Allreduce #pragma omp task wait on S1.1 #pragma omp task wait Convergence test S1.1 #pragma omp task wait Convergence test Fig. 4 Dependencies between kernels in the BJCG solver. oss taskwait, before the invocation of the communication primitive. This enforces that all tasks up to that point are completed before the communication (in that process) is allowed to proceed, creating a task synchronization point which is leveraged to perform the convergence test (τ > τmax?) right after it. This is followed by an MPI synchronization across processes implicit in the MPI collective primitive. The global reductions are realized via MPI_Allreduce. Similarly to the previous case, we insert a #pragma oss taskwait on the specific variable being reduced prior the invocation to the MPI collectives for the reduction, so that all tasks operating on that variable have been completed before the reduction across nodes can begin. Furthermore, the results from each reduction task (e.g., ˜ βifor S8) are accumulated into the local result (βk) using atomic updates. Figure 4 summarizes the previous elaboration focusing on the operations computed by process Pk, during iteration l, using a simple example with the sparse coefficient matrix defined as in Figure 3. Note the partitioning of the kernels into multiple tasks, with I= 3,J= 5.
8 María Barreda et al. Compute preconditioner for A→M Set starting guess x Initialize z, q, s, p, α, γ, τ, l := 0 r:= b−Ax,u:= M−1r,w:= Au,γ:=< r, u >,δ:=< w, u >,τ:=< r, r > while (τ > τmax) Step Operation Kernel Communication if (l > 0) β:= γ/γ0 α0:= α α:= γ/(δ−βγ/α0) else β:= 0 α:= γ/δ endif γ0:= γ S1 :d:= M−1wApply preconditioner – S2 : S2.1:d→e– All gather S2.2:w:= Ae SpMV – S3 :z:= w+βz axpy – S4 :q:= d+βq axpy – S5 :s:= w+βs axpy – S6 :p:= u+βp axpy – S7 :x:= x+αp axpy – S8 :r:= r−αs axpy – S9 :u:= u−αq axpy – S10 :w:= w−αz axpy – S11 :γ:= < r, u > dot product Combined all reduceS12 :δ:= < w, u > dot product S13 :τ:= < r, r > dot product l:= l+ 1 end while Fig. 5 Message-passing formulation of the pipelined BJCG solver annotated with communication patterns. 4 Increasing Task Asynchronism in the BJCG Solver The analysis of the parallel BJCG method in the previous section reveals three synchronization points per iteration. As the degree of hardware concurrency grows, these synchronizations can become more expensive than some of the computational kernels, impairing the parallel scalability of the method; see, e.g., [7,9] In this section, we focus on the pipelined formulation of the CG solver proposed in [9] and its iteration-fusing task-parallel variant in [18], analyzing how to reduce synchronization points in a message-passing implementation. 4.1 Pipelining Message-passing pipelined BJCG solver Figure 5 displays the pipelined BJCG solver. Let us make the same assumptions as those stated in the presentation of the message-passing BJCG solver in subsection 3.1; that is, A, M are both partitioned and distributed by blocks of rows, all vectors are partitioned/distributed conformally unless otherwise stated, and the scalars are globally replicated. Then, we can easily derive that the number of synchronizations have been reduced to only two: –The gathering of the distributed vector yinto the globally replicated copy eprior to the SpMV in S2.1 and S2.2, respectively. –A combined global reduction for the dot products in S11,S12,S13. In this case, the convergence criterion can be tested right after the computation of τ, in S13. Task-parallel pipelined BJCG solver Exploiting two levels of parallelism, by combining MPI with OpenMP or OmpSs, is also possible in the pipelined variant of the method. The dependency pattern in this algorithm can be expressed in the form of a (simplified) TDG as shown in Figure 6.
Iteration-Fusing Conjugate Gradient for Sparse Linear Systems with MPI+OmpSs 9 S1 S2 S10 S12 S1 ... S10 ... S12 ww δ, α δ, α w iteration literation iteration ll +1−1 d Fig. 6 TDG of the dependency pattern in the task-parallel pipelined BJCG solver. For clarity, in this case we merge all axpy(-type) updates into a single kernel (S10) and the three dot products into a single one as well (S12). The purpose of dividing the kernels into fine-grain tasks is to overlap (execute partially in parallel) tasks from different kernels. In the pipelined algorithm, the preconditioner application (S1) is immediately followed by the gathering of vector d(S2.1), in preparation for the SpMV. This introduces a synchronization point which impedes a concurrent execution of these two kernels. In contrast, by dividing the SpMV itself (S2.2) into tasks, these can be executed in parallel with some of the tasks for the subsequent axpy (S10), (as well as tasks for other axpy vector updates). Furthermore, a task-parallelization also allows a partially-concurrent execution of the axpy and the final dot product (S12). In summary, S2.2 kS10 kS12. Unfortunately, after the combined reduction, there appears a new synchronization point implicit to the communication, which is leveraged to test the convergence criterion. Figure 7 offer simplified TDGs of the classical and pipeline versions of the BJCG solver (left and right, respectively), exposing which kernels can proceed in parallel by dividing their execution into multiple tasks. Comparing both TDGs, we can conclude that the classical version comprisses less vector operations than the pipelined version, but the first one requires an additional synchronization step. Implementation using MPI+OmpSs The codes for this scheme annotate tasks using OmpSs directive/clauses. Furthermore, they employ MPI collective primitives for the replication of vector d(MPI_Allgatherv), just before the SpMV; and the global reduction (MPI_Allreduce) of the scalars γ, δ, τ, at the end of the iteration. As in the taskparallel implementation of the plain CG method, an intra-process task-synchronization is enforced, via the introduction of a #pragma oss taskwait, before the MPI_Allgatherv collective. This enforces that all operations on dhave been completed before its replication into e. Similarly, the insertion of directives #pragma oss taskwait on the three scalars being reduced before the MPI_Allreduce ensures the correct behaviour of these operations. 4.2 Iteration-fusing In [18], the authors propose a variant of the pipelined scheme, named iteration-fusing CG (IFCG), that enables the concurrent execution of kernels from consecutive iterations on multicore processors. Specifically, their variant IFCG1 decomposes all kernels into fine-grain tasks, such as we described in previous sections, and relaxes the periodicity of the convergence test, to perform it only every titerations. For those iterations where the test is not checked, on a shared-memory processor this allows that the dot products at the end of one iteration proceed in parallel with the application of the preconditioner and SpMV at the beginning of the subsequent iteration, as there exist no dependencies between them and there is no need for MPI communication primitives; see Figure 5. Our message-passing implementation of the pipelined CG scheme already decomposes the iteration kernels into tasks of fine granularity. At first sight, it could appear that relaxing the periodicity of the iteration test could then unleash the same “iteration-fusing effect” on a message-passing architecture. Unfortunately, the MPI primitive for the (combined) global reductions at the end of the iteration hinder this, as collective routines are blocking. Moreover, the same problem appears in the SpMV, as it is necessary to replicate vector dbefore this operation can commence. An easy way to solve the previous issues would be to use tasks to implement both the computation and communication phases, relying on task dependencies to deal with inter-node and intra-node synchronizations. However, this approach cannot be efficiently implemented with the current MPI and OpenMP specifications. Concretely, MPI provides the MPI_THREAD_MULTIPLE mode, which supports the concurrent invocation of MPI calls from multiple threads, but this is not sufficient to efficiently support task-based programming models such as OmpMP or OmpSs-2. The main issue is that tasks are not aware of the synchronous MPI primitives, which might block not only the task but also the underlying hardware thread that runs it. Even if the MPI implementation does not rely on busy-waiting to check for operation completion and the hardware thread becomes idle, the task runtime has no means to discover
16 María Barreda et al. 18. Zhuang, S., Casas, M.: Iteration-fusing Conjugate Gradient. In: Proceedings of the International Conference on Supercomputing, ICS ’17, pp. 21:1–21:10. ACM, New York, NY, USA (2017). DOI 10.1145/3079079.3079091. URL http://doi.acm.org/10.1145/3079079.3079091