Skip to content

Commit

Permalink
DEBUG: Add sinus RHS generation to benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Grützmacher committed Dec 11, 2020
1 parent 1e171e8 commit 396788c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 8 deletions.
2 changes: 2 additions & 0 deletions benchmark/run_all_benchmarks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ fi

if [ "${SOLVERS_RHS}" == "random" ]; then
SOLVERS_RHS_FLAG="--random_rhs=true"
elif [ "${SOLVERS_RHS}" == "sinus" ]; then
SOLVERS_RHS_FLAG="--custom_sinus_rhs=true"
else
SOLVERS_RHS_FLAG="--random_rhs=false"
fi
Expand Down
36 changes: 28 additions & 8 deletions benchmark/solver/solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ DEFINE_double(
DEFINE_bool(random_rhs, false,
"Use a random vector for the rhs (otherwise use all ones)");

DEFINE_bool(custom_sinus_rhs, false,
"Use b = A * (s / |s|) as the RHS with s(i)=sin(i)");


DEFINE_bool(random_initial_guess, false,
"Use a random vector for the initial guess (otherwise use rhs)");

Expand Down Expand Up @@ -499,20 +503,36 @@ int main(int argc, char *argv[])
auto data = gko::read_raw<etype>(mtx_fd);
system_matrix = share(formats::matrix_factory.at(
test_case["optimal"]["spmv"].GetString())(exec, data));
auto vec_size =
gko::dim<2>{system_matrix->get_size()[0], FLAGS_nrhs};
if (test_case.HasMember("rhs")) {
std::ifstream rhs_fd{test_case["rhs"].GetString()};
b = gko::read<Vec>(rhs_fd, exec);
} else {
b = create_matrix<etype>(
exec,
gko::dim<2>{system_matrix->get_size()[0], FLAGS_nrhs},
engine, FLAGS_random_rhs);
// TODO: Remove (only present to perform benchmark for
// CB-GMRES)
if (FLAGS_custom_sinus_rhs) {
auto tmp = create_matrix_sin<etype>(exec, vec_size);
auto scalar = Vec::create(exec->get_master(),
gko::dim<2>{1, vec_size[1]});
tmp->compute_norm2(scalar.get());
for (gko::size_type i = 0; i < vec_size[1]; ++i) {
scalar->at(0, i) =
gko::one<etype>() / scalar->at(0, i);
}
// normalize sin-vector
tmp->scale(scalar.get());
b = Vec::create(exec, vec_size);
system_matrix->apply(tmp.get(), b.get());
} else {
b = create_matrix<etype>(exec, vec_size, engine,
FLAGS_random_rhs);
}
}
if (FLAGS_random_initial_guess) {
x = create_matrix<etype>(
exec,
gko::dim<2>{system_matrix->get_size()[0], FLAGS_nrhs},
engine);
x = create_matrix<etype>(exec, vec_size, engine);
} else if (FLAGS_custom_sinus_rhs) { // TODO remove!!
x = create_matrix<etype>(exec, vec_size);
} else {
x = b->clone();
}
Expand Down
21 changes: 21 additions & 0 deletions benchmark/utils/general.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,27 @@ std::unique_ptr<vec<ValueType>> create_vector(
return res;
}

// Create a matrix with value indices sin(idx++)
template <typename ValueType>
std::unique_ptr<vec<ValueType>> create_matrix_sin(
std::shared_ptr<const gko::Executor> exec, gko::dim<2> size)
{
struct count {
using itype = gko::int32;
itype idx;
count() = default;
itype get_next_value() { return idx++; }
};
auto my_dist = [](count &c) {
return std::sin(
static_cast<gko::remove_complex<ValueType>>(c.get_next_value()));
};
auto res = vec<ValueType>::create(exec);
res->read(gko::matrix_data<ValueType>(size, my_dist, count{}));
return res;
}


template <typename ValueType>
std::unique_ptr<vec<ValueType>> create_matrix(
std::shared_ptr<const gko::Executor> exec, gko::dim<2> size)
Expand Down

0 comments on commit 396788c

Please sign in to comment.