Skip to content

Commit

Permalink
test: Print matrices and vectors more consistently. Use A, B, C, etc.…
Browse files Browse the repository at this point in the history
… for inputs; C_out, etc. for outputs.
  • Loading branch information
mgates3 committed May 28, 2024
1 parent 5709ede commit 4883403
Show file tree
Hide file tree
Showing 35 changed files with 196 additions and 153 deletions.
30 changes: 18 additions & 12 deletions test/test_bdsqr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ void test_bdsqr_work(Params& params, bool run)
lapack::Job jobvt = params.jobvt();
bool check = params.check() == 'y';
bool trace = params.trace() == 'y';
int verbose = params.verbose();
slate::Origin origin = params.origin();

// mark non-standard output values
Expand Down Expand Up @@ -113,6 +112,11 @@ void test_bdsqr_work(Params& params, bool run)
}
}

if (mpi_rank == 0) {
print_vector( "D", D, params );
print_vector( "E", E, params );
}

//---------
// run test
if (trace) slate::trace::Trace::on();
Expand All @@ -130,6 +134,17 @@ void test_bdsqr_work(Params& params, bool run)
if (trace)
slate::trace::Trace::finish();

if (mpi_rank == 0) {
print_vector( "D_out ", D, params );
}
// todo: print crashes if U or VT is empty.
if (jobu != slate::Job::NoVec) {
print_matrix( "U_out", U, params );
}
if (jobvt != slate::Job::NoVec) {
print_matrix( "VT_out", VT, params );
}

if (check) {
//==================================================
// Test results
Expand All @@ -147,17 +162,8 @@ void test_bdsqr_work(Params& params, bool run)

params.ref_time() = barrier_get_wtime(MPI_COMM_WORLD) - time;

if (verbose) {
// Print first 20 and last 20 rows.
printf( "%9s %9s\n", "D", "Dref" );
for (int64_t i = 0; i < n; ++i) {
if (i < 20 || i > n-20) {
bool okay = std::abs( D[i] - Dref[i] ) < tol;
printf( "%9.6f %9.6f%s\n",
D[i], Dref[i], (okay ? "" : " !!") );
}
}
printf( "\n" );
if (mpi_rank == 0) {
print_vector( "Dref_out", Dref, params );
}

// Relative forward error: || D - Dref || / || Dref ||.
Expand Down
4 changes: 2 additions & 2 deletions test/test_gbmm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ void test_gbmm_work(Params& params, bool run)
else if (transA == slate::Op::ConjTrans)
A = conj_transpose( A );

print_matrix( "Cref_in", Cref, params );
print_matrix( "Cref", Cref, params );

// Get norms of the original data.
real_t A_norm = slate::norm( norm, A );
Expand All @@ -208,7 +208,7 @@ void test_gbmm_work(Params& params, bool run)

time = barrier_get_wtime(MPI_COMM_WORLD) - time;

print_matrix( "Cref", Cref, params );
print_matrix( "Cref_out", Cref, params );

// get differences Cref = Cref - C
slate::add( -one, C, one, Cref );
Expand Down
4 changes: 2 additions & 2 deletions test/test_gbsv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ void test_gbsv_work(Params& params, bool run)
}
printf( "] + 1;\n" );
}
print_matrix("A2", A, params);
print_matrix("B2", B, params);
print_matrix( "A_out", A, params );
print_matrix( "B_out", B, params );
}

if (check) {
Expand Down
4 changes: 2 additions & 2 deletions test/test_gels.cc
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ void test_gels_work(Params& params, bool run)
params.time4() = slate::timers[ "gels_cholqr::trsm" ];
}

print_matrix( "A2", A, params );
print_matrix( "BX2", BX, params );
print_matrix( "A_out", A, params );
print_matrix( "BX_out", BX, params );
}

if (check) {
Expand Down
8 changes: 2 additions & 6 deletions test/test_gemm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ void test_gemm_work(Params& params, bool run)
bool ref = params.ref() == 'y' || ref_only;
bool check = params.check() == 'y' && ! ref_only;
bool trace = params.trace() == 'y';
int verbose = params.verbose();
slate::Target target = params.target();
slate::Origin origin = params.origin();
slate::MethodGemm method_gemm = params.method_gemm();
Expand Down Expand Up @@ -183,14 +182,11 @@ void test_gemm_work(Params& params, bool run)

if (trace) slate::trace::Trace::finish();

if (verbose >= 2) {
C.tileGetAllForReading( slate::HostNum, slate::LayoutConvert::None );
print_matrix( "C_out", C, params );
}

// compute and save timing/performance
params.time() = time;
params.gflops() = gflop / time;

print_matrix( "C_out", C, params );
}

if (check && ! ref) {
Expand Down
2 changes: 1 addition & 1 deletion test/test_geqrf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void test_geqrf_work(Params& params, bool run)

slate::TriangularFactors<scalar_t> T;

print_matrix("A", A, params);
print_matrix( "A", A, params );

// For checks, keep copy of original matrix A.
slate::Matrix<scalar_t> Aref;
Expand Down
4 changes: 3 additions & 1 deletion test/test_gesv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,10 @@ void test_gesv_work(Params& params, bool run)
llong( info ), params.matrix.cond_actual() );
params.msg() = buf;
}

print_matrix( "B_out", B, params );
print_matrix( "X_out", X, params );
}
print_matrix( "X_out", X, params );

if (info != 0 || std::isinf( params.matrix.cond_actual() )) {
// info != 0 if and only if cond == inf (singular matrix).
Expand Down
10 changes: 10 additions & 0 deletions test/test_getri.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "blas/flops.hh"
#include "lapack/flops.hh"
#include "grid_utils.hh"
#include "print_matrix.hh"

#include "scalapack_wrappers.hh"
#include "scalapack_copy.hh"
Expand Down Expand Up @@ -96,6 +97,8 @@ void test_getri_work(Params& params, bool run)
}
slate::generate_matrix(params.matrix, A);

print_matrix( "A", A, params );

// Create pivot structure to store pivots after factoring
slate::Pivots pivots;

Expand Down Expand Up @@ -183,6 +186,13 @@ void test_getri_work(Params& params, bool run)
// compute and save timing/performance
params.time() = time;
params.gflops() = gflop / time;

if (params.routine == "getriOOP") {
print_matrix( "A_inv = C_out", C, params );
}
else {
print_matrix( "A_inv = A_out", A, params );
}
}

if (info != 0 || std::isinf( params.matrix.cond_actual() )) {
Expand Down
23 changes: 7 additions & 16 deletions test/test_hb2st.cc
Original file line number Diff line number Diff line change
Expand Up @@ -207,27 +207,18 @@ void test_hb2st_work(Params& params, bool run)
}
}

print_matrix("D", 1, n, &Lambda2[0], 1, params);
print_matrix("E", 1, n-1, &E[0], 1, params);
if (mpi_rank == 0) {
print_vector( "D", Lambda2, params );
print_vector( "E", E, params );
}

info = lapack::steqr(lapack::Job::NoVec, n, &Lambda2[0], &E[0],
dummy, 1);
assert(info == 0);

if (verbose) {
printf( "%% first and last 20 rows of Lambda1 and Lambda2\n" );
printf( "%9s %9s\n", "Lambda1", "Lambda2" );
for (int64_t i = 0; i < n; ++i) {
if (i < 20 || i >= n-20) {
bool okay = std::abs( Lambda1[i] - Lambda2[i] ) < tol;
printf( "%9.6f %9.6f%s\n",
Lambda1[i], Lambda2[i], (okay ? "" : " !!") );
}
else if (i == 20) {
printf( "--------------------\n" );
}
}
printf( "\n" );
if (mpi_rank == 0) {
print_vector( "Lambda1", Lambda1, params );
print_vector( "Lambda2", Lambda2, params );
}

// Relative forward error: || L - Lref || / || Lref ||.
Expand Down
2 changes: 1 addition & 1 deletion test/test_hbmm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ void test_hbmm_work(Params& params, bool run)
params.time() = time;
params.gflops() = gflop / time;

print_matrix("C2", C, params);
print_matrix( "C_out", C, params );

if (check || ref) {
//==================================================
Expand Down
4 changes: 2 additions & 2 deletions test/test_hegst.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ void test_hegst_work(Params& params, bool run)
params.time() = time;
//params.gflops() = gflop / time;

print_matrix("A_hegst", A, params);
print_matrix( "A_out", A, params );
}

if (check || ref) {
Expand Down Expand Up @@ -175,7 +175,7 @@ void test_hegst_work(Params& params, bool run)
params.ref_time() = time;
// params.ref_gflops() = gflop / time;

print_matrix("Aref_hegst", Aref, params);
print_matrix( "Aref_out", Aref, params );

if (! ref_only) {
// Local operation: error = Aref - A
Expand Down
8 changes: 4 additions & 4 deletions test/test_hegv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ void test_hegv_work(Params& params, bool run)

print_matrix("A", A, params);
print_matrix("B", B, params);
print_matrix("Z", Z, params);

std::vector<scalar_t> Aref_data, Bref_data, Zref_data;
std::vector<real_t> Lambda_ref;
Expand Down Expand Up @@ -245,9 +244,10 @@ void test_hegv_work(Params& params, bool run)

}

print_matrix("A", A, params);
print_matrix("B", B, params);
print_matrix("Z", Z, params);
if (mpi_rank == 0) {
print_vector( "Lambda", Lambda, params );
}
print_matrix( "Z_out", Z, params );

if (check && jobz == slate::Job::Vec) {
// do error checks for the operations
Expand Down
12 changes: 6 additions & 6 deletions test/test_hemm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ void test_hemm_work(Params& params, bool run)
bool check = params.check() == 'y';
bool ref = params.ref() == 'y';
bool trace = params.trace() == 'y';
int verbose = params.verbose();
slate::Origin origin = params.origin();
slate::Target target = params.target();
slate::MethodHemm method_hemm = params.method_hemm();
Expand Down Expand Up @@ -109,6 +108,10 @@ void test_hemm_work(Params& params, bool run)
slate::generate_matrix( params.matrixB, B);
slate::generate_matrix( params.matrixC, C);

print_matrix( "A", A, params );
print_matrix( "B", B, params );
print_matrix( "C", C, params );

// If reference run is required, record norms to be used in the check/ref.
real_t A_norm=0, B_norm=0, C_orig_norm=0;
if (ref) {
Expand Down Expand Up @@ -185,18 +188,15 @@ void test_hemm_work(Params& params, bool run)

time = barrier_get_wtime(MPI_COMM_WORLD) - time;

if (verbose >= 2) {
C.tileGetAllForReading( slate::HostNum, slate::LayoutConvert::None );
print_matrix( "C_out", C, params );
}

if (trace) slate::trace::Trace::finish();

// Compute and save timing/performance
double gflop = blas::Gflop<scalar_t>::hemm(side, m, n);
params.time() = time;
params.gflops() = gflop / time;

print_matrix( "C_out", C, params );

if (check && ! ref) {
auto& X = X_alloc.A;
auto& Y = Y_alloc.A;
Expand Down
10 changes: 5 additions & 5 deletions test/test_her2k.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ void test_her2k_work(Params& params, bool run)
slate_assert( opB.mt() == C.mt() );
slate_assert( opA.nt() == opB.nt() );

print_matrix("A", A, params);
print_matrix("B", B, params);
print_matrix("Initial C", C, params);
print_matrix( "A", A, params );
print_matrix( "B", B, params );
print_matrix( "C", C, params );

if (trace) slate::trace::Trace::on();
else slate::trace::Trace::off();
Expand Down Expand Up @@ -177,7 +177,7 @@ void test_her2k_work(Params& params, bool run)

time = barrier_get_wtime(MPI_COMM_WORLD) - time;

print_matrix("Cslate", C, params);
print_matrix( "C_out", C, params );

if (trace) slate::trace::Trace::finish();

Expand Down Expand Up @@ -243,7 +243,7 @@ void test_her2k_work(Params& params, bool run)
&Cref_data[0], 1, 1, Cref_desc);
time = barrier_get_wtime(MPI_COMM_WORLD) - time;

print_matrix("Cref", Cref, params);
print_matrix( "Cref_out", Cref, params );

// get differences C = C - Cref
slate::add(-one, Cref, one, C);
Expand Down
6 changes: 6 additions & 0 deletions test/test_herk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "slate/slate.hh"
#include "test.hh"
#include "blas/flops.hh"
#include "print_matrix.hh"

#include "matrix_utils.hh"
#include "test_utils.hh"
Expand Down Expand Up @@ -93,6 +94,9 @@ void test_herk_work(Params& params, bool run)
slate::generate_matrix( params.matrix, A );
slate::generate_matrix( params.matrixC, C );

print_matrix( "A", A, params );
print_matrix( "C", C, params );

// If reference run is required, record norms to be used in the check/ref.
real_t A_norm=0, C_orig_norm=0;
if (ref) {
Expand Down Expand Up @@ -158,6 +162,8 @@ void test_herk_work(Params& params, bool run)
params.time() = time;
params.gflops() = gflop / time;

print_matrix( "C_out", C, params );

if (check && ! ref) {
auto& X = X_alloc.A;
auto& Y = Y_alloc.A;
Expand Down
4 changes: 2 additions & 2 deletions test/test_hesv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ void test_hesv_work(Params& params, bool run)
params.msg() = buf;
}

print_matrix( "Aout", A, params );
print_matrix( "Bout", B, params );
print_matrix( "A_out", A, params );
print_matrix( "B_out", B, params );

//---------------------
// compute and save timing/performance
Expand Down
7 changes: 3 additions & 4 deletions test/test_pbsv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ void test_pbsv_work(Params& params, bool run)
print_matrix("A", A, params);
print_matrix("B", B, params);


// if check is required, copy test data and create a descriptor for it
slate::Matrix<scalar_t> Bref;
if (check || ref) {
Expand Down Expand Up @@ -202,8 +201,8 @@ void test_pbsv_work(Params& params, bool run)
// A.mpiRank(), llong( A.bandwidth( )));
//printf( "nb = %lld;\n", llong( nb ) );
}
print_matrix("A2", A, params);
print_matrix("B2", B, params);
print_matrix( "A_out", A, params );
print_matrix( "B_out", B, params );
}
if (check) {
//==================================================
Expand Down Expand Up @@ -249,7 +248,7 @@ void test_pbsv_work(Params& params, bool run)
printf("Anorm = %.4e; Xnorm = %.4e; Rnorm = %.4e; error = %.4e;\n",
A_norm, X_norm, R_norm, residual);
}
print_matrix("Residual", Bref, params);
print_matrix( "Residual", Bref, params );
}
// todo: reference solution requires setting up band matrix in ScaLAPACK's
// band storage format.
Expand Down
Loading

0 comments on commit 4883403

Please sign in to comment.