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

Thin host matrix wrapper #140

Merged
merged 54 commits into from
Jul 23, 2024
Merged

Thin host matrix wrapper #140

merged 54 commits into from
Jul 23, 2024

Conversation

greole
Copy link
Collaborator

@greole greole commented Jun 27, 2024

This PR adds a thin wrapper class around OpenFOAMs host LDU matrix class. The aim of this class is to simplify compute and access functions in order to create a ginkgo distributed matrix object. Ideally, this class doesn't need to be device persistent if we just make the distributed matrix class device persistent and an update function.

Additionally it introduces a communication pattern wrapper class.

@greole greole changed the title initial commit for new thin host matrix wrapper Thin host matrix wrapper Jun 27, 2024
src/CommunicationPattern/CommunicationPattern.H Outdated Show resolved Hide resolved
src/CommunicationPattern/CommunicationPattern.H Outdated Show resolved Hide resolved
src/CommunicationPattern/CommunicationPattern.H Outdated Show resolved Hide resolved
src/CommunicationPattern/CommunicationPattern.H Outdated Show resolved Hide resolved
src/CommunicationPattern/CommunicationPattern.H Outdated Show resolved Hide resolved
src/CommunicationPattern/CommunicationPattern.H Outdated Show resolved Hide resolved
src/CommunicationPattern/CommunicationPattern.H Outdated Show resolved Hide resolved
src/CommunicationPattern/CommunicationPattern.H Outdated Show resolved Hide resolved
src/CommunicationPattern/CommunicationPattern.H Outdated Show resolved Hide resolved
src/CommunicationPattern/CommunicationPattern.H Outdated Show resolved Hide resolved
unitTests/CommunicationPattern.C Outdated Show resolved Hide resolved
unitTests/CommunicationPattern.C Show resolved Hide resolved
unitTests/CommunicationPattern.C Show resolved Hide resolved
include/OGL/CommunicationPattern.H Outdated Show resolved Hide resolved
include/OGL/CommunicationPattern.H Outdated Show resolved Hide resolved
include/OGL/CommunicationPattern.H Outdated Show resolved Hide resolved
// to the corresponding target_id
gko::array<comm_size_type> target_sizes;

// send_idx stores the index_set ie which cells
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the variable index_set from?

include/OGL/CommunicationPattern.H Outdated Show resolved Hide resolved
include/OGL/CommunicationPattern.H Show resolved Hide resolved
include/OGL/CommunicationPattern.H Show resolved Hide resolved
include/OGL/CommunicationPattern.H Show resolved Hide resolved
to make it clear that there is only one owner process in the test
The unit test does not verify any functionality of CommunicationPattern.
It verifies the functionality of a MPI communicator, and thus should not
belong to the test suite for CommunicationPattern.

To make some hardcoded unit tests more self-contained, the ascertain part
for the communicator size is added accordinlgy.
chihta-wang and others added 24 commits July 15, 2024 20:36
1. Use vectors instead of vectors of vectors for expected results.
2. Parameterize the communicator size to avoid the repeated function calls.
… that it is not

hardcoded anymore.
Now it can run on an arbitrarily even number of processes.
and "compute_gather_to_owner_counts_single_owner" to verify
that each process can send a different number of elements to owner processes.
for the moment.

Modify the unit test "compute_scatter_from_owner_counts_single_owner" so that
the owner can send data to itself.
If only 1 process is used, the program will abort.
implement additional unit tests for communication pattern, see #143
unitTests/HostMatrix.C Outdated Show resolved Hide resolved
Copy link
Collaborator

@chihta-wang chihta-wang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check the comments for the header file HostMatrix.H and for the unit test code HostMatrix.C.

We may need some unit tests for the member functions of the class HostMatrixWrapper?

** @param cols pointer to columns array
** @param permute pointer to permuter array
*/
void init_local_sparsity(const label nrows, const label upper_nnz,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why only upper non-zeros are considered? How about the lower non-zeros?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const label upper_nnz is just the number of entries in the upper triangular matrix. the number of upper_nnz==lower_nnz

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
void init_local_sparsity(const label nrows, const label upper_nnz,
void init_local_sparsity(const label nrows, const label non_diag_nnz,

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'll keep it as upper_nnz, because we already use non_diag_nnz for 2*upper_nnz


const ExecutorHandler &exec_;

const DeviceIdGuardHandler device_id_guard_;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is device_id_guard?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for more details see scoped_device_id_guard.hpp in Ginkgo

** ret = [(1,2,1),(2,20, 2), (3, 20, 2) ...]
** i0 i1, i...
*/
[[nodiscard]] std::vector<std::tuple<label, label, label, label>>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a inconsistency between the comment and the function declaration regarding the return value.
In the comment, a vector of 3-element tuples is specified for the return value. However, the function declaration has a vector of 4-element tuples as the return type.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch.

const lduInterfaceFieldPtrsList &interfaces) const;

public:
// segregated matrix wrapper constructor
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is a segregated matrix?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OF uses the term segregated opposed to coupled matrix. In a coupled matrix all transport equations are stored in a single matrix. In a segregated approach each transport equation gets its own matrix.

EXPECT_EQ(((HostMatrixEnvironment *)global_env)->args_->size(), 1);
}

TEST(HostMatrix, runsInParallelWithCorrectNumberOfRanks)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the unit tests for host matrix wrapper are hardcoded at the moment, it's better to put this test to a place where setup takes place, e.g., the body of the SetUp function

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aggree, will do that.

** 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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is compute_local_coeffs implemented?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, not. Will either added here in a separate PR or somewhere else. The reason is that it depends on the new distributed matrix wrapper class which is currently missing.

/** Copies the interface matrix coefficients to non_local_coeffs without
** changing or reinstantiating the sparsity pattern.
**/
void compute_non_local_coeffs(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is compute_non_local_coeffs implemented?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as for the local_coeffs.

@greole greole merged commit e6ce3e7 into stack/ogl_0.6 Jul 23, 2024
10 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The send_offsets and recv_offsets returned by the function compute_scatter_from_owner_counts
2 participants