Skip to content

Commit 19cbcc5

Browse files
author
Denis Jelovina
committed
Add table of contenet
1 parent 643d7f1 commit 19cbcc5

File tree

3 files changed

+26
-23
lines changed

3 files changed

+26
-23
lines changed

ALP_Transition_Path_Tutorial.tex

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1+
\section{Introduction to ALP and Transition Paths}\label{sec:intro}
12

2-
\section*{Introduction to ALP and Transition Paths}
3+
\textbf{Algebraic Programming (ALP)} is a C++ framework for high-performance linear algebra that can auto-parallelize and auto-optimize your code. A key feature of ALP is its transition path APIs, which let you use ALP through standard interfaces without changing your existing code. In practice, ALP generates drop-in replacements for established linear algebra APIs. You simply re-link your program against ALP's libraries to get optimized performance (no code modifications needed). ALP v0.8 provides transition-path libraries for several standards, including the NIST Sparse BLAS and a CRS-based iterative solver interface (ALP/Solver). This means you can take an existing C/C++ program that uses a supported API and benefit from ALP's optimizations (such as vectorization and parallelism) just by linking with ALP's libraries [1].
34

4-
\textbf{Algebraic Programming (ALP)} is a C++ framework for high-performance linear algebra that can auto-parallelize and auto-optimize your code. A key feature of ALP is its transition path APIs, which let you use ALP through standard interfaces without changing your existing code. In practice, ALP generates drop-in replacements for established linear algebra APIs. You simply re-link your program against ALP’s libraries to get optimized performance (no code modifications needed). ALP v0.8 provides transition-path libraries for several standards, including the NIST Sparse BLAS and a CRS-based iterative solver interface (ALP/Solver). This means you can take an existing C/C++ program that uses a supported API and benefit from ALP’s optimizations (such as vectorization and parallelism) just by linking with ALP’s libraries [1].
5+
One of these transition paths, and the focus of this tutorial, is ALP's \textbf{sparse Conjugate Gradient (CG) solver}. This CG solver accepts matrices in Compressed Row Storage (CRS) format (also known as CSR) and solves $Ax=b$ using an iterative method. Under the hood it leverages ALP's non-blocking execution model, which overlaps computations and memory operations for efficiency. From the user's perspective, however, the solver is accessed via a simple C-style API that feels synchronous. In this workshop, we'll learn how to use this CG solver interface step by step: from setting up ALP, to coding a solution for a small linear system, to building and running the program.
56

6-
One of these transition paths, and the focus of this tutorial, is ALP’s \textbf{sparse Conjugate Gradient (CG) solver}. This CG solver accepts matrices in Compressed Row Storage (CRS) format (also known as CSR) and solves $Ax=b$ using an iterative method. Under the hood it leverages ALP’s non-blocking execution model, which overlaps computations and memory operations for efficiency. From the user’s perspective, however, the solver is accessed via a simple C-style API that feels synchronous. In this workshop, we’ll learn how to use this CG solver interface step by step: from setting up ALP, to coding a solution for a small linear system, to building and running the program.
7+
\section{Setup: Installing ALP and Preparing to Use the Solver}\label{sec:setup}
78

8-
9-
\section*{Setup: Installing ALP and Preparing to Use the Solver}
109
This section explains how to install ALP on a Linux system and compile a simple example. ALP (Algebraic Programming) provides a C++17 library implementing the GraphBLAS interface for linear-algebra-based computations.
1110

12-
\subsection*{Installation on Linux}
11+
\subsection{Installation on Linux}
1312

1413
\begin{enumerate}
1514
\item Install prerequisites: Ensure you have a C++11 compatible compiler (e.g. \texttt{g++} 4.8.2 or later) with OpenMP support, CMake (>= 3.13) and GNU Make, plus development headers for libNUMA and POSIX threads.
@@ -39,7 +38,7 @@ \subsection*{Installation on Linux}
3938
\begin{lstlisting}[language=bash]
4039
$ source ../install/bin/setenv
4140
\end{lstlisting}
42-
This script updates paths to make ALPs compiler wrapper and libraries available.
41+
This script updates paths to make ALP's compiler wrapper and libraries available.
4342

4443
\item Compile an example: ALP provides a compiler wrapper \texttt{grbcxx} to compile programs that use the ALP/GraphBLAS API. This wrapper automatically adds the correct include paths and links against the ALP library and its dependencies. For example, to compile the provided sp.cpp sample:
4544
\begin{lstlisting}[language=bash]
@@ -54,10 +53,10 @@ \subsection*{Installation on Linux}
5453
(The \texttt{grbrun} tool is more relevant when using distributed backends or controlling the execution environment; for basic usage, the program can also be run directly.)
5554
\end{enumerate}
5655

57-
You can also specify a backend with the -b flag. For instance, -b reference builds a sequential version, while -b reference\_omp enables ALPs shared-memory (OpenMP) parallel backend . If you built ALP with distributed-memory support, you might use -b hybrid or -b bsp1d for hybrid or MPI- nstyle backends. In those cases, you would run the program via grbrun (which handles launching multiple processes) – but for this tutorial, we will use a single-process, multi-threaded backend, so running the program normally is fine.
56+
You can also specify a backend with the -b flag. For instance, -b reference builds a sequential version, while -b reference\_omp enables ALP's shared-memory (OpenMP) parallel backend . If you built ALP with distributed-memory support, you might use -b hybrid or -b bsp1d for hybrid or MPI- nstyle backends. In those cases, you would run the program via grbrun (which handles launching multiple processes) – but for this tutorial, we will use a single-process, multi-threaded backend, so running the program normally is fine.
5857
\\
5958

60-
\textbf{Direct linking option}: If you prefer to compile with your usual compiler, you need to include ALPs headers and link against the ALP libraries manually. For the CG solver transition path, that typically means linking against the sparse solver library (e.g. libspsolver\_shmem\_parallel for the parallel version) and any core ALP libraries it depends on. For example, if ALP is installed in /opt/alp , you might compile with:
59+
\textbf{Direct linking option}: If you prefer to compile with your usual compiler, you need to include ALP's headers and link against the ALP libraries manually. For the CG solver transition path, that typically means linking against the sparse solver library (e.g. libspsolver\_shmem\_parallel for the parallel version) and any core ALP libraries it depends on. For example, if ALP is installed in /opt/alp , you might compile with:
6160

6261
\begin{lstlisting}[language=bash]
6362
gcc -I/opt/alp/include -L/opt/alp/lib \
@@ -66,27 +65,29 @@ \subsection*{Installation on Linux}
6665
\end{lstlisting}
6766

6867

69-
(ALPs documentation provides details on which libraries to link for each backend [3].) Using grbcxx is recommended for simplicity, but its good to know what happens under the hood. Now that our environment is set up, lets look at the CG solver API.
68+
(ALP's documentation provides details on which libraries to link for each backend [3].) Using grbcxx is recommended for simplicity, but it's good to know what happens under the hood. Now that our environment is set up, let's look at the CG solver API.
7069

7170

72-
\section*{Overview of ALPs Non-Blocking Sparse CG API}
71+
\section{Overview of ALP's Non-Blocking Sparse CG API}\label{sec:api}
7372

74-
The ALP/Solver transition path provides a C-style interface for initializing and running a Conjugate Gradient solver. All functions are exposed via a header (e.g. solver.h in ALPs include directory) and use simple types like pointers and handles. The main functions in this API are:
73+
The ALP/Solver transition path provides a C-style interface for initializing and running a Conjugate Gradient solver. All functions are exposed via a header (e.g. solver.h in ALP's include directory) and use simple types like pointers and handles. The main functions in this API are:
7574

7675
\begin{itemize}
7776
\item \textbf{sparse\_cg\_init(\&handle, n, vals, cols, offs):} Initializes a CG solver instance. It allocates/assigns a solver context to the user-provided sparse\_cg\_handle\_t (an opaque handle type defined by ALP). The matrix $A$ is provided in CRS format by three arrays: vals (the nonzero values), cols (the column indices for each value), and offs (offsets in the vals array where each row begins). The dimension n (number of rows, which should equal number of columns for $A$) is also given. After this call, the handle represents an internal solver state with matrix $A$ stored. Return: Typically returns 0 on success (and a non-zero error code on failure) [4].
7877

79-
\item \textbf{sparse\_cg\_set\_preconditioner(handle, func, data):} (Optional) Sets a preconditioner for the iterative solve. The user provides a function func that applies the preconditioner $M^{-1}$ to a vector (i.e. solves $Mz = r$ for a given residual $r$), along with a user data pointer. ALP will call this func(z, r, data) in each CG iteration to precondition the residual. If you don’t call this, the solver will default to no preconditioning (i.e. $M = I$). You can use this to plug in simple preconditioners (like Jacobi, with data holding the diagonal of $A$) or even advanced ones, without modifying the solver code. Return: 0 on success, or error code if the handle is invalid, etc.
78+
\item \textbf{sparse\_cg\_set\_preconditioner(handle, func, data):} (Optional) Sets a preconditioner for the iterative solve. The user provides a function func that applies the preconditioner $M^{-1}$ to a vector (i.e. solves $Mz = r$ for a given residual $r$), along with a user data pointer. ALP will call this func(z, r, data) in each CG iteration to precondition the residual. If you don't call this, the solver will default to no preconditioning (i.e. $M = I$). You can use this to plug in simple preconditioners (like Jacobi, with data holding the diagonal of $A$) or even advanced ones, without modifying the solver code. Return: 0 on success, or error code if the handle is invalid, etc.
79+
80+
\item \textbf{sparse\_cg\_solve(handle, x, b):} Runs the CG iteration to solve $Ax = b$. Here b is the right-hand side vector (input), and x is the solution vector (output). You should allocate both of these arrays of length n beforehand. The solver will iterate until it converges to a solution within some default tolerance or until it reaches an iteration limit. On input, you may put an initial guess in x. If not, it's safe to initialize x to zero (the solver will start from $x_0 = 0$ by default in that case). Upon return, x will contain the approximate solution. Return: 0 if the solution converged (or still 0 if it ran the maximum iterations – specific error codes might indicate divergence or other issues in future versions).
8081

81-
\item \textbf{sparse\_cg\_solve(handle, x, b):} Runs the CG iteration to solve $Ax = b$. Here b is the right-hand side vector (input), and x is the solution vector (output). You should allocate both of these arrays of length n beforehand. The solver will iterate until it converges to a solution within some default tolerance or until it reaches an iteration limit. On input, you may put an initial guess in x. If not, it’s safe to initialize x to zero (the solver will start from $x_0 = 0$ by default in that case). Upon return, x will contain the approximate solution. Return: 0 if the solution converged (or still 0 if it ran the maximum iterations – specific error codes might indicate divergence or other issues in future versions).
82+
\end{itemize}
8283

8384
\item \textbf{sparse\_cg\_destroy(handle):} Destroys the solver instance and releases any resources associated with the given handle. After this, the handle becomes invalid. Always call this when you are done solving to avoid memory leaks. Return: 0 on success (and the handle pointer may be set to NULL or invalid after). This API is non-blocking in the sense that internally ALP may overlap operations (like sparse matrix-vector multiplications and vector updates) and use asynchronous execution for performance. However, the above functions themselves appear synchronous. For example, sparse\_cg\_solve will only return after the solve is complete (there’s no separate “wait” call exposed in this C interface). The benefit of ALP’s approach is that you, the developer, don’t need to manage threads or message passing at all ALP’s GraphBLAS engine handles parallelism behind the scenes. You just call these routines as you would any standard library. Now, let’s put these functions into practice with a concrete example.
8485
\end{itemize}
8586

8687
This API is non-blocking in the sense that internally ALP may overlap operations (like sparse matrix-vector multiplications and vector updates) and use asynchronous execution for performance. However, the above functions themselves appear synchronous. For example, sparse\_cg\_solve will only return after the solve is complete (there’s no separate “wait” call exposed in this C interface). The benefit of ALP’s approach is that you, the developer, don’t need to manage threads or message passing at all. ALP’s GraphBLAS engine handles parallelism behind the scenes. You just call these routines as you would any standard library. Now, let’s put these functions into practice with a concrete example.
8788

8889

89-
\section*{Example: Solving a Linear System with ALP’s CG Solver}
90+
\section{Example: Solving a Linear System with ALP’s CG Solver}
9091

9192
Suppose we want to solve a small system $Ax = b$ to familiarize ourselves with the CG interface. We will use the following $3 \times 3$ symmetric positive-definite matrix $A$: $$ A = \begin{pmatrix} 4 & 1 & 0\\
9293
1 & 3 & -1\\
@@ -192,7 +193,7 @@ \section*{Example: Solving a Linear System with ALP’s CG Solver}
192193

193194

194195

195-
\section*{Building and Running the Example}
196+
\section{Building and Running the Example}
196197
To compile the above code with ALP, we will use the direct linking option as discussed.
197198
\begin{lstlisting}[language=bash]
198199
g++ example.cpp -o cg_demo \

ALP_Tutorial.tex

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
\section{Quick Start}
1+
\section{Quick Start}\label{sec:quick_start}
22

33
This section explains how to install ALP on a Linux system and compile a simple example. ALP (Algebraic Programming) provides a C++17 library implementing the GraphBLAS interface for linear-algebra-based computations. To get started quickly:
44

5-
\subsection*{Installation on Linux}
5+
\subsection{Installation on Linux}
66

77
\begin{enumerate}
88
\item Install prerequisites: Ensure you have a C++11 compatible compiler (e.g. \texttt{g++} 4.8.2 or later) with OpenMP support, CMake (>= 3.13) and GNU Make, plus development headers for libNUMA and POSIX threads.
@@ -46,7 +46,7 @@ \subsection*{Installation on Linux}
4646
\end{enumerate}
4747
After these steps, ALP is installed and you are ready to develop ALP-based programs. In the next sections we introduce core ALP concepts and walk through a simple example program.
4848

49-
\section{Introduction to ALP Concepts}
49+
\section{Introduction to ALP Concepts}\label{sec:alp_concepts}
5050

5151
ALP exposes a programming model similar to the GraphBLAS standard, using algebraic containers (vectors, matrices, etc.) and algebraic operations on those containers. This section covers the basic data structures, the algebraic structures (semirings) that define how arithmetic is done, and key primitive operations (such as matrix-vector multiply and element-wise operations).
5252

@@ -63,7 +63,7 @@ \subsection{Vectors and Matrices in ALP}
6363

6464
By default, new vectors/matrices start empty (with no stored elements). You can query properties like length or dimensions via \texttt{grb::size(vector)} for vector length, \texttt{grb::nrows(matrix)} and \texttt{grb::ncols(matrix)} for matrix dimensions, and \texttt{grb::nnz(container)} for the number of stored nonzero elements.
6565

66-
\subsubsection*{Exercise: Allocating Vectors and Matrices in ALP}
66+
\subsubsection{Exercise: Allocating Vectors and Matrices in ALP}
6767

6868
Write a C++ program that uses ALP to allocate two vectors and one matrix as follows:
6969
\begin{itemize}
@@ -190,7 +190,7 @@ \subsection{Primitive Operations (mxv, eWiseMul, dot, etc.)}
190190

191191

192192

193-
\section{Simple Example}
193+
\section{Simple Example}\label{sec:simple_example}
194194

195195
To illustrate ALP usage, let's create a simple C++ program that:
196196
\begin{itemize}
@@ -429,7 +429,7 @@ \section{Simple Example}
429429
\end{lstlisting}
430430

431431

432-
\section{Makefile and CMake Instructions}
432+
\section{Makefile and CMake Instructions}\label{sec:build_instructions}
433433

434434
Finally, we provide guidance on compiling and running the above example in your own development environment. If you followed the installation steps and used \texttt{grbcxx}, compilation is straightforward. Here we outline two approaches: using the ALP wrapper scripts, and integrating ALP manually via a build system.
435435

main.tex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@
3131
3232
\maketitle
3333
34-
\section*{Welcome to My GitHub Pages LaTeX Document!}
34+
\section{Welcome to GitHub Pages generated from LaTeX Document!}
3535
3636
This document was compiled from \LaTeX{} source code using GitHub Actions and deployed to GitHub Pages.
3737
38+
\tableofcontents
39+
3840
\input{ALP_Tutorial.tex}
3941
4042
\input{ALP_Transition_Path_Tutorial.tex}

0 commit comments

Comments
 (0)