Skip to content

Commit

Permalink
review updates
Browse files Browse the repository at this point in the history
Co-authored-by: Tobias Ribizel <ribizel@kit.edu>
  • Loading branch information
MarcelKoch and upsj committed Mar 29, 2022
1 parent f1736b2 commit 5ef505b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 29 deletions.
41 changes: 19 additions & 22 deletions core/distributed/matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ Matrix<ValueType, LocalIndexType, GlobalIndexType>::Matrix(
dynamic_cast<ReadableFromMatrixData<ValueType, LocalIndexType>*>(
offdiag_mtx.get())));
one_scalar_.init(exec, dim<2>{1, 1});
initialize<local_vector_type>({one<value_type>()}, exec)
->move_to(one_scalar_.get());
one_scalar_->fill(one<value_type>());
}


Expand Down Expand Up @@ -270,28 +269,28 @@ void Matrix<ValueType, LocalIndexType, GlobalIndexType>::apply_impl(
const LinOp* b, LinOp* x) const
{
auto dense_b = as<global_vector_type>(b);
auto exec = this->get_executor();
auto dense_x = as<global_vector_type>(x);
auto mutable_local_x = gko::matrix::Dense<ValueType>::create(
x->get_executor(), dense_x->get_local_vector()->get_size(),
auto x_exec = x->get_executor();
auto local_x = gko::matrix::Dense<ValueType>::create(
x_exec, dense_x->get_local_vector()->get_size(),
gko::make_array_view(
x->get_executor(),
dense_x->get_local_vector()->get_num_stored_elements(),
x_exec, dense_x->get_local_vector()->get_num_stored_elements(),
dense_x->get_local_values()),
dense_x->get_local_vector()->get_stride());
if (this->get_const_local_offdiag()->get_size()) {
auto req = this->communicate(dense_b->get_local_vector());
diag_mtx_->apply(dense_b->get_local_vector(), mutable_local_x.get());
diag_mtx_->apply(dense_b->get_local_vector(), local_x.get());
req.wait();
auto exec = this->get_executor();
auto needs_host_buffer =
exec->get_master() != exec && !gko::mpi::is_gpu_aware();
if (needs_host_buffer) {
recv_buffer_->copy_from(host_recv_buffer_.get());
}
offdiag_mtx_->apply(one_scalar_.get(), recv_buffer_.get(),
one_scalar_.get(), mutable_local_x.get());
one_scalar_.get(), local_x.get());
} else {
diag_mtx_->apply(dense_b->get_local_vector(), mutable_local_x.get());
diag_mtx_->apply(dense_b->get_local_vector(), local_x.get());
}
}

Expand All @@ -302,31 +301,31 @@ void Matrix<ValueType, LocalIndexType, GlobalIndexType>::apply_impl(
{
auto dense_b = as<global_vector_type>(b);
auto dense_x = as<global_vector_type>(x);
auto mutable_local_x = gko::matrix::Dense<ValueType>::create(
x->get_executor(), dense_x->get_local_vector()->get_size(),
const auto x_exec = x->get_executor();
auto local_x = gko::matrix::Dense<ValueType>::create(
x_exec, dense_x->get_local_vector()->get_size(),
gko::make_array_view(
x->get_executor(),
dense_x->get_local_vector()->get_num_stored_elements(),
x_exec, dense_x->get_local_vector()->get_num_stored_elements(),
dense_x->get_local_values()),
dense_x->get_local_vector()->get_stride());
auto exec = this->get_executor();
auto local_alpha = as<local_vector_type>(alpha);
auto local_beta = as<local_vector_type>(beta);
if (this->get_const_local_offdiag()->get_size()) {
auto req = this->communicate(dense_b->get_local_vector());
diag_mtx_->apply(local_alpha, dense_b->get_local_vector(), local_beta,
mutable_local_x.get());
local_x.get());
req.wait();
auto exec = this->get_executor();
auto needs_host_buffer =
exec->get_master() != exec && !gko::mpi::is_gpu_aware();
if (needs_host_buffer) {
recv_buffer_->copy_from(host_recv_buffer_.get());
}
offdiag_mtx_->apply(local_alpha, recv_buffer_.get(), one_scalar_.get(),
mutable_local_x.get());
local_x.get());
} else {
diag_mtx_->apply(local_alpha, dense_b->get_local_vector(), local_beta,
mutable_local_x.get());
local_x.get());
}
}

Expand Down Expand Up @@ -369,8 +368,7 @@ Matrix<ValueType, LocalIndexType, GlobalIndexType>::operator=(
recv_sizes_ = other.recv_sizes_;
local_to_global_ghost_ = other.local_to_global_ghost_;
one_scalar_.init(this->get_executor(), dim<2>{1, 1});
initialize<local_vector_type>({one<value_type>()}, this->get_executor())
->move_to(one_scalar_.get());
one_scalar_->fill(one<value_type>());
}
return *this;
}
Expand All @@ -394,8 +392,7 @@ Matrix<ValueType, LocalIndexType, GlobalIndexType>::operator=(
recv_sizes_ = std::move(other.recv_sizes_);
local_to_global_ghost_ = std::move(other.local_to_global_ghost_);
one_scalar_.init(this->get_executor(), dim<2>{1, 1});
initialize<local_vector_type>({one<value_type>()}, this->get_executor())
->move_to(one_scalar_.get());
one_scalar_->fill(one<value_type>());
}
return *this;
}
Expand Down
8 changes: 4 additions & 4 deletions include/ginkgo/core/distributed/vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,17 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <ginkgo/core/base/dense_cache.hpp>
#include <ginkgo/core/base/mpi.hpp>
#include <ginkgo/core/distributed/base.hpp>
#include <ginkgo/core/distributed/partition.hpp>
#include <ginkgo/core/matrix/dense.hpp>


namespace gko {
namespace distributed {


template <typename LocalIndexType, typename GlobalIndexType>
class Partition;


/**
* Vector is a format which explicitly stores (multiple) distributed column
* vectors in a dense storage format.
Expand All @@ -71,9 +74,6 @@ namespace distributed {
* @note Operations between two vectors (axpy, dot product, etc.) are only valid
* if both vectors where created using the same partition.
*
* @note Operations between two vectors (axpy, dot product, etc.) are only valid
* if both vectors use the same partition.
*
* @tparam ValueType The precision of vector elements.
*
* @ingroup dist_vector
Expand Down
6 changes: 3 additions & 3 deletions reference/distributed/matrix_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ void build_diag_offdiag(
};

// store offdiagonal columns and their range indices
std::map<GlobalIndexType, range_index_type> offdiag_cols;
map<GlobalIndexType, range_index_type> offdiag_cols(exec);
// store offdiagonal entries with global column idxs
std::vector<global_nonzero> global_offdiag_entries;
std::vector<local_nonzero> diag_entries;
vector<global_nonzero> global_offdiag_entries(exec);
vector<local_nonzero> diag_entries(exec);
for (size_type i = 0; i < input.get_num_elems(); ++i) {
const auto global_row = input_row_idxs[i];
const auto global_col = input_col_idxs[i];
Expand Down

0 comments on commit 5ef505b

Please sign in to comment.