Self-Assessment Quiz: Linear Algebra and LAPACK

Twenty questions to confirm you can call LAPACK correctly before you rely on it in real work. Aim for 16 or more. The calling-convention questions (arguments, info, lda, what gets overwritten) are the ones that bite in practice, so if you miss those, reread §21.3 before moving on. Answers and a topic map are at the end; for the "what does this print?" item, solve it by hand first.


Question 1

The LAPACK routine name dgesv decodes as: - A. double · general · solve - B. double · symmetric · eigenvalues - C. single · general · SVD - D. double · triangular · factorize

Question 2

After a successful call dgesv(n, 1, a, n, ipiv, b, n, info), where is the solution vector $\mathbf{x}$? - A. In a - B. In ipiv - C. In b (it overwrote the right-hand side) - D. Returned as the function value

Question 3

The leading dimension lda of a matrix argument is: - A. The number of rows you are actually using - B. The declared first dimension of the array (its column stride in memory) - C. Always equal to n - D. The number of nonzero elements

Question 4

A LAPACK routine returns info = 0. This means: - A. The matrix was singular - B. The routine completed successfully - C. The first argument was illegal - D. The answer is guaranteed accurate to full precision

Question 5

A dgesv call returns info = -4. The most likely cause is: - A. The matrix is ill-conditioned - B. The fourth argument (lda) had an illegal value — a bug in your call - C. The system has no solution - D. LAPACK ran out of memory

Question 6

After integer :: m(2,2); m = reshape([1, 2, 3, 4], [2, 2]) (no order=), what is m(1, 2)? - A. 2 - B. 3 - C. 4 - D. 1

Question 7

Which computes the matrix product of two rank-2 arrays a and b? - A. a * b - B. matmul(a, b) - C. dot_product(a, b) - D. a .x. b

Question 8

The Level 3 BLAS (e.g. dgemm) is special because it: - A. Is the only level written in Fortran - B. Does $O(n^3)$ work on $O(n^2)$ data, so it reuses cache and approaches peak speed - C. Operates only on vectors - D. Requires a GPU

Question 9

A tuned BLAS beats a correct hand-written triple-loop matrix multiply mainly because it: - A. Uses a faster algorithm with a lower operation count - B. Blocks the work to fit cache and uses SIMD, turning a memory-bound loop into a compute-bound one - C. Skips the rounding steps - D. Runs in lower precision

Question 10

Calling dsyev with lwork = -1 (a workspace query): - A. Solves the eigenproblem using minimal memory - B. Does no real computation and writes the optimal workspace size into work(1) - C. Is an error - D. Returns the eigenvalues in work

Question 11

dsyev returns the eigenvalues of a symmetric matrix in w: - A. In descending order - B. In ascending order - C. In the order they appear on the diagonal - D. In arbitrary order

Question 12

The linker reports undefined reference to 'dgesv_'. This means: - A. The code has a syntax error - B. The compile failed - C. The code compiled but the LAPACK library was not linked (add -llapack -lblas) - D. dgesv does not exist

Question 13

True or false, with justification: dgesv is an efficient way to solve a linear system with a million rows when the matrix is sparse (a few nonzeros per row).

Question 14

For a tridiagonal system, the honest LAPACK routine — $O(n)$ instead of $O(n^3)$ — is: - A. dgesv - B. dgetrf - C. dgtsv - D. dsyev

Question 15

The ipiv array that dgesv requires holds: - A. The solution vector - B. The pivot indices recording the row interchanges from partial pivoting - C. The eigenvalues - D. Scratch space you must not read

Question 16

True or false: replacing reference BLAS with OpenBLAS (same interface) typically changes your numerical answer by a large amount.

Question 17

You solve A x = b in double precision (machine epsilon $\approx 10^{-16}$) with $\kappa(A) \approx 10^{8}$. Roughly how many correct significant decimal digits should you expect in x? - A. About 16 - B. About 8 - C. About 2 - D. Exactly 0

Question 18

What does this fragment print (the matrix is $\begin{bmatrix}1&1\\0&2\end{bmatrix}$)?

a = reshape([1.0_dp, 1.0_dp, 0.0_dp, 2.0_dp], [2, 2], order=[2, 1])
b = [3.0_dp, 4.0_dp]
call dgesv(2, 1, a, 2, ipiv, b, 2, info)
print '(2f6.2)', b
  • A. 1.00 2.00
  • B. 3.00 4.00
  • C. 2.00 1.00
  • D. A compile error

Question 19

LAPACK and the BLAS, being Fortran libraries, expect matrices stored in: - A. Row-major order - B. Column-major order - C. Whatever order you pass - D. A sparse format

Question 20

The LAPACK routine that computes a singular value decomposition of a general matrix is: - A. dgesv - B. dsyev - C. dgesvd - D. dgetrf


Answer Key

Q Ans Why
1 A d double, ge general, sv solve.
2 C The solution overwrites b; a is overwritten with the LU factors.
3 B lda is the declared first dimension — the memory stride between columns — not the used size.
4 B info = 0 is success. Accuracy is a separate question (conditioning).
5 B info < 0 means the (-info)-th argument was illegal — argument 4 (lda) here; your bug.
6 B Column-major fill: (1,1)=1, (2,1)=2, (1,2)=3, (2,2)=4, so m(1,2)=3.
7 B matmul is the matrix product; * is elementwise.
8 B High arithmetic intensity ($O(n^3)$ work on $O(n^2)$ data) lets it reuse cache and hit near-peak.
9 B Cache blocking + SIMD make it compute-bound; the operation count is the same $\sim 2n^3$.
10 B The query computes nothing and returns the optimal lwork in work(1).
11 B dsyev returns eigenvalues in ascending order.
12 C An undefined reference is a link error; the library flag is missing, not a compile fault.
13 False dgesv is dense: it stores all $n^2$ entries and does $O(n^3)$ work, impossible at a million rows. Use a sparse solver (or dgtsv if tridiagonal).
14 C dgtsv = double / general tridiagonal / solve, $O(n)$.
15 B ipiv records the partial-pivoting row interchanges; required even if you never read it.
16 False Same mathematical interface → same result (to rounding); OpenBLAS is just tuned to run faster.
17 B $\kappa \approx 10^{8}$ costs about 8 of ~16 digits, leaving ~8 trustworthy.
18 A Solve $\begin{bmatrix}1&1\\0&2\end{bmatrix}\mathbf{x}=(3,4)$: $x_2=2$, $x_1=1$ → prints 1.00 2.00.
19 B Fortran (and thus LAPACK) is column-major; a Fortran matrix needs no transpose to pass in.
20 C dgesvd = double / general / SVD.

Topics to review by question

  • Q1, 20 → §21.3–21.4 (LAPACK naming scheme).
  • Q2, 5, 6, 15, 18, 19 → §21.3 (the dgesv calling convention, overwriting, column-major, info).
  • Q3 → §21.3 (leading dimension lda).
  • Q4, 5 → §21.3 (info values).
  • Q7 → §21.1 (matmul vs *).
  • Q8, 9 → §21.2 (BLAS levels, why tuned beats hand-rolled).
  • Q10, 11 → §21.4 (workspace query, dsyev).
  • Q12 → §21.5 (linking, link-vs-compile errors).
  • Q13, 14 → §21.6 (sparse matrices, dgtsv).
  • Q16 → §21.5 (interchangeable BLAS implementations).
  • Q17 → §21.3 + Chapter 20 (conditioning).

Scored below 16? The usual gaps are the calling convention (Q2, Q5, Q6, Q15 — reread §21.3, and internalize that dgesv overwrites both a and b) and the link-vs-compile distinction (Q12). Both are the kind of mistake that costs an afternoon the first time and thirty seconds forever after.