Skip to content

Commit

Permalink
fixes sonarcloud issues where it makes sense
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcelKoch committed May 4, 2022
1 parent ab8b482 commit 6afb2b8
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 29 deletions.
4 changes: 2 additions & 2 deletions core/distributed/vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,8 @@ ValueType& Vector<ValueType>::at_local(size_type row, size_type col) noexcept
}

template <typename ValueType>
ValueType Vector<ValueType>::at_local(size_type row,
size_type col) const noexcept
ValueType Vector<ValueType>::at_local(size_type row, size_type col) const
noexcept
{
return local_.at(row, col);
}
Expand Down
10 changes: 10 additions & 0 deletions include/ginkgo/core/distributed/base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,22 @@ class DistributedBase {
public:
virtual ~DistributedBase() = default;

DistributedBase(const DistributedBase& other) = default;

DistributedBase(DistributedBase&& other) = default;

/**
* Copy assignment that doesn't change the used mpi::communicator.
* @return unmodified *this
*/
DistributedBase& operator=(const DistributedBase&) { return *this; }

/**
* Move assignment that doesn't change the used mpi::communicator.
* @return unmodified *this
*/
DistributedBase& operator=(DistributedBase&&) noexcept { return *this; }

/**
* Access the used mpi::communicator.
* @return used mpi::communicator
Expand Down
8 changes: 8 additions & 0 deletions include/ginkgo/core/distributed/vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,10 @@ class Vector
/**
* Creates a distributed vector from local vectors with a specified size.
*
* @note The data form the local_vector will be moved into the new
* distributed vector. This means, access to local_vector
* will be invalid after this call.
*
* @param exec Executor associated with this vector
* @param comm Communicator associated with this vector
* @param global_size The global size of the vector
Expand All @@ -384,6 +388,10 @@ class Vector
* be deduced from the local sizes, which will incur a collective
* communication.
*
* @note The data form the local_vector will be moved into the new
* distributed vector. This means, access to local_vector
* will be invalid after this call.
*
* @param exec Executor associated with this vector
* @param comm Communicator associated with this vector
* @param local_vector The underlying local vector, the data will be moved
Expand Down
6 changes: 4 additions & 2 deletions omp/distributed/vector_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ void build_local(
auto range_starting_indices = partition->get_range_starting_indices();
auto num_ranges = partition->get_num_ranges();

auto find_range = [&](GlobalIndexType idx, size_type hint) {
auto find_range = [range_bounds, num_ranges](GlobalIndexType idx,
size_type hint) {
if (range_bounds[hint] <= idx && idx < range_bounds[hint + 1]) {
return hint;
} else {
Expand All @@ -66,7 +67,8 @@ void build_local(
return static_cast<size_type>(std::distance(range_bounds + 1, it));
}
};
auto map_to_local = [&](GlobalIndexType idx,
auto map_to_local = [range_bounds, range_starting_indices](
GlobalIndexType idx,
size_type range_id) -> LocalIndexType {
return static_cast<LocalIndexType>(idx - range_bounds[range_id]) +
range_starting_indices[range_id];
Expand Down
6 changes: 4 additions & 2 deletions reference/distributed/vector_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ void build_local(
auto range_starting_indices = partition->get_range_starting_indices();
auto num_ranges = partition->get_num_ranges();

auto find_range = [&](GlobalIndexType idx, size_type hint) {
auto find_range = [range_bounds, num_ranges](GlobalIndexType idx,
size_type hint) {
if (range_bounds[hint] <= idx && idx < range_bounds[hint + 1]) {
return hint;
} else {
Expand All @@ -66,7 +67,8 @@ void build_local(
return static_cast<size_type>(std::distance(range_bounds + 1, it));
}
};
auto map_to_local = [&](GlobalIndexType idx,
auto map_to_local = [range_bounds, range_starting_indices](
GlobalIndexType idx,
size_type range_id) -> LocalIndexType {
return static_cast<LocalIndexType>(idx - range_bounds[range_id]) +
range_starting_indices[range_id];
Expand Down
40 changes: 17 additions & 23 deletions test/mpi/distributed/vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ TYPED_TEST_SUITE(VectorCreation, gko::test::ValueLocalGlobalIndexTypes);

TYPED_TEST(VectorCreation, CanReadGlobalMatrixData)
{
using part_type = typename TestFixture::part_type;
using value_type = typename TestFixture::value_type;
auto vec = TestFixture::dist_vec_type::create(this->exec, this->comm);
auto rank = this->comm.rank();
Expand All @@ -170,7 +169,6 @@ TYPED_TEST(VectorCreation, CanReadGlobalMatrixData)
TYPED_TEST(VectorCreation, CanReadGlobalMatrixDataSomeEmpty)
{
using part_type = typename TestFixture::part_type;
using value_type = typename TestFixture::value_type;
auto part = gko::share(part_type::build_from_contiguous(
this->exec, {this->exec, {0, 0, 6, 6}}));
auto vec = TestFixture::dist_vec_type::create(this->exec, this->comm);
Expand All @@ -195,21 +193,23 @@ TYPED_TEST(VectorCreation, CanReadGlobalMatrixDataSomeEmpty)

TYPED_TEST(VectorCreation, CanReadGlobalDeviceMatrixData)
{
using it = typename TestFixture::global_index_type;
using index_type = typename TestFixture::global_index_type;
using d_md_type = typename TestFixture::d_md_type;
using part_type = typename TestFixture::part_type;
using vt = typename TestFixture::value_type;
using value_type = typename TestFixture::value_type;
d_md_type md{
this->exec, gko::dim<2>{6, 2},
gko::Array<it>{this->exec, I<it>{0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5}},
gko::Array<it>{this->exec, I<it>{0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1}},
gko::Array<vt>{this->exec,
I<vt>{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}}};
gko::Array<index_type>{
this->exec, I<index_type>{0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5}},
gko::Array<index_type>{
this->exec, I<index_type>{0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1}},
gko::Array<value_type>{
this->exec, I<value_type>{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}}};
auto part = gko::share(part_type::build_from_contiguous(
this->exec, {this->exec, {0, 2, 4, 6}}));
auto vec = TestFixture::dist_vec_type::create(this->exec, this->comm);
auto rank = this->comm.rank();
I<I<vt>> ref_data[3] = {
I<I<value_type>> ref_data[3] = {
{{0, 1}, {2, 3}},
{{4, 5}, {6, 7}},
{{8, 9}, {10, 11}},
Expand Down Expand Up @@ -244,7 +244,8 @@ TYPED_TEST(VectorCreation, CanReadGlobalMatrixDataScattered)
vec->read_distributed(md, part.get());

GKO_ASSERT_EQUAL_DIMENSIONS(vec->get_size(), gko::dim<2>(6, 2));
GKO_ASSERT_EQUAL_DIMENSIONS(vec->get_local_vector()->get_size(), ref_size[rank]);
GKO_ASSERT_EQUAL_DIMENSIONS(vec->get_local_vector()->get_size(),
ref_size[rank]);
GKO_ASSERT_MTX_NEAR(vec->get_local_vector(), ref_data[rank], 0.0);
}

Expand Down Expand Up @@ -358,7 +359,6 @@ class VectorReductions : public ::testing::Test {
using global_index_type = gko::int64;
using part_type =
gko::distributed::Partition<local_index_type, global_index_type>;
using md_type = gko::matrix_data<value_type, global_index_type>;
using dist_vec_type = gko::distributed::Vector<value_type>;
using dense_type = gko::matrix::Dense<value_type>;
using real_dense_type = typename dense_type::real_type;
Expand Down Expand Up @@ -518,7 +518,6 @@ TYPED_TEST(VectorReductions, ComputesNorm1IsSameAsDense)

TYPED_TEST(VectorReductions, ComputeDotCopiesToHostOnlyIfNecessary)
{
using value_type = typename TestFixture::value_type;
this->init_result();
auto transfer_count_before = this->logger->get_transfer_count();

Expand All @@ -531,7 +530,6 @@ TYPED_TEST(VectorReductions, ComputeDotCopiesToHostOnlyIfNecessary)

TYPED_TEST(VectorReductions, ComputeConjDotCopiesToHostOnlyIfNecessary)
{
using value_type = typename TestFixture::value_type;
this->init_result();
auto transfer_count_before = this->logger->get_transfer_count();

Expand All @@ -544,7 +542,6 @@ TYPED_TEST(VectorReductions, ComputeConjDotCopiesToHostOnlyIfNecessary)

TYPED_TEST(VectorReductions, ComputeNorm2CopiesToHostOnlyIfNecessary)
{
using value_type = typename TestFixture::value_type;
this->init_result();
auto transfer_count_before = this->logger->get_transfer_count();

Expand All @@ -557,7 +554,6 @@ TYPED_TEST(VectorReductions, ComputeNorm2CopiesToHostOnlyIfNecessary)

TYPED_TEST(VectorReductions, ComputeNorm1CopiesToHostOnlyIfNecessary)
{
using value_type = typename TestFixture::value_type;
this->init_result();
auto transfer_count_before = this->logger->get_transfer_count();

Expand All @@ -572,11 +568,8 @@ template <typename ValueType>
class VectorLocalOps : public ::testing::Test {
public:
using value_type = ValueType;
using mixed_type = gko::next_precision<value_type>;
using local_index_type = gko::int32;
using global_index_type = gko::int64;
using part_type =
gko::distributed::Partition<local_index_type, global_index_type>;
using dist_vec_type = gko::distributed::Vector<value_type>;
using complex_dist_vec_type = typename dist_vec_type::complex_type;
using real_dist_vec_type = typename dist_vec_type ::real_type;
Expand Down Expand Up @@ -706,7 +699,6 @@ TYPED_TEST(VectorLocalOps, AdvancedApplyNotSupported)

TYPED_TEST(VectorLocalOps, ConvertsToPrecision)
{
using Vector = typename TestFixture::dist_vec_type;
using T = typename TestFixture::value_type;
using OtherT = typename gko::next_precision<T>;
using OtherVector = typename gko::distributed::Vector<OtherT>;
Expand All @@ -723,7 +715,6 @@ TYPED_TEST(VectorLocalOps, ConvertsToPrecision)

TYPED_TEST(VectorLocalOps, MovesToPrecision)
{
using Vector = typename TestFixture::dist_vec_type;
using T = typename TestFixture::value_type;
using OtherT = typename gko::next_precision<T>;
using OtherVector = typename gko::distributed::Vector<OtherT>;
Expand All @@ -746,7 +737,8 @@ TYPED_TEST(VectorLocalOps, ComputeAbsoluteSameAsLocal)
auto local_abs = this->local_x->compute_absolute();
auto abs = this->x->compute_absolute();

GKO_ASSERT_MTX_NEAR(abs->get_local_vector(), local_abs, r<value_type>::value);
GKO_ASSERT_MTX_NEAR(abs->get_local_vector(), local_abs,
r<value_type>::value);
}


Expand All @@ -771,7 +763,8 @@ TYPED_TEST(VectorLocalOps, MakeComplexSameAsLocal)
this->complex = this->x->make_complex();
this->local_complex = this->local_x->make_complex();

GKO_ASSERT_MTX_NEAR(this->complex->get_local_vector(), this->local_complex, 0.0);
GKO_ASSERT_MTX_NEAR(this->complex->get_local_vector(), this->local_complex,
0.0);
}


Expand All @@ -783,7 +776,8 @@ TYPED_TEST(VectorLocalOps, MakeComplexInplaceSameAsLocal)
this->x->make_complex(this->complex.get());
this->local_x->make_complex(this->local_complex.get());

GKO_ASSERT_MTX_NEAR(this->complex->get_local_vector(), this->local_complex, 0.0);
GKO_ASSERT_MTX_NEAR(this->complex->get_local_vector(), this->local_complex,
0.0);
}


Expand Down

0 comments on commit 6afb2b8

Please sign in to comment.