Skip to content

Commit

Permalink
Merge branch 'splines-linear-problem-periodic-band2' into lapack-backend
Browse files Browse the repository at this point in the history
  • Loading branch information
blegouix committed Jun 17, 2024
2 parents cc28f25 + 9b5fd29 commit d35d9c5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
6 changes: 4 additions & 2 deletions include/ddc/kernels/splines/splines_linear_problem_maker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class SplinesLinearProblemMaker
* a periodic band matrix.
*
* It simply calls make_new_block_matrix_with_band_main_block with bottom_size being
* max(kl, ku) (except if the alloation would be higher than instantiating a SplinesLinearProblemDense).
* max(kl, ku) (except if the allocation would be higher than instantiating a SplinesLinearProblemDense).
*
* @tparam the Kokkos::ExecutionSpace on which matrix-related operation will be performed.
* @param n The size of one of the dimensions of the whole square matrix.
Expand All @@ -124,8 +124,10 @@ class SplinesLinearProblemMaker
int const ku,
bool const pds)
{
assert(kl < n);
assert(ku < n);
int const bottom_size = std::max(kl, ku);
int const top_size = std::max(0, n - bottom_size);
int const top_size = n - bottom_size;

if (bottom_size * (n + top_size) + (2 * kl + ku + 1) * top_size >= n * n) {
return std::make_unique<SplinesLinearProblemDense<ExecSpace>>(n);
Expand Down
27 changes: 14 additions & 13 deletions tests/splines/matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,23 +416,24 @@ TEST_P(MatrixSizesFixture, PeriodicBand)
{
auto const [N, k] = GetParam();

// Build a non-symmetric full-rank band matrix
for (std::ptrdiff_t s(-k); s < (std::ptrdiff_t)k + 1; ++s) {
if (s == 0)
continue;

// Build a full-rank periodic band matrix permuted in such a way the band is shifted
for (std::ptrdiff_t s(-k + k / 2 + 1); s < static_cast<std::ptrdiff_t>(k - k / 2); ++s) {
std::cout << s;
std::unique_ptr<ddc::detail::SplinesLinearProblem<Kokkos::DefaultExecutionSpace>> matrix
= ddc::detail::SplinesLinearProblemMaker::make_new_periodic_band_matrix<
Kokkos::DefaultExecutionSpace>(N, k - s, k + s, false);
Kokkos::DefaultExecutionSpace>(
N,
static_cast<std::ptrdiff_t>(k - s),
k + s,
false);
for (std::size_t i(0); i < N; ++i) {
for (std::size_t j(0); j < N; ++j) {
int diag = ddc::detail::modulo((int)(j - i), (int)N);
if (diag == s || diag == (std::ptrdiff_t)N + s) {
matrix->set_element(i, j, 0.5);
} else if (
diag <= s + (std::ptrdiff_t)k
|| diag >= (std::ptrdiff_t)N + s - (std::ptrdiff_t)k) {
matrix->set_element(i, j, -1.0 / k);
std::ptrdiff_t diag = ddc::detail::
modulo(static_cast<std::ptrdiff_t>(j - i), static_cast<std::ptrdiff_t>(N));
if (diag == s || diag == N + s) {
matrix->set_element(i, j, 2.0 * k + 1);
} else if (diag <= s + k || diag >= N + s - k) {
matrix->set_element(i, j, -1.);
}
}
}
Expand Down

0 comments on commit d35d9c5

Please sign in to comment.