Abstract
The QR factorization and the SVD are two fundamental matrix decompositions with applications throughout scientific computing and data analysis. For matrices with many more rows than columns, so-called "tall-and-skinny matrices," there is a numerically stable, efficient, communication-avoiding algorithm for computing the QR factorization. It has been used in traditional high performance computing and grid computing environments. For MapReduce environments, existing methods to compute the QR decomposition use a numerically unstable approach that relies on indirectly computing the Q factor. In the best case, these methods require only two passes over the data. In this paper, we describe how to compute a stable tall-and-skinny QR factorization on a MapReduce architecture in only slightly more than 2 passes over the data. We can compute the SVD with only a small change and no difference in performance. We present a performance comparison between our new direct TSQR method, a standard unstable implementation for MapReduce (Cholesky QR), and the classic stable algorithm implemented for MapReduce (Householder QR). We find that our new stable method has a large performance advantage over the Householder QR method. This holds both in a theoretical performance model as well as in an actual implementation.
Introduction
Tall-and-skinny matrices—those with significantly more rows than columns—are ubiquitous in large-scale data analysis, often representing millions or billions of observations across a few hundred features. QR factorization ($A = QR$) is a fundamental tool for processing such data, yet standard algorithms face a trade-off between numerical stability and computational efficiency in distributed MapReduce environments.
Existing approaches like Cholesky QR are fast but unstable for ill-conditioned matrices. Conversely, Householder QR is stable but requires $2n$ passes over the data (where $n$ is the number of columns), making it prohibitively slow for large datasets. Indirect TSQR methods compute $R$ stably but find $Q$ via $Q = AR^{-1}$, which reintroduces instability. This paper presents Direct TSQR, a method that achieves the stability of Householder QR with the efficiency of communication-avoiding algorithms.
The Direct TSQR Algorithm
The proposed Direct TSQR algorithm computes the QR factorization in three primary MapReduce stages, minimizing data movement and disk I/O:
- Local QR Factorization: The input matrix $A$ is partitioned into blocks $A_i$. Each mapper performs a local QR factorization: $A_i = Q_i R_i$. The $R_i$ factors are sent to the reducer, while the $Q_i$ factors are persisted to disk.
- Reduction of R Factors: The $R_i$ factors are collected and factorized in a hierarchical tree structure to produce the final upper-triangular matrix $R$ and a set of intermediate "coupling" $Q$ factors. This process is illustrated in Figure 1.
- Direct Reconstruction of Q: In a second map pass, the coupling factors are distributed back to the mappers. Each mapper computes its portion of the final $Q$ by multiplying its local $Q_i$ by the corresponding coupling factor.
The mathematical core of the "Direct" approach is the reconstruction of the global $Q$ matrix from local and coupling factors. Unlike indirect methods that rely on matrix inversion, this direct multiplication preserves the orthogonality of $Q$ to machine precision, as shown in the block-matrix formulation in Figure 2.
Evaluation and Results
The authors evaluated Direct TSQR on a 10-node MapReduce cluster using synthetic matrices up to 1 terabyte in size (4 billion rows).
- Numerical Accuracy: For ill-conditioned matrices (condition numbers up to $10^{20}$), Direct TSQR maintained machine-level precision ($Q^TQ \approx I$ within $10^{-15}$), whereas Cholesky QR and Indirect TSQR failed completely, with orthogonality errors jumping to $10^0$.
- Performance: Direct TSQR demonstrated a significant speed advantage over Householder QR. For a $4 \text{ billion} \times 4$ matrix, Direct TSQR completed in approximately 6,128 seconds, nearly 2.5x faster than the extrapolated runtime for Householder QR. As the number of columns increases, this performance gap widens.
- Scalability and Robustness: The algorithm scales linearly with the number of rows. Furthermore, it leverages MapReduce's inherent fault tolerance; even with a high task failure rate (1/8), the total runtime increased by only 23%, demonstrating the robustness of the implementation.
Conclusion
Direct TSQR provides a robust solution for large-scale linear algebra in MapReduce environments. It bridges the gap between high-performance communication-avoiding methods and numerically stable classical algorithms. While the reduction of $R$ factors can become a serial bottleneck as the number of columns grows, the method remains the most viable option for stable, large-scale QR factorization on commodity clusters. Future work includes extending this approach to hybrid MPI/Hadoop architectures to further reduce disk I/O overhead.
Summary updated