#include#include int main() { // Create a 4x4 matrix grid with 2 rows and 2 columns DistMatrixGrid grid(2, 2); // Create two distributed matrices with 2 rows and 3 columns DistMatrix mat1(grid, 2, 3); DistMatrix mat2(grid, 2, 3); // Set the values of the two matrices mat1.Set(0, 0, 1); mat1.Set(0, 1, 2); mat1.Set(0, 2, 3); mat1.Set(1, 0, 4); mat1.Set(1, 1, 5); mat1.Set(1, 2, 6); mat2.Set(0, 0, 7); mat2.Set(0, 1, 8); mat2.Set(0, 2, 9); mat2.Set(1, 0, 10); mat2.Set(1, 1, 11); mat2.Set(1, 2, 12); // Multiply the two matrices and store the result in a new distributed matrix DistMatrix result(grid, 2, 3); Multiply(mat1, mat2, result); // Print the result std::cout << result << std::endl; return 0; }
#includeBoth examples were written using the Elemental package library, which is an open-source library for distributed-memory dense and sparse-direct linear algebra ; a library that performs high-performance operations on dense and sparse matrices.#include int main() { // Create a 4x4 matrix grid with 2 rows and 2 columns DistMatrixGrid grid(2, 2); // Create a distributed matrix with 3 rows and 2 columns DistMatrix mat1(grid, 3, 2); // Set the values of the matrix mat1.Set(0, 0, 1); mat1.Set(0, 1, 2); mat1.Set(1, 0, 3); mat1.Set(1, 1, 4); mat1.Set(2, 0, 5); mat1.Set(2, 1, 6); // Perform an SVD on the matrix and store the result in three new distributed matrices DistMatrix U(grid, mat1.Height(), mat1.Height()); DistMatrix VT(grid, mat1.Width(), mat1.Width()); DistMatrix S(grid, mat1.Height(), mat1.Width()); SVD(mat1, U, S, VT); // Print the result std::cout << "U: " << U << std::endl; std::cout << "S: " << S << std::endl; std::cout << "VT: " << VT << std::endl; return 0; }