-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbeamer-tutorial.tex
More file actions
2168 lines (1955 loc) · 86.6 KB
/
beamer-tutorial.tex
File metadata and controls
2168 lines (1955 loc) · 86.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\documentclass[aspectratio=169]{beamer}
\usetheme{Madrid}
\usecolortheme{seahorse}
\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{footline}[frame number]
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{graphicx}
\usepackage{amsmath,amssymb,mathtools}
\usepackage{hyperref}
\usepackage{xcolor}
\usepackage{listings}
% Simple diagram support
\usepackage{tikz}
\usetikzlibrary{arrows.meta,positioning}
\newcommand{\PA}[1]{{\textcolor{cyan}{[{\bfseries PA:} #1]}}}
\newcommand{\DeJ}[1]{{\textcolor{magenta}{[{\bfseries DJ:} #1]}}} % DJ was taken!
\newcommand{\AJ}[1]{{\textcolor{green}{[{\bfseries AJ:} #1]}}}
\newcommand{\GG}[1]{{\textcolor{blue}{[{\bfseries GG:} #1]}}}
% Map common Unicode symbols to LaTeX math (outside listings)
\usepackage{newunicodechar}
\newunicodechar{·}{\ensuremath{\cdot}}
\newunicodechar{⊙}{\ensuremath{\odot}}
\newunicodechar{ᵀ}{\ensuremath{^{\top}}}
\newunicodechar{×}{\ensuremath{\times}}
\newunicodechar{–}{-}
\newunicodechar{—}{-}
% Listing styles (Unicode-safe for later use)
\definecolor{terminalback}{rgb}{0.9,0.9,0.9}
\definecolor{terminaltext}{rgb}{0.1,0.1,0.1}
\lstdefinestyle{terminal}{
backgroundcolor=\color{gray!20},
basicstyle=\ttfamily\small\color{terminaltext},
frame=single, rulecolor=\color{white}, breaklines=true,
captionpos=b, showstringspaces=false,
upquote=true, columns=fullflexible,
commentstyle=\color{terminaltext},
keywordstyle=\color{terminaltext},
stringstyle=\color{terminaltext},
identifierstyle=\color{terminaltext},
literate={·}{{$\cdot$}}1 {⊙}{{$\odot$}}1 {ᵀ}{{$^\top$}}1 {×}{{$\times$}}1 {‐}{{-}}1 {–}{{-}}1 {—}{{-}}1
}
\lstdefinestyle{code}{
backgroundcolor=\color[rgb]{0.95,0.95,0.95},
basicstyle=\ttfamily\small, frame=single, breaklines=true, showstringspaces=false,
rulecolor=\color{black}, numbers=none, keepspaces=true, captionpos=b, tabsize=2,
language=C++,
literate={·}{{$\cdot$}}1 {⊙}{{$\odot$}}1 {ᵀ}{{$^\top$}}1 {×}{{$\times$}}1 {‐}{{-}}1 {"}{{"`}}1 {"}{{'"}}1
}
\lstdefinestyle{cpp-rich}{
language=C++,
basicstyle=\ttfamily\scriptsize,
keywordstyle=\color{blue}\bfseries,
identifierstyle=\color{black},
commentstyle=\color{gray}\itshape,
stringstyle=\color{green!50!black},
morekeywords={nullptr,override,final,constexpr},
showstringspaces=false,
upquote=true,
frame=single,
rulecolor=\color{black},
breaklines=true,
columns=fullflexible,
keepspaces=true,
tabsize=2,
backgroundcolor=\color[rgb]{0.95,0.95,0.95},
literate={·}{{$\cdot$}}1 {⊙}{{$\odot$}}1 {ᵀ}{{$^\top$}}1 {×}{{$\times$}}1 {‐}{{-}}1 {–}{{-}}1 {—}{{-}}1
}
% make it the default
\lstset{style=cpp-rich}
% alias macro (use in optional args: \begin{lstlisting}[\cpplistingstyle])
\newcommand{\cpplistingstyle}{style=cpp-rich}
\title{Algebraic Programming (ALP) Tutorial}
%\subtitle{From HPC to GraphBLAS and Transition Paths}
\author{ALP HIPO Team}
\date{\today}
% Show roadmap before each section/subsection with upcoming content highlighted
\AtBeginSection{
\begin{frame}{Roadmap}
\tableofcontents[currentsection,sectionstyle=show/shaded,subsectionstyle=show/show/hide]
\end{frame}
}
\AtBeginSubsection{
\begin{frame}{Roadmap}
\tableofcontents[currentsection,currentsubsection,sectionstyle=show/shaded,subsectionstyle=show/shaded/hide]
\end{frame}
}
\begin{document}
\frame{\titlepage}
% =========================
% Monday 10 Nov, Morning
% =========================
\section{Monday 10 Nov, Morning}
% One initial agenda slide for Monday; will be auto-repeated via Roadmap frames
\begin{frame}{Today's Plan}
Morning:
\begin{enumerate}
\item Introduction to ALP, installation, and short demos
\item Hands-on (I): installation, containers, I/O, copying, masking, and standard matrices
\item Introduction to core primitives
\item Hands-on (II): numerical linear algebra
\item Interoperability with existing code: transition paths \& Python
\end{enumerate}\vspace{\baselineskip}
Afternoon:
\begin{enumerate}\setcounter{enumi}{6}
\item Ising Machine, and
\item other solvers
\end{enumerate}
\end{frame}
\subsection{1) Introduction to ALP, installation, and short demos}
% Owner: DJ
% Intro (concise outline)
\begin{frame}{Introduction to GraphBLAS and ALP}
\begin{itemize}
\item What you'll learn: algebraic programming for graphs and sparse data
\item Who it's for: HPC developers and solver authors
\item How we'll use ALP: C++ headers, precompiled libraries, Python API
\end{itemize}
% Owner: DJ
% TODO: add a one-slide agenda summary graphic
\end{frame}
% Slide 1
\begin{frame}{Goals, Audience, and Scope}
\begin{itemize}
\item Goals
\begin{itemize}
\item Express algorithms as algebra over vectors/matrices
\item Introduce GraphBLAS: containers, primitives, masks
\item Demonstrate ALP backends for performance portability
\end{itemize}
\item Audience
\begin{itemize}
\item Developers of HPC applications, graph analytics, and solvers
\item No prior GraphBLAS/ALP knowledge assumed
\end{itemize}
\item Scope: multiple usage modes
\begin{itemize}
\item C++ header library for new algorithms/solvers (template API)
\item Precompiled libraries: use provided algorithms as black boxes
\item Python API for precompiled algorithms
\end{itemize}
\end{itemize}
% Owner: DJ
% Source: ALP_Tutorial.tex (intro), alp_graphblas_tutorial.txt (overview)
\end{frame}
% Slide 2
\begin{frame}{ALP in One Slide: Programming Model and Backends}
\begin{itemize}
\item Programming model (humble by design)
\begin{itemize}
\item Heavily templated C++ header library (no runtime codegen)
\item Hardware-unaware, hardware-independent user code
\item Algebraic API: write what to compute, not how
\end{itemize}
\item Backends handle hardware specifics
\begin{itemize}
\item reference (single-threaded), \texttt{reference\_omp} (OpenMP)
\item nonblocking (multi-threaded with auto-fusion)
\item bsp1d (distributed/LPF), dense-dispatch (BLAS-backed, WIP), tensor (experimental, WIP)
\item Same source runs across backends with consistent semantics
\end{itemize}
\item Flexible infrastructure
\begin{itemize}
\item Rich type system and traits enable different and mixed data-type operations
\item Compile-time algebraic properties (associative, commutative, idempotent, annihilators)
are known to the backends and propagate from top to bottom of the algorithm
\end{itemize}
\end{itemize}
% Owner: DJ
\end{frame}
% Slide 2b (graphic)
\begin{frame}{ALP in One Slide: Programming Model and Backends (Graphic)}
\centering
\scriptsize
\begin{tikzpicture}[
node distance=8mm and 6mm,
mainbox/.style={rounded corners, draw, very thick, align=center, inner sep=2pt, minimum height=0.75cm, text width=.56\linewidth},
sidebox/.style={rounded corners, draw, very thick, align=left, inner sep=2pt, text width=.18\linewidth},
arrow/.style={-{Latex[length=1.6mm,width=1.6mm]}, very thick, shorten >=6pt, shorten <=6pt}
]
% Main vertical flow (compact stack)
\node[mainbox, fill=blue!10] (user) {User Algorithm (C++ via ALP/GraphBLAS API, or Python bindings)};
\node[mainbox, fill=cyan!10, below=8mm of user] (api) {GraphBLAS Algebraic API: Vectors/Matrix containers, Operators/Monoids/Semirings, Masks/Descriptors};
% Compile-time traits note placed between API and Backends
\node[mainbox, fill=yellow!15, below=8mm of api] (traits) {Compile-time traits \& algebraic properties propagate down (types, identities, associativity, commutativity, idempotence)};
\node[mainbox, fill=green!12, below=8mm of traits] (backends) {Backend selection (same source, consistent semantics):\ \texttt{reference}, \texttt{reference\_omp}, nonblocking, bsp1d, dense-dispatch (WIP), tensor (exp.)};
\node[mainbox, fill=orange!15, below=8mm of backends] (exec) {Optimized execution: fusion, mask-aware scheduling, blocking/tiling, kernel dispatch (mxv/vxm, mxm, eWise*, reductions), runtime/platform (CPU/OpenMP, LPF, BLAS path)};
\draw[arrow] (user) -- (api);
\draw[arrow] (backends) -- (exec);
% Side inputs/metadata
\node[sidebox, dashed, draw=gray, fill=white, right=2mm of api] (desc) {Descriptors \& Masks\\ replace, accumulate, transpose};
\draw[arrow, dashed] (desc.west) -- (api.east);
\node[sidebox, dashed, draw=gray, fill=white, left=2mm of api] (io) {Parsers \& Builders\\ MatrixMarket, buildMatrixUnique};
\draw[arrow, dashed] (io.east) -- (api.west);
\draw[arrow] (api.south) -- (traits.north);
\draw[arrow] (traits.south) -- (backends.north);
\end{tikzpicture}
\end{frame}
% Slide 3
\begin{frame}{What is GraphBLAS: Concepts and Motivation}
\begin{itemize}
\item Motivation
\begin{itemize}
\item Graphs map to sparse matrices; algorithms to linear algebra
\item Sparse/graph workloads are bandwidth-bound and irregular
\end{itemize}
\item Core concepts
\begin{itemize}
\item Semirings $\langle D,\oplus,\otimes\rangle$ (plus–times, min–plus, Boolean)
\item Primitives: mxv/vxm, mxm, eWiseAdd/Mul/Apply, dot, masks, descriptors
\item Containers: \texttt{grb::Vector<T>}, \texttt{grb::Matrix<T>}
\end{itemize}
\item Why beyond traditional dense LA
\begin{itemize}
\item Algebraic flexibility enables BFS, SSSP, etc., via non-standard "addition" and "multiplication"
\item Masking and sparsity-aware execution preserve efficiency
\end{itemize}
\end{itemize}
% Owner: DJ
% Source: alp_graphblas_tutorial.txt (GraphBLAS), ALP_Tutorial.tex (ALP/GraphBLAS)
\end{frame}
% Slide 4
\begin{frame}{Automation and Optimization Space}
\begin{itemize}
\item What automation to expect (from ALP backends)
\begin{itemize}
\item Auto-parallel execution (threads/processes) across backends
\item Cache-aware blocking/tiling; minimized data movement
\item Mask-aware computation and potential kernel fusion (backend-dependent)
\end{itemize}
\item Algorithm-level optimization space (ALP vs. BLAS/LAPACK)
\begin{itemize}
\item ALP: end-to-end algebraic programs expose global opportunities
(fusion across primitives, mask-driven sparsity cuts, reordering, schedule selection)
\item LAPACK: dense factorizations focus on tiling and blocking inside fixed algorithms
\item BLAS-only: kernel-local tuning; limited visibility for cross-kernel optimizations
\end{itemize}
\item Portability outcome
\begin{itemize}
\item Express once at the algebraic level; get optimized code on shared, distributed, or hybrid memory systems
\item Mixed-type and custom-operator workflows supported via templates
\end{itemize}
\end{itemize}
% Owner: DJ
% TODO: add a tiny mxv code snippet + "same code, different backend" example timings
% Source: ALP_Tutorial.tex (semantics, portability), alp_graphblas_tutorial.txt (landscape)
\end{frame}
% (Duplicate intro frames removed below to avoid repetition)
\begin{frame}[fragile]{1. ALP Installation}
\framesubtitle{Prerequisites (skip if already installed)}
\begin{itemize}
\item Requirements:
\begin{itemize}
\item C++11 compiler, OpenMP, CMake (>=3.13), libNUMA, pthreads
\end{itemize}
\item Debian/Ubuntu:
\begin{lstlisting}[style=terminal, language=bash]
sudo apt-get install build-essential libnuma-dev libpthread-stubs0-dev cmake
\end{lstlisting}
\item Red Hat/CentOS:
\begin{lstlisting}[style=terminal, language=bash]
dnf group install "Development Tools"
dnf install numactl-devel cmake
\end{lstlisting}
\item Clone \textbf{ALP-Tutorial} from the official GitHub repository:
\begin{lstlisting}[style=terminal, language=bash]
git clone https://github.com/Algebraic-Programming/ALP-Tutorial.git
\end{lstlisting}
\end{itemize}
% Owner: PA
% Source (ALP_Tutorial.tex - Installation on Linux, step 1)
\end{frame}
\begin{frame}[fragile]{1. ALP Installation}
\framesubtitle{Obtain and Build ALP}
\begin{enumerate}
\item Clone \textbf{ALP} from the official GitHub repository:
\begin{lstlisting}[style=terminal, language=bash]
git clone https://github.com/Algebraic-Programming/ALP.git
\end{lstlisting}
\item Build and install \textbf{ALP} with default configuration settings:
\begin{lstlisting}[style=terminal, language=bash]
cd ALP && mkdir build && cd build
../bootstrap.sh --prefix=../install
make -j
make install
\end{lstlisting}
\item \textbf{Activate ALP environment}:
\begin{lstlisting}[style=terminal, language=bash]
source ../install/bin/setenv
\end{lstlisting}
\end{enumerate}
% Owner: PA
% Source (ALP_Tutorial.tex - Installation on Linux, steps 2-3)
\end{frame}
\begin{frame}[fragile]{1. ALP Installation}
\framesubtitle{Setup Environment and Test}
\begin{enumerate}
\item Return to the \textbf{ALP-Tutorial} directory:
\begin{lstlisting}[style=terminal, language=bash]
cd ../ALP-Tutorial/scripts
\end{lstlisting}
\item \textbf{Compile example}:
\begin{lstlisting}[style=terminal, language=bash]
grbcxx sp.cpp -o sp_example
\end{lstlisting}
\item \textbf{Run}:
\begin{lstlisting}[style=terminal, language=bash]
grbrun ./sp_example
\end{lstlisting}
\end{enumerate}
% Owner: PA
% Source (ALP_Tutorial.tex - Installation on Linux, steps 4-6)
\end{frame}
\begin{frame}[fragile]{2. Hands-on: Setting up scripts}
\framesubtitle{ALP/GraphBLAS Overview}
\begin{itemize}
\item You can find code skeletons for the tutorial in: \texttt{path/to/alp-tutorial/scripts}
% \item You should copy the scripts to your home directory:
% \begin{lstlisting}[style=terminal, language=bash]
% cp -r /some/path/to/alp/tutorial/scripts ~/alp_tutorial_scripts
% cd ~/alp_tutorial_scripts && ls -l
%\end{lstlisting}
\item You can use any editor of your preference to edit these scripts (e.g. nano, vim, gedit)
\item Run these commands to test your setup:
\begin{lstlisting}[style=terminal, language=bash]
grbcxx alp_hw.cpp
grbrun ./a.out
\end{lstlisting}
\item \textbf{Expected output}:
\begin{lstlisting}[style=terminal, language=bash]
Info: grb::init (reference) called.
Hello from ./a.out
Info: grb::finalize (reference) called.
\end{lstlisting}
\end{itemize}
\end{frame}
\begin{frame}[fragile]{2. Hands-on: What did we just run?}
\framesubtitle{Hello World in ALP/GraphBLAS}
\vspace{-0.6em}
\begin{lstlisting}[style=cpp-rich, language=C++, basicstyle=\ttfamily\scriptsize]
#include <cstddef>
#include <cstring>
#include <graphblas.hpp>
#include <assert.h>
constexpr size_t max_fn_size = 255;
typedef char Filename[ max_fn_size ];
void hello_world( const Filename &in, int &out ) {
std::cout << "Hello from " << in << std::endl;
out = 0;
}
int main( int argc, char ** argv ) {
Filename fn;
std::strncpy( fn, argv[0], max_fn_size );
int error_code = 100;
grb::Launcher< grb::AUTOMATIC > launcher;
assert( launcher.exec( &hello_world, fn, error_code, true ) == grb::SUCCESS );
return error_code;
}
\end{lstlisting}
% Owner: PA
% Source (ALP_Tutorial.tex - ALP/GraphBLAS, Hello World)
\end{frame}
\begin{frame}{2. Hands-on: What did we just run?}
\framesubtitle{ALP/GraphBLAS Overview}
\begin{itemize}
\item Pure C++ (developed similarly to the GraphBLAS C specification)
\item Exposes a GraphBLAS interface with 3 categories (part of the \texttt{grb} namespace):
\begin{itemize}
\item Algebraic containers (vectors, matrices, etc.)
\item Algebraic structures (binary operators, semirings, etc.)
\item Algebraic operations (take containers and structures as arguments)
\end{itemize}
\item \textbf{\texttt{grb::Launcher}}:
\begin{itemize}
\item Wraps calls to ALP programs
\item Adapts to run-time conditions (e.g., distributed execution)
\item \textbf{Question:} Why is the last argument to \texttt{launcher.exec} \texttt{true}?
\begin{itemize}
\item Consider the programmer reference documentation for the \texttt{grb::Launcher}...
\end{itemize}
\end{itemize}
\item All ALP programs: input (\href{https://www.geeksforgeeks.org/cpp/pod-type-in-cpp/}{\textcolor{blue}{POD}}) $\rightarrow$ output (POD)
\begin{itemize}
\item \textbf{\texttt{hello\_world} example}:
\begin{itemize}
\item \textbf{Question:} Why is \texttt{argv[0]} not directly passed as input to \texttt{hello\_world}?
\item Returns zero error\_code as output (POD type)
\end{itemize}
\end{itemize}
\end{itemize}
\vfill
\colorbox{gray!20}{
\begin{minipage}{0.95\textwidth}
\small
\textbf{For more info:} ALP Documentation: \url{http://albert-jan.yzelman.net/alp/user/}
\end{minipage}}
% Owner: PA
% Source (ALP_Tutorial.tex - ALP/GraphBLAS, Hello World explanation)
\end{frame}
\subsection{2) Hands-on: installation, containers, I/O, copying, masking, standard matrices (2–3.3)}
\begin{frame}[fragile]{2.1. Hands-on: Containers}
\framesubtitle{2.1. ALP/GraphBLAS Containers}
\begin{itemize}
\item \textbf{Primary containers:} \texttt{grb::Vector<T>} and \texttt{grb::Matrix<T>}
\begin{itemize}
\item Templated on value type \texttt{T} (any POD type: \texttt{double}, \texttt{std::complex<T>}, etc.)
\item Support for sparse: Store nonzeros efficiently internally (with CSR/CSC formats)
\end{itemize}
\item \textbf{Examples:}
\begin{lstlisting}[style=cpp-rich, language=C++, basicstyle=\ttfamily\scriptsize]
grb::Vector<double> x(100000), y(150000);
grb::Matrix<void> A(150000, 100000);
\end{lstlisting}
\begin{itemize}
\item \textbf{Note:} \texttt{Matrix<void>} stores pattern only (Boolean matrices/unweighted graphs)
\end{itemize}
\item \textbf{Container Properties:}
\begin{itemize}
\item \texttt{grb::size(vector)}, \texttt{grb::nrows(matrix)}, \texttt{grb::ncols(matrix)}: dimensions
\item \texttt{grb::nnz(container)}: number of stored elements ($<<$ nrows $\times$ ncols for sparse matrices)
\item \texttt{grb::capacity(container)}: maximum capacity (default: max dimension)
\end{itemize}
\item \textbf{Basics:} New containers are \textbf{empty}; size is \textbf{fixed}, capacity \textbf{can be increased}
\end{itemize}
% Owner: PA
% Source (ALP_Tutorial.tex - ALP/GraphBLAS Containers)
\end{frame}
\begin{frame}[fragile]{2.1. Hands-on: Containers}
\framesubtitle{Exercise 2}
\vspace{-0.5em}
\textbf{Exercise 2.} Allocate the following vectors and matrices:
\begin{itemize}
\item \texttt{grb::Vector<double>} \texttt{x}: length 100, capacity 100
\item \texttt{grb::Vector<double>} \texttt{y}: length 1000, capacity 1000
\item \texttt{grb::Matrix<double>} \texttt{A}: size $(100 \times 1000)$, capacity 1000
\item \texttt{grb::Matrix<double>} \texttt{B}: size $(100 \times 1000)$, capacity 5000
\item Start from \texttt{alp\_hw.cpp} (in the \texttt{hello\_world} function)
\begin{lstlisting}[style=terminal, language=bash, basicstyle=\ttfamily\scriptsize\color{terminaltext}]
cp alp_hw.cpp alp_containers_ex2.cpp
\end{lstlisting}
\item \textbf{Hint:} \href{http://albert-jan.yzelman.net/alp/user/group__IO.html#ga0857eef4e6995027be48e7d6b03ea4d3}{\textcolor{blue}{search the documentation}} for \texttt{grb::resize} to override the default capacities
\end{itemize}
\textbf{Expected output}:
\begin{lstlisting}[style=terminal, language=bash, basicstyle=\ttfamily\scriptsize\color{terminaltext}]
Info: grb::init (reference) called.
Capacity of x: 100
Capacity of y: 1000
Capacity of A: 1000
Capacity of B: 5000
Info: grb::finalize (reference) called.
\end{lstlisting}
\textbf{Question.} Is overriding the default capacity necessary for all of \texttt{x, y, A} and \texttt{B}?
% Owner: PA
% Source (ALP_Tutorial.tex - ALP/GraphBLAS Containers, Exercise 2)
\end{frame}
\begin{frame}[fragile]{2.2. Hands-on: Basic Container I/O}
\framesubtitle{Container primitives and Exercise 3}
\begin{columns}[T]
\begin{column}{0.45\textwidth}
\textbf{Container manipulation primitives:}
\begin{itemize}
\item \texttt{grb::clear(container)}:\\ removes all elements
\item \texttt{grb::set(vector,scalar)}:\\ sets all elements to \textit{scalar} (-> dense)
\item \texttt{grb::setElement(vector,scalar
\\,index)}: sets element at \textit{index} to \textit{scalar}
\end{itemize}
\end{column}
\begin{column}{0.5\textwidth}
\textbf{Exercise 3.} Allocate:
\begin{itemize}
\item \texttt{grb::Vector<bool>} \texttt{x}, \texttt{y}:\\ length 497, capacities 497 and 1
\item \texttt{grb::Matrix<void>} \texttt{A}:\\ size $497 \times 497$, capacity 1727
\item Initialize \texttt{y} with \texttt{true} at index 200
\item Initialize \texttt{x} with \texttt{false} everywhere
\item Print nnz for \texttt{x} and \texttt{y}
\end{itemize}
\end{column}
\end{columns}
\vspace{1em}
Start from \texttt{alp\_containers\_ex2.cpp}
\begin{lstlisting}[style=terminal, language=bash, basicstyle=\ttfamily\scriptsize\color{terminaltext}]
cp alp_containers_ex2.cpp alp_containers_ex3.cpp
\end{lstlisting}
% \textbf{Expected output:}
% \begin{lstlisting}[style=terminal, language=bash, basicstyle=\ttfamily\scriptsize\color{terminaltext}]
% nonzeroes in x: 497
% nonzeroes in y: 1
% \end{lstlisting}
\textbf{Bonus question:} Print the capacity of \texttt{y}. Should the value returned be unexpected, considering the specification in the user documentation? Is this a bug in ALP?
% Owner: PA
% Source (ALP_Tutorial.tex - Basic Container I/O, Exercise 3)
\end{frame}
\begin{frame}[fragile]{2.2. Hands-on: Basic Container I/O}
\framesubtitle{Exercise 4: Itterators}
ALP/GraphBLAS exposes \textbf{C++ STL-compatible iterators:}
\begin{lstlisting}[style=cpp-rich, language=C++, basicstyle=\ttfamily\scriptsize]
for( const auto &pair : y ) {
std::cout << "y[" << pair.first << "]=" << pair.second << "\n";
}
\end{lstlisting}
\textbf{Exercise 4.} Use output iterators to double-check that \texttt{x} has $497$ values and that all those values equal \texttt{false}:
\begin{itemize}
\item Use STL-compatible iterators to iterate over \texttt{x}
\item Count the number of entries and verify each value is \texttt{false}
\end{itemize}
Start from \texttt{alp\_containers\_ex3.cpp}
\begin{lstlisting}[style=terminal, language=bash, basicstyle=\ttfamily\scriptsize\color{terminaltext}]
cp alp_containers_ex3.cpp alp_containers_ex4.cpp
\end{lstlisting}
% Owner: PA
% Source (ALP_Tutorial.tex - Basic Container I/O, Exercise 4)
\end{frame}
\begin{frame}[fragile]{2.2. Hands-on: Basic Container I/O}
\framesubtitle{Container file I/O}
ALP supports reading sparse matrices from common file formats(e.g. MatrixMarket \texttt{.mtx})
\begin{itemize}
\item \textbf{MatrixMarket file parser:}
\begin{lstlisting}[style=cpp-rich, language=C++, basicstyle=\ttfamily\scriptsize]
#include <graphblas/utils/parser.hpp>
std::string in( "matrix_file.mtx" );
grb::utils::MatrixFileReader< double > parser( in, true );
const auto iterator = parser.begin();
std::cout << "First parsed entry: ( " << iterator.i() << ", " << iterator.j() << " ) = " << iterator.v() << "\n";
\end{lstlisting}
\begin{itemize}
\item \textbf{Constructor}: \texttt{filename, consecutive\_vertices (use = \texttt{true} for .mtx)}
\item \textbf{Sparse iterators}: \texttt{iterator.i()}, \texttt{iterator.j()}, \texttt{iterator.v()}
\end{itemize}
\item \textbf{Building/loading matrices from files:}
\begin{lstlisting}[style=cpp-rich, language=C++, basicstyle=\ttfamily\scriptsize]
grb::RC rc = grb::buildMatrixUnique( A, parser.begin(grb::SEQUENTIAL),
parser.end(grb::SEQUENTIAL),grb::SEQUENTIAL);
\end{lstlisting}
\item \textbf{Iterator types:} \texttt{SEQUENTIAL} (all elements) vs \texttt{PARALLEL} (subset per process)
\item \textbf{Return codes:} \texttt{grb::RC} (error codes) -> \texttt{grb::SUCCESS} on success
\end{itemize}
% Owner: PA
% Source (ALP_Tutorial.tex - Basic Container I/O)
\end{frame}
\begin{frame}[fragile]{2.2. Hands-on: Basic Container I/O}
\framesubtitle{Exercise 5: File I/O}
\textbf{Exercise 5.} Use the \texttt{MatrixFileReader} and its iterators to build \texttt{A} from \texttt{west0497.mtx}:
\begin{itemize}
\item Use \texttt{MatrixFileReader} and \texttt{buildMatrixUnique}
\item Print the number of nonzeroes in \texttt{A} after \texttt{buildMatrixUnique}
\item Modify the \texttt{main} function to take as the first program argument a path to an .mtx file
\item Pass that path to the ALP/GraphBLAS program
\end{itemize}
\textbf{Download the west0497 matrix from the SuiteSparse matrix collection:}
\begin{lstlisting}[style=terminal, language=bash, basicstyle=\ttfamily\scriptsize\color{terminaltext}]
wget "https://suitesparse-collection-website.herokuapp.com/MM/HB/west0497.tar.gz" && tar -xzvf west0497.tar.gz
\end{lstlisting}
\textbf{Run the application with the path \texttt{./west0497/west0497.mtx}. Expected output:}
\begin{lstlisting}[style=terminal, language=bash, basicstyle=\ttfamily\scriptsize\color{terminaltext}]
./a.out ./west0497/west0497.mtx
First parsed entry: ( 495, 496 ) = 0.897354
nonzeroes in A: 1727
\end{lstlisting}
\textbf{Bonus question:} Why is there no \texttt{grb::set(matrix,scalar)} primitive?
% Owner: PA
% Source (ALP_Tutorial.tex - Basic Container I/O, Exercise 5)
\end{frame}
\begin{frame}[fragile]{3.3. Hands-on: Copying, Masking, and Standard Matrices}
\framesubtitle{Copying with Resize/Execute Phases}
\texttt{grb::set} supports copying containers with automatic capacity management:
\begin{lstlisting}[style=cpp-rich, language=C++, basicstyle=\ttfamily\scriptsize]
grb::RC rc = grb::set( x, y ); // Works normally
\end{lstlisting}
But... if capacity $B$(497) $<$ $A$ nnz (1727), \texttt{grb::set(B, A)} returns \textbf{grb::ILLEGAL}
\begin{lstlisting}[style=cpp-rich, language=C++, basicstyle=\ttfamily\scriptsize]
grb::Matrix< double > B( 497, 497 );
rc = rc ? rc : grb::set( B, A ); // grb::ILLEGAL, B capacity violation
\end{lstlisting}
\textbf{Solution:} use \texttt{RESIZE} phase first, then \texttt{EXECUTE}
\begin{lstlisting}[style=cpp-rich, language=C++, basicstyle=\ttfamily\scriptsize]
rc = rc ? rc : grb::set( B, A, grb::RESIZE );
rc = rc ? rc : grb::set( B, A, grb::EXECUTE );
\end{lstlisting}
\begin{itemize}
\item \textbf{Resize phase}: ALP figures out required capacity and resizes if necessary
\item \textbf{Execute phase}: Performs the copy (default if omitted)
\end{itemize}
\textbf{Question.} What does the code pattern \texttt{rc = rc ? rc : <function call>;} achieve?
\textbf{Question.} $A$ contains $1727$ double-precision elements. Are these $1727$ nonzeroes?
% Owner: PA
% Source (ALP_Tutorial.tex - Copying, Masking, and Standard Matrices)
\end{frame}
\begin{frame}[fragile]{3.3. Hands-on: Copying, Masking, and Standard Matrices}
\framesubtitle{Masking}
\texttt{grb::set} can also accept a \textit{mask} argument that determines which outputs are computed:
\begin{itemize}
\item The mask determines which positions get output entries
\item All GraphBLAS primitives with output containers can take mask arguments
\end{itemize}
\begin{lstlisting}[style=cpp-rich, language=C++, basicstyle=\ttfamily\scriptsize]
grb::RC rc = grb::set( x, y, false ); // Second argument is a mask
\end{lstlisting}
\textbf{Example}: If $y$ has only $y[200]=\texttt{true}$, then \texttt{grb::set(x, y, false)} results in $x$ having only one entry: $x[200]=\texttt{false}$. Why?
\begin{itemize}
\item Mask evaluates \texttt{false} for positions where $y$ has no element (no output generated)
\item At position $200$, mask $y$ contains \texttt{true}, so output entry is generated
\end{itemize}
\textbf{Question.} What would \texttt{grb::set( y, x, true )} return for $y$, assuming it is computed immediately after the preceding code snippet?
% \begin{itemize}
% \item The mask evaluates \texttt{true} for positions where $x$ has an element
% \item The output is the same as the input, since the mask is \texttt{true} for all positions
% \end{itemize}
% Owner: PA
% Source (ALP_Tutorial.tex - Copying, Masking, and Standard Matrices)
\end{frame}
\begin{frame}[fragile]{3.3. Hands-on: Copying, Masking, and Standard Matrices}
\framesubtitle{Standard Matrix Factories}
Iterator-based ingestion allows construction of vectors and matrices with regular structures. ALP/GraphBLAS provides standard matrix factories:
\begin{lstlisting}[style=cpp-rich, language=C++, basicstyle=\ttfamily\scriptsize]
#include <graphblas/algorithms/matrix_factory.hpp>
const grb::Matrix< double > identity =
grb::algorithms::matrices< double >::identity( n );
\end{lstlisting}
\begin{itemize}
\item \textbf{Factory patterns}: \texttt{identity}, \texttt{eye}, \texttt{diag}
\begin{itemize}
\item with optional offset $k$ for superdiagonal/subdiagonal
\end{itemize}
\item \textbf{Dense patterns}: \texttt{dense}, \texttt{full}, \texttt{zeros}, \texttt{ones}
\begin{itemize}
\item \textbf{Discouraged} - ALP/GraphBLAS not optimized for dense matrices
\end{itemize}
\item Finally, matrices can be derived from existing ones via \texttt{grb::set(matrix,mask,value)}
\item \href{http://albert-jan.yzelman.net/alp/v0.8-preview/classgrb_1_1algorithms_1_1matrices.html#a1336accbaf6a61ebd890bef9da4116fc}
{\textcolor{blue}{See documentation}} for all supported patterns.
\end{itemize}
% Owner: PA
% Source (ALP_Tutorial.tex - Copying, Masking, and Standard Matrices)
\end{frame}
\begin{frame}[fragile]{3.3. Hands-on: Copying, Masking, and Standard Matrices}
\framesubtitle{Exercises 6 and 7: Masking and matrix manipulation}
\textbf{Exercise 6.} Determine whether $A$ holds explicit zeroes (entries with numerical value zero):
\begin{itemize}
\item Start from \texttt{alp\_containers\_ex5.cpp}
\item Use masking and copying to detect explicit zeroes on A.
\item \textbf{Hint:} Consider changing $A$ element type to \texttt{double}.
\end{itemize}
\textbf{Exercise 7.} Count explicit zeroes on diagonal, superdiagonal, and subdiagonal of $A$:
\begin{itemize}
\item Use the condition(s): $|\{A_{ij}\in A\ |\ A_{ij}=0, |i-j|\leq1, 0\leq i,j<497\}|$
\item \textbf{Note:} \textit{Explicit zeroes} = entries \textit{present in the matrix} but with \textit{numerical value} zero.
\item \textbf{Hint:} Matrix factory patterns could be helpful here...
\end{itemize}
\textbf{Bonus question.} How much memory beyond storing the $n\times n$ identity matrix will \texttt{matrices<double>::identity(n)} consume? \textbf{Hint:} consider that iterators passed to \texttt{buildMatrixUnique} iterate over regular index sequences.
% Owner: PA
% Source (ALP_Tutorial.tex - Copying, Masking, and Standard Matrices)
\end{frame}
\subsection{3) Introduction to core primitives}
\begin{frame}[fragile]
\frametitle{Primitives overview}
Element-wise addition, $z=x+y$:
$$
\left(\begin{tabular}{c}0\\0\\1\\0\\0\end{tabular}\right) +
\left(\begin{tabular}{c}1\\0\\0\\0\\1\end{tabular}\right) =
\left(\begin{tabular}{c}1\\0\\1\\0\\1\end{tabular}\right).
$$
ALP/GraphBLAS:
\begin{itemize}
\item {\color{gray}\texttt{grb::Vector< double > x( n ), y( n ), z( n );}}
\begin{itemize}
\item {\color{gray}(as discussed before)}
\end{itemize}
\item {\color{gray}...}
\item {\color{gray}\texttt{grb::semirings::plusTimes< double > plusTimes;}}
\begin{itemize}
\item {\color{gray}(will be detailed tomorrow)}
\end{itemize}
\item \texttt{grb::clear( z ); // makes sure z is empty}
\item \texttt{grb::eWiseAdd( z, x, y, plusTimes ); // z = x + y}
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Primitives overview}
Element-wise multiplication, $z=x\odot y$:
$$
\left(\begin{tabular}{c}0\\0\\1\\0\\0\end{tabular}\right) \odot
\left(\begin{tabular}{c}1\\0\\0\\0\\1\end{tabular}\right) =
\left(\begin{tabular}{c}0\\0\\0\\0\\0\end{tabular}\right).
$$
ALP/GraphBLAS:
\begin{itemize}
\item {\color{gray}...}
\item \texttt{grb::RC rc = grb::clear( z ); // makes sure z is empty}
\item \texttt{rc = rc ? rc : grb::eWiseMul( z, x, y, plusTimes ); // z = x .* y}
\end{itemize}
Every primitive emits a \textbf{return code} (RC). Two fundamental ones are:
\begin{itemize}
\item \texttt{grb::SUCCESS}: primitive executed OK;
\item \texttt{grb::PANIC}: something bad happened.
\end{itemize}
Always check return codes! (The above snippet contains a short-cut)
\end{frame}
\begin{frame}[fragile]
\frametitle{Primitives overview}
Dot product, $\alpha=(x,y)$:
$$
\alpha = \sum_i x_iy_i.
$$
ALP/GraphBLAS:
\begin{itemize}
\item {\color{gray}...}
\item \texttt{double alpha = 0.0;}
\item \texttt{grb::RC rc = grb::dot( alpha, x, y, plusTimes );}
\end{itemize}\vspace{\baselineskip}\pause
What if I again execute a dot product:
\begin{itemize}
\item \texttt{rc = rc ? rc : grb::dot( alpha, x, y, plusTimes );}
\end{itemize}
Does $\alpha$ now equal $\sum_i x_iy_i$, or ${\color{red}2}\sum_i x_iy_i$?
\vspace{\baselineskip}\pause
Answer: $2\sum_i x_iy_i$ -- dot, eWiseAdd, eWiseMul, ... \textbf{are in-place}
\end{frame}
\begin{frame}[fragile]
\frametitle{Primitives overview}
Most ALP primitives are in-place: helps achieve \textbf{high performance}
$$
x \odot y \to x
$$
ALP/GraphBLAS:
\begin{itemize}
\item {\color{gray}...}
\item \texttt{auto times = plusTimes.getMultiplicativeOperator();}
\item \texttt{grb::RC rc = grb::foldl( x, y, times ); // x <- x .* y}
\end{itemize}\vspace{\baselineskip}\pause
We could also have folded in the other direction:
\begin{itemize}
\item {\color{gray}...}
\item \texttt{grb::RC rc = grb::foldr( x, y, times ); // y <- x .* y}
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Primitives overview}
Similar to \texttt{grb::dot}, we may also fold into scalars:
$$
\beta = \sum_i x_i
$$
ALP/GraphBLAS:
\begin{itemize}
\item {\color{gray}...}
\item \texttt{auto plus = plusTimes.getAdditiveMonoid();}
\item \texttt{double beta = 0.0;}
\item \texttt{grb::RC rc = grb::foldl( beta, x, plus );}
\end{itemize}
or
\begin{itemize}
\item \texttt{grb::RC rc = grb::foldr( x, beta, plus );}
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Primitives overview}
Higher-level primitives:
$$
\gamma=(xA)^TAy, C=AB
$$
ALP/GraphBLAS:
\begin{itemize}
\item {\color{gray}...}
\item \texttt{double gamma = 0,0;}
\item \texttt{grb::RC rc = grb::mxv( u, A, y, plusTimes ); // u = Ay}
\item \texttt{rc = rc ? rc : grb::vxm<}\\
\texttt{ grb::descriptors::transpose\_matrix}\\
\texttt{>( v, x, A, plusTimes ); // v = xA'}
\item \texttt{rc = rc ? rc : dot( gamma, v, u, plusTimes );}
\item \texttt{rc = rc ? rc : mxm( C, A, B, plusTimes );}
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Primitives overview}
In BLAS-terminology, we overviewed three levels of primitives:
\begin{itemize}
\item Level-1: foldl/foldr, dot, eWiseAdd/Mul
\item Level-2: mxv, vxm
\item Level-3: mxm
\end{itemize}\vspace{\baselineskip}
We also overviewed:
\begin{itemize}
\item error handling: \texttt{grb::MISMATCH}, \texttt{grb::ILLEGAL};
\item GraphBLAS descriptors that alter semantics (transpose); and
\item ALP's default in-place behaviour of operations.
\end{itemize}
% Owner: AJ
% Source (ALP_Tutorial.tex - Numerical Linear Algebra):
% Primitives: \texttt{grb::foldl}, \texttt{grb::dot}, \texttt{grb::eWiseAdd}, \texttt{grb::eWiseMul},
% \texttt{grb::mxv}, \texttt{grb::vxm}, \texttt{grb::mxm}.
% \begin{lstlisting}
% auto plusTimes = grb::semirings::plusTimes<double>();
% grb::mxv(y, A, x, plusTimes);
% \end{lstlisting}
\end{frame}
\subsection{4) Hands-on: numerical linear algebra (3.4)}
\begin{frame}[fragile]{Exercise 8}
\begin{itemize}
\item Build small $A$ and $x$
\item Compute $y = A x$, $z = x \odot y$, $\delta = x^{\top} x$
\item Print results
\end{itemize}
% Owner: DJ
% Source (ALP_Tutorial.tex - Exercise 8):
% One example:
% A = [ [0,1,2], [0,3,4], [5,6,0] ], x = [1,2,3]^T
% Expected:
% \begin{lstlisting}[language=bash]
% x = [ 1, 2, 3 ]
% y = A·x = [ 7, 18, 17 ]
% z = x ⊙ y = [ 7, 36, 51 ]
% dot(x,x) = 14
% \end{lstlisting}
\end{frame}
% Exercise 8 details from ALP_Tutorial.tex
\begin{frame}[fragile]{Exercise 8: Problem statement}
Given the matrix $A$ and vector $x$ below, compute
\[ y = A\cdot x, \quad z = x \odot y, \quad d = x^{\top} x. \]
\vspace{0.5em}
\[
A = \begin{bmatrix}
0 & 1 & 2 \\
0 & 3 & 4 \\
5 & 6 & 0
\end{bmatrix}, \qquad
x = \begin{bmatrix} 1 \\ 2 \\ 3 \end{bmatrix}.
\]
\vspace{0.5em}
\textbf{Expected output:}
\begin{lstlisting}[]
x = [ 1, 2, 3 ]
y = A·x = [ 7, 18, 17 ]
z = x ⊙ y = [ 7, 36, 51 ]
dot(x,x) = 14
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]{Exercise 8: Starter code (C++)}
\textbf{Your tasks on this slide}
\begin{itemize}
\item Open code \texttt{alp\_exercise8\_starter.cpp} from the tutorial materials. And complete the following tasks:
\item Build matrix $A$ from (I,J,values): reserve capacity and call \texttt{buildMatrixUnique}.
\item Initialize vector $x = [1,2,3]^\top$ using \texttt{setElement} (clear first with \texttt{set}).
\item Compute $y = A\cdot x$ via \texttt{mxv} using the \texttt{plusTimes} semiring.
\item Compute $z = x \odot y$ with \texttt{eWiseMul} under the same semiring.
\item Compute \texttt{dot\_val} = $x^{\top} x$ with \texttt{dot} (\texttt{plusTimes}). Print all results.
\end{itemize}
\vspace{0.5em}
\footnotesize Code on next slide →
\end{frame}
\begin{frame}[fragile]{Exercise 8: Starter code (C++) — continued}
\begin{lstlisting}[ language=C++, basicstyle=\ttfamily\scriptsize,
caption={Exercise 8 starter: complete the TODOs},
label=lst:exercise8-starter, showstringspaces=false, aboveskip=2pt, belowskip=2pt]
#include <cstdio>
#include <iostream>
#include <vector>
#include <utility> // for std::pair
#include <array>
#include <graphblas.hpp>
using namespace grb;
// Indices and values for our sparse 3x3 matrix A:
// A = [ 1 0 2 ]
// [ 0 3 4 ]
// [ 5 6 0 ]
// We store the nonzero entries via buildMatrixUnique.
static const size_t Iidx[6] = { 0, 0, 1, 1, 2, 2 }; // row indices
static const size_t Jidx[6] = { 0, 2, 1, 2, 0, 1 }; // column indices
static const double Avalues[6] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 };
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]{Exercise 8: Starter code (C++) — continued}
\begin{lstlisting}[language=C++, basicstyle=\ttfamily\scriptsize, showstringspaces=false, aboveskip=2pt, belowskip=2pt]
int main( int argc, char **argv ) {
(void)argc;
(void)argv;
std::printf("example (ALP/GraphBLAS) API usage\n\n");
// 1) Create a 3x3 sparse matrix A
std::printf("Step 1: Constructing a 3x3 sparse matrix A.\n");
Matrix<double> A(3, 3);
// TODO 1: Reserve memory for 6 non-zero entries and build A from (Iidx,Jidx,Avalues),
// use resize and buildMatrixUnique
// 2) Create a 3-element vector x and initialize x = [1, 2, 3]^T
// TODO 2: Initialize x = [1, 2, 3]^T
// first clear with set, then setElement for indices 0..2
// 3) Create two result vectors y and z (dimension 3) and set to zero
// TODO 3: Create y and z with proper type
// 4) Use the built-in "plusTimes" semiring alias
// (add = plus, multiply = times, id‐add = 0.0, id-mul = 1.0)
auto plusTimes = grb::semirings::plusTimes<double>();
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]{Exercise 8: Starter code (C++) — continued}
\begin{lstlisting}[language=C++, basicstyle=\ttfamily\scriptsize, showstringspaces=false, aboveskip=2pt, belowskip=2pt]
// 5) Compute y = A·x (matrix‐vector multiply under plus‐times semiring)
// TODO 3: y = A·x (matrix-vector multiply under plusTimes) using mxv()
// 6) Compute z = x ⊙ y (element‐wise multiply) via eWiseMul with semiring
// TODO 4: z = x ⊙ y (element-wise multiply) using eWiseMul()
// 7) Compute dot_val = xᵀ·x (dot‐product under plus‐times semiring)
// TODO 5: dot_val = x^T x (dot-product under plusTimes) using dot()
// 8) Print x, y, z, and dot_val
return EXIT_SUCCESS;
}
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]{Exercise 8: Solutions}
Answers:
\begin{itemize}
\item $x=(1,2,3)$
\item $y=(8,18,17)$
\item $z=(8,36,51)$
\item complexity is $\Omega(n)$
\item random-access buildVector complexity is $\mathcal{O}(n/T+T)$
\end{itemize}\vspace{\baselineskip}
Bonus, the following descriptor short-hands building $x$:
\begin{itemize}