Skip to content
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

Implementation of repartitioning distributed matrix wrapper #147

Merged
merged 69 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
4b009d5
add Repartitioner file
greole Aug 9, 2024
5a447aa
move implementation to body
greole Aug 9, 2024
ae2d38a
start adding repartitioner unit tests
greole Aug 15, 2024
5a7409b
small fixes
greole Aug 15, 2024
004c4d4
wip repartitioner implementations
greole Aug 16, 2024
7f771e1
fix test name
greole Aug 16, 2024
fe2c9f8
make it compile
greole Aug 16, 2024
9883fe8
format files
greole Aug 17, 2024
4f460a4
fix typos
greole Aug 17, 2024
1d754e1
add more unitTests
greole Aug 17, 2024
ee329da
move impl to .C files
greole Aug 17, 2024
732479a
add repart comm pattern basic unit test
greole Aug 18, 2024
bf46e9a
add 2 of 4 repartition test
greole Aug 18, 2024
05e62b6
add printer for vector of labels
greole Aug 18, 2024
02ea8d4
Add some description for get_coeffients function
chihta-wang Aug 12, 2024
eff21e8
- Add a unit test for Combination Matrix by using read function
chihta-wang Aug 12, 2024
d493a8d
- Add a mtx file for storing the vector b
chihta-wang Aug 14, 2024
4fdce85
- Use a sparse matrix with floating-point numbers to replace the orig…
chihta-wang Aug 14, 2024
422ece2
- Add a unit test for Combination Matrix which stores L, D, and U mat…
chihta-wang Aug 14, 2024
0b035b5
Finish the verification of entry values in the unit test for
chihta-wang Aug 14, 2024
040e7e8
Finish the unit test for the function convert_to COO format.
chihta-wang Aug 14, 2024
b416ff0
- Implement the function convert_to CSR
chihta-wang Aug 14, 2024
c84ec5e
- Implement the function move_to COO format for CombinationMatrix class
chihta-wang Aug 14, 2024
b3b7032
- Implement the function move_to CSR format for CombinationMatrix class
chihta-wang Aug 14, 2024
0450d2a
format files
greole Aug 17, 2024
9e4fc09
Apply suggestions from code review
greole Aug 20, 2024
9d36400
start value parameterization
greole Aug 20, 2024
b55c138
fix issue with narrowing conversion
greole Aug 20, 2024
34d1df2
improve doc strings, const correctnes
greole Aug 20, 2024
9c6961d
parameterize has_correct_properties test
greole Aug 20, 2024
b7cef8a
parameterize has_correct_properties test
greole Aug 20, 2024
2ef0fcd
removed solver compilation since it registers solver multiple times
greole Aug 20, 2024
42a8c54
implement can_repartition_1d_comm_pattern n ranks
greole Aug 20, 2024
6e5fd07
add rows check for 1d cells array
greole Aug 21, 2024
9435c5e
add unit test for 2d cells array
greole Aug 21, 2024
5fcd46a
add unit test for 2d cells array
greole Aug 21, 2024
f40969c
format files
greole Aug 21, 2024
da51180
format files, update reuse file
greole Aug 21, 2024
cc567e9
format file
greole Aug 21, 2024
8b4d406
format cmake files
greole Aug 21, 2024
df9f4f6
format files .mtx
greole Aug 21, 2024
afdf6ad
update docstring
greole Aug 21, 2024
341a5df
add docstrings, constructor, and compute dimensions function
greole Aug 24, 2024
edc9deb
implement exchange spans method
greole Aug 24, 2024
124e324
add compute_dimensions implementation
greole Aug 24, 2024
52a29fd
WIP repartition sparsisty
greole Aug 26, 2024
eba1ce2
WIP repartition sparsisty
greole Aug 27, 2024
1235ae5
refactor unit test, add WIP 1d sparsity pattern test
greole Aug 28, 2024
7953f05
add non local column test
greole Aug 28, 2024
bf078c0
Merge branch 'stack/ogl_0.6' into impl/repartitioner_sparsity
greole Aug 28, 2024
e5fa830
Merge remote-tracking branch 'origin/impl/repartitioner_sparsity' int…
greole Aug 28, 2024
e81098d
fix typos
greole Aug 28, 2024
3c6074b
format file
greole Aug 28, 2024
492761f
fix non local issue
greole Aug 28, 2024
1c1f505
fix typos
greole Aug 28, 2024
ef48e6e
format
greole Aug 28, 2024
45d70e9
add Distributed file
greole Aug 9, 2024
fa04ac8
make it compile
greole Aug 29, 2024
93a9b5b
add unit test
greole Aug 29, 2024
8318b16
extend unit test
greole Aug 29, 2024
731b75d
Fix local span computation
greole Aug 30, 2024
7836e5f
parameterize unit test, clean up
greole Aug 30, 2024
aa0dd6e
WIP make update_impl compile, start apply unit test
greole Aug 30, 2024
7e77323
add some more hostmatrix tests and getters
greole Aug 30, 2024
edd60a9
add working distributed unit test
greole Sep 3, 2024
315f591
add working distributed unit test
greole Sep 3, 2024
0d5db93
add export function
greole Sep 4, 2024
fa72256
format
greole Sep 4, 2024
e29975e
Fix typo
greole Sep 4, 2024
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
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ target_sources(
src/DevicePersistent/ExecutorHandler/ExecutorHandler.C
src/MatrixWrapper/HostMatrix.C
src/MatrixWrapper/SparsityPattern.C
src/MatrixWrapper/Distributed.C
src/Repartitioner.C
# src/Solver/CG/GKOCG.C src/Solver/BiCGStab/GKOBiCGStab.C
# src/Solver/GMRES/GKOGMRES.C
Expand Down
1 change: 1 addition & 0 deletions cmake/ginkgo.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ include(FetchContent)
if(NOT ${OGL_USE_EXTERNAL_GINKGO})
FetchContent_Declare(
Ginkgo
SYSTEM
QUITE
GIT_SHALLOW ON
GIT_REPOSITORY "https://github.com/ginkgo-project/ginkgo.git"
Expand Down
6 changes: 6 additions & 0 deletions include/OGL/CommunicationPattern.H
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ struct CommunicationPattern {
*/
gko::array<label> total_rank_send_idx() const;

/* @brief concatenate all separate send idxs arrays into one contiguous
* array
*/
gko::array<label> compute_recv_gather_idxs(
const ExecutorHandler &exec_handler) const;


/** Computes the send and recv pattern for ginkgos distributed matrix SpMV
*/
Expand Down
5 changes: 2 additions & 3 deletions include/OGL/DevicePersistent/DeviceIdGuard.H
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ struct DeviceIdGuardInitFunctor {
std::shared_ptr<gko::scoped_device_id_guard> init() const
{
return std::make_shared<gko::scoped_device_id_guard>(
std::move(executor_->get_scoped_device_id_guard()));
executor_->get_scoped_device_id_guard());
// std::move(executor_->get_scoped_device_id_guard()));
}
};

Expand All @@ -41,6 +42,4 @@ public:
{}
};


} // namespace Foam
// namespace Foam
9 changes: 4 additions & 5 deletions include/OGL/DevicePersistent/ExecutorHandler.H
Original file line number Diff line number Diff line change
Expand Up @@ -176,22 +176,21 @@ public:
MPI_COMM_WORLD, gko_force_host_buffer_);
}

std::shared_ptr<gko::experimental::mpi::communicator>
std::shared_ptr<const gko::experimental::mpi::communicator>
get_gko_mpi_device_comm() const
{
return this->device_comm_;
}

std::shared_ptr<gko::experimental::mpi::communicator> get_communicator()
const
std::shared_ptr<const gko::experimental::mpi::communicator>
get_communicator() const
{
return this->device_comm_;
}

label get_rank() const { return get_communicator().get()->rank(); };
label get_rank() const { return get_communicator()->rank(); };
};

using PersistentExecutor = ExecutorHandler;

} // namespace Foam
// namespace Foam
21 changes: 11 additions & 10 deletions include/OGL/DevicePersistent/Partition.H
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,18 @@ struct PartitionInitFunctor {

std::shared_ptr<part_type> init() const
{
auto exec = exec_.get_ref_exec();
auto comm = exec_.get_gko_mpi_host_comm();
FatalErrorInFunction << "Not implemented" << abort(FatalError);
// auto exec = exec_.get_ref_exec();
// auto comm = exec_.get_gko_mpi_host_comm();

word msg{"initialising partition of size " +
std::to_string(local_size_)};
LOG_1(verbose_, msg)
// word msg{"initialising partition of size " +
// std::to_string(local_size_)};
// LOG_1(verbose_, msg)

if (ranks_per_gpu_ == 1) return {};
// if (ranks_per_gpu_ == 1) return {};


return {};
}
};

Expand All @@ -84,8 +88,6 @@ class PersistentPartition

mutable label global_elements_;

const ExecutorHandler &exec_;

public:
using part_type = gko::experimental::distributed::Partition<label, label>;
/* PersistentPartition constructor using existing memory
Expand All @@ -107,8 +109,7 @@ public:
communication_pattern),
false, verbose),
ranks_per_gpu_(ranks_per_gpu),
local_elements_(elements),
exec_(exec)
local_elements_(elements)
{
auto comm = exec.get_gko_mpi_host_comm();
label local_elements = local_elements_;
Expand Down
60 changes: 57 additions & 3 deletions include/OGL/MatrixWrapper/Combination.H
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "fvCFD.H"


/* @brief The CombinationMatrix class is a wrapper around Ginkgos combination
* linear operator. It provides an interface for creating linear combinations of
* a given inner matrix type and a read implementation
Expand All @@ -18,7 +19,8 @@ class CombinationMatrix
public gko::EnableCreateMethod<CombinationMatrix<InnerMatrixType>>,
public gko::ReadableFromMatrixData<scalar, label>,
public gko::ConvertibleTo<gko::matrix::Coo<scalar, label>>,
public gko::ConvertibleTo<gko::matrix::Csr<scalar, label>> {
public gko::ConvertibleTo<gko::matrix::Csr<scalar, label>>,
public gko::WritableToMatrixData<scalar, label> {
friend class gko::EnableCreateMethod<CombinationMatrix<InnerMatrixType>>;
friend class gko::EnablePolymorphicObject<
CombinationMatrix<InnerMatrixType>, gko::LinOp>;
Expand Down Expand Up @@ -66,6 +68,25 @@ public:
return *this;
}


void write(gko::matrix_data<scalar> &res) const override
{
auto exec = this->get_executor();
auto operators = this->get_operators();

std::vector<gko::matrix_data_entry<scalar, label>> data;
for (auto op : operators) {
auto tmp_mat_data = gko::matrix_data<scalar>();
gko::as<InnerMatrixType>(op)->write(tmp_mat_data);
data.insert(data.end(), tmp_mat_data.nonzeros.begin(),
tmp_mat_data.nonzeros.end());
}
auto mat_data = gko::matrix_data<scalar>();
res.nonzeros = data;
res.size = this->get_size();
}


/**
* Returns a list of coefficients of the combination.
*
Expand Down Expand Up @@ -176,7 +197,7 @@ protected:
* */
void apply_impl(const gko::LinOp *b, gko::LinOp *x) const override
{
if (this->get_size()[0] > 0) {
if (this->get_size()[0] > 0 && this->get_size()[1] > 0) {
this->comb_->apply(b, x);
}
}
Expand All @@ -187,11 +208,44 @@ protected:
void apply_impl(const gko::LinOp *alpha, const gko::LinOp *b,
const gko::LinOp *beta, gko::LinOp *x) const override
{
if (this->get_size()[0] > 0) {
if (this->get_size()[0] > 0 && this->get_size()[1] > 0) {
this->comb_->apply(alpha, b, beta, x);
}
}

private:
std::shared_ptr<gko::Combination<scalar>> comb_;
};


namespace detail {
std::shared_ptr<gko::matrix::Coo<scalar, label>> convert_combination_to_coo(
std::shared_ptr<const gko::Executor> exec,
std::shared_ptr<const gko::LinOp> in)
{
auto out = gko::share(gko::matrix::Coo<scalar, label>::create(exec));
gko::as<CombinationMatrix<gko::matrix::Coo<scalar, label>>>(in)->convert_to(
out.get());

return out;
}

template <typename InnerMatrixType>
void export_mtx(const word fieldName,
std::shared_ptr<CombinationMatrix<InnerMatrixType>> out,
const word local, const objectRegistry &db,
const word matrixFormat)
{
std::string folder{db.time().timePath()};
std::filesystem::create_directories(folder);
std::string fn{folder + "/" + fieldName + "_A_" + local + ".mtx"};
std::cout << "exporting " << fn << std::endl;
std::ofstream stream{fn};
stream << std::setprecision(15);

auto coo = gko::share(
gko::matrix::Coo<scalar, label>::create(out->get_executor()));
out->convert_to(coo);
}

} // namespace detail
Loading
Loading