8000 Store sparsity by greole · Pull Request #37 · hpsim/OGL · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Store sparsity #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions IOHandler/IOGKOMatrixHandler/IOGKOMatrixHandler.C
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,18 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#include <ginkgo/ginkgo.hpp>
#include "IOGKOMatrixHandler.H"
#include "common.H"

namespace Foam {

void IOGKOMatrixHandler::init_device_matrix(
const objectRegistry &db, std::vector<scalar> &values_host,
std::vector<label> &col_idxs_host, std::vector<label> &row_idxs_host,
const label nElems, const label nCells, const bool store) const
const label nElems, const label nCells, const bool update) const
{
std::shared_ptr<gko::Executor> device_exec = get_device_executor();

if (sys_matrix_stored_) {
if (sys_matrix_stored_ && !update) {
gkomatrix_ptr_ = &db.lookupObjectRef<GKOCSRIOPtr>(sys_matrix_name_);
return;
}
Expand Down Expand Up @@ -75,24 +76,24 @@ void IOGKOMatrixHandler::init_device_matrix(
auto gkomatrix =
gko::share(mtx::create(device_exec, gko::dim<2>(nCells, nCells)));

SIMPLE_TIME(verbose_, convert_coo_to_csr,
coo_mtx->convert_to(gkomatrix.get());
)


// if updating system matrix is not needed store ptr in obj registry
if (store) {
const fileName path = sys_matrix_name_;
const fileName path = sys_matrix_name_;
if (!sys_matrix_stored_) {
gkomatrix_ptr_ = new GKOCSRIOPtr(IOobject(path, db), gkomatrix);
// in any case store sparsity pattern
const fileName path_col = sparsity_pattern_name_cols_;
const fileName path_row = sparsity_pattern_name_rows_;
io_col_idxs_ptr_ = new GKOIDXIOPtr(IOobject(path_col, db), col_idx);
io_row_idxs_ptr_ = new GKOIDXIOPtr(IOobject(path_row, db), row_idx);
} else {
gkomatrix_ptr_ = NULL;
gkomatrix_ = gkomatrix;
SIMPLE_LOG(verbose_, "Matrix has been updated ");
gkomatrix_ptr_ = new GKOCSRIOPtr(IOobject(path, db), gkomatrix);
}


// in any case store sparsity pattern
const fileName path_col = sparsity_pattern_name_cols_;
const fileName path_row = sparsity_pattern_name_rows_;
io_col_idxs_ptr_ = new GKOIDXIOPtr(IOobject(path_col, db), col_idx);
io_row_idxs_ptr_ = new GKOIDXIOPtr(IOobject(path_row, db), row_idx);
};


Expand Down
12 changes: 10 additions & 2 deletions IOHandler/IOGKOMatrixHandler/IOGKOMatrixHandler.H
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ private:

const bool update_init_guess_vector_;

const bool verbose_;

const bool export_;

mutable label prev_solve_iters_ = 0;
Expand Down Expand Up @@ -94,17 +96,23 @@ public:
db.foundObject<regIOobject>(init_guess_vector_name_)),
update_init_guess_vector_(
controlDict.lookupOrDefault<Switch>("updateInitVector", false)),

verbose_(
controlDict.lookupOrDefault<Switch>("verbose", false)),
export_(controlDict.lookupOrDefault<Switch>("export", false)){};

bool get_sys_matrix_stored() const { return sys_matrix_stored_; };

bool get_sparsity_pattern_stored() const
{
return sparsity_pattern_stored_;
};

void init_device_matrix(const objectRegistry &db,
std::vector<scalar> &values_host,
std::vector<label> &col_idxs_host,
std::vector<label> &row_idxs_host,
const label nElems, const label nCells,
const bool store) const;
const bool update) const;

std::shared_ptr<mtx> get_gkomatrix() const
{
Expand Down
7 changes: 6 additions & 1 deletion lduLduBase/lduLduBase.H
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public:
if (!stored) {
SIMPLE_TIME(verbose_, init_host_sparsity_pattern,
this->init_host_sparsity_pattern();)

SIMPLE_LOG(verbose_, "matrix not stored update host matrix")
SIMPLE_TIME(verbose_, update_host_mtx,
this->update_host_matrix_data();)
Expand All @@ -108,6 +109,10 @@ public:
"matrix is stored and update of host matrix requested")
SIMPLE_TIME(verbose_, exp_update_host_mtx,
this->update_host_matrix_data();)
SIMPLE_LOG(verbose_, "host matrix needs to be resorted")
SIMPLE_TIME(
verbose_, sort_host_mtx,
this->sort_host_matrix_data(this->get_sorting_idxs());)
}
}

Expand All @@ -133,7 +138,7 @@ public:

init_device_matrix(this->matrix().mesh().thisDb(), this->values(),
this->col_idxs(), this->row_idxs(), this->nElems(),
this->nCells(), !get_update_sys_matrix());
this->nCells(), get_update_sys_matrix());
}


Expand Down
0