Skip to content

Commit

Permalink
wip refactor everything again
Browse files Browse the repository at this point in the history
  • Loading branch information
greole committed Nov 19, 2024
1 parent b53bb06 commit 1cec3af
Show file tree
Hide file tree
Showing 15 changed files with 1,732 additions and 1,843 deletions.
17 changes: 8 additions & 9 deletions include/OGL/MatrixWrapper/Distributed.H
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public:

std::shared_ptr<const gko::LinOp> get_local() const
{
if (repartitioner_->get_fused()) {
if (fuse_) {
return dist_mtx_->get_local_matrix();
} else {
return gko::as<CombinationMatrix<gko::LinOp>>(
Expand All @@ -77,12 +77,12 @@ public:
gko::experimental::EnableDistributedLinOp<
RepartDistMatrix>::operator=(other);
this->dist_mtx_ = other.dist_mtx_;
this->fuse_ = other.fuse_;
this->local_sparsity_ = other.local_sparsity_;
this->non_local_sparsity_ = other.non_local_sparsity_;
this->src_comm_pattern_ = other.src_comm_pattern_;
this->repart_comm_pattern_ = other.repart_comm_pattern_;
this->repartitioner_ = other.repartitioner_;
this->local_interfaces_ = other.local_interfaces_;
}
return *this;
}
Expand All @@ -98,13 +98,13 @@ public:
FatalErrorInFunction << "Not implemented" << abort(FatalError);
gko::experimental::EnableDistributedLinOp<
RepartDistMatrix>::operator=(std::move(other));
this->fuse_ = other.fuse_;
this->dist_mtx_ = std::move(other.dist_mtx_);
this->local_sparsity_ = std::move(other.local_sparsity_);
this->non_local_sparsity_ = std::move(other.non_local_sparsity_);
this->src_comm_pattern_ = std::move(other.src_comm_pattern_);
this->repart_comm_pattern_ = std::move(other.repart_comm_pattern_);
this->repartitioner_ = std::move(other.repartitioner_);
this->local_interfaces_ = std::move(other.local_interfaces_);
}
return *this;
}
Expand All @@ -125,18 +125,17 @@ public:
std::shared_ptr<const SparsityPattern> non_local_sparsity,
std::shared_ptr<const CommunicationPattern> src_comm_pattern,
std::shared_ptr<const CommunicationPattern> repart_comm_pattern,
std::shared_ptr<const Repartitioner> repartitioner,
std::vector<InterfaceLocality> &local_interfaces)
std::shared_ptr<const Repartitioner> repartitioner, bool fuse)
: gko::experimental::EnableDistributedLinOp<RepartDistMatrix>(exec),
gko::experimental::distributed::DistributedBase(comm),
fuse_(fuse),
matrix_format_(matrix_format),
dist_mtx_(std::move(dist_mtx)),
local_sparsity_(local_sparsity),
non_local_sparsity_(non_local_sparsity),
src_comm_pattern_(src_comm_pattern),
repart_comm_pattern_(repart_comm_pattern),
repartitioner_(repartitioner),
local_interfaces_(local_interfaces)
repartitioner_(repartitioner)
{
this->set_size(dist_mtx_->get_size());
}
Expand Down Expand Up @@ -196,6 +195,8 @@ protected:


private:
bool fuse_;

const word matrix_format_;

std::shared_ptr<dist_mtx> dist_mtx_;
Expand All @@ -209,8 +210,6 @@ private:
std::shared_ptr<const CommunicationPattern> repart_comm_pattern_;

std::shared_ptr<const Repartitioner> repartitioner_;

std::vector<InterfaceLocality> local_interfaces_;
};

std::shared_ptr<const gko::LinOp> get_local(
Expand Down
86 changes: 49 additions & 37 deletions include/OGL/MatrixWrapper/HostMatrix.H
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private:
// number of local elements on interfaces
// ie number of interfaces which column_idx is < nrows_
// and have to be sorted into local matrix
const label local_interface_nnz_;
// const label local_interface_nnz_;

// total number of local upper and lower elements
// ie 2*upper_nnz_ since the sparsity pattern is symmetric
Expand All @@ -120,10 +120,10 @@ private:
const label local_matrix_nnz_;

// nnzs of local matrix including local interfaces
const label local_matrix_w_interfaces_nnz_;
// const label local_matrix_w_interfaces_nnz_;

// non-local indices
const label non_local_matrix_nnz_;
// const label non_local_matrix_nnz_;

const lduInterfaceFieldPtrsList &interfaces_;

Expand Down Expand Up @@ -184,20 +184,19 @@ private:
** contains coefficients that resides on the owning rank. The coefficient
** can include local interfaces.
**/
[[nodiscard]] std::tuple<std::vector<label>, std::vector<label>,
std::vector<label>, std::vector<gko::span>>
compute_local_sparsity(std::shared_ptr<const gko::Executor> exec) const;
[[nodiscard]] std::shared_ptr<SparsityPattern> compute_local_sparsity()
const;

/** Based on OpenFOAMs interfaces this function computes
** the interface sparsity pattern.
** Here, the sparsity pattern
** only contains all coefficient that reside on an interface (local and
*non-local).
**/
[[nodiscard]] std::tuple<std::vector<label>, std::vector<label>,
std::vector<label>, std::vector<label>,
std::vector<gko::span>>
compute_interface_sparsity(std::shared_ptr<const gko::Executor> exec) const;
[[nodiscard]] std::shared_ptr<SparsityPattern> compute_interface_sparsity(
std::shared_ptr<
const gko::experimental::distributed::Partition<label, label>>
partition) const;


public:
Expand Down Expand Up @@ -228,22 +227,27 @@ public:
**/
[[nodiscard]] std::pair<std::shared_ptr<SparsityPattern>,
std::shared_ptr<SparsityPattern>>
compute_sparsity_patterns(std::shared_ptr<const gko::Executor> exec) const;

/** Copies the LDU matrix coefficients to local_coeffs without changing or
** reinstantiating the sparsity pattern.
** This uses the local_sparsity_.ldu_mapping to permute the data already
** on the host or device to be in row major order.
**/
void compute_local_coeffs(std::shared_ptr<const SparsityPattern> sparsity,
gko::array<scalar> &target_coeffs) const;

/** Copies the interface matrix coefficients to non_local_coeffs without
** changing or reinstantiating the sparsity pattern.
**/
void compute_non_local_coeffs(
std::shared_ptr<const SparsityPattern> sparsity,
gko::array<scalar> &target_coeffs) const;
compute_sparsity_patterns(
std::shared_ptr<
const gko::experimental::distributed::Partition<label, label>>
partition) const;

// /** Copies the LDU matrix coefficients to local_coeffs without changing
// or
// ** reinstantiating the sparsity pattern.
// ** This uses the local_sparsity_.ldu_mapping to permute the data already
// ** on the host or device to be in row major order.
// **/
// void compute_local_coeffs(std::shared_ptr<const SparsityPattern>
// sparsity,
// gko::array<scalar> &target_coeffs) const;

// /** Copies the interface matrix coefficients to non_local_coeffs without
// ** changing or reinstantiating the sparsity pattern.
// **/
// void compute_non_local_coeffs(
// std::shared_ptr<const SparsityPattern> sparsity,
// gko::array<scalar> &target_coeffs) const;


/** Iterates all interfaces and counts the number of unique neighbour
Expand All @@ -260,17 +264,18 @@ public:

label get_local_nrows() const { return nrows_; }

label get_local_matrix_wo_interface_nnz() const
{
return local_matrix_nnz_;
}
// label get_local_matrix_wo_interface_nnz() const
// {
// return local_matrix_nnz_;
// }

/* return the total nnz of local matrix including local interface */
label get_local_matrix_nnz() const
{
return local_matrix_w_interfaces_nnz_;
}
// label get_local_matrix_nnz() const
// {
// return local_matrix_w_interfaces_nnz_;
// }

label get_upper_nnz() const { return upper_nnz_; }
// label get_upper_nnz() const { return upper_nnz_; }

const scalar *get_lower() const { return lower_; }

Expand All @@ -285,9 +290,16 @@ public:

label get_num_interfaces() const { return interface_ptr_.size(); };

const scalar *get_interface_data(label i) const
/* returns access to interface data pointer via
* id:
* 0 - upper
* 1 - lower
* 2 - diag
* n - interfaces
* */
const scalar *get_interface_data(label id) const
{
return interface_ptr_[i];
return interface_ptr_[id];
}

bool get_symmetric() const { return symmetric_; }
Expand Down
Loading

0 comments on commit 1cec3af

Please sign in to comment.