void TestColumnMaxNorms(Int m, Int n, const Grid& g, bool print) { // Generate random matrix to test. DistMatrix<T, MC, MR, W> A(g); Uniform(A, m, n); if (print) Print(A, "A"); DistMatrix<T, MR, STAR, W> norms(g); ColumnMaxNorms(A, norms); if (print) Print(norms, "norms"); for (Int j = 0; j < A.LocalWidth(); ++j) { T got = norms.GetLocal(j, 0); T expected = 0; for (Int i = 0; i < A.LocalHeight(); ++i) expected = Max(expected, Abs(A.GetLocal(i, j))); T r; mpi::AllReduce(&expected, &r, 1, mpi::MAX, g.ColComm()); expected = r; if (got != expected) { Output("Results do not match, norms(", j, ")=", got, " instead of ", expected); RuntimeError("got != expected"); } } }
void TestColumnTwoNorms(Int m, Int n, const Grid& g, bool print) { // Generate random matrix to test. DistMatrix<T, MC, MR, W> A(g); Uniform(A, m, n); if (print) Print(A, "A"); DistMatrix<T, MR, STAR, W> norms(g); ColumnTwoNorms(A, norms); if (print) Print(norms, "norms"); for (Int j = 0; j < A.LocalWidth(); ++j) { T got = norms.GetLocal(j, 0); T expected = 0; for (Int i = 0; i < A.LocalHeight(); ++i) { T val = A.GetLocal(i, j); expected += val * val; } expected = mpi::AllReduce(expected, g.ColComm()); expected = Sqrt(expected); // Compute max(expected, 1) to use relative bound. // (std::max and El::Max don't support BigFloat. T div = expected > 1 ? expected : 1; if (Abs(got - expected) / div > m * n * 10 * limits::Epsilon<El::Base<T>>()) { Output("Results do not match, norms(", j, ")=", got, " instead of ", expected); RuntimeError("got != expected"); } } }