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

implement additional unit tests for communication pattern #143

Merged
merged 23 commits into from
Jul 16, 2024

Conversation

chihta-wang
Copy link
Collaborator

Add new unit tests for the following functions

  • compute_owner_rank
  • compute_gather_to_owner_counts
  • compute_scatter_from_owner_counts

Refactor original unit tests for the function compute_gather_to_owner_counts

The unit tests can run on any arbitrary even number of CPU processes.

@chihta-wang
Copy link
Collaborator Author

chihta-wang commented Jul 15, 2024

The send_offsets and recv_offsets returned by the function compute_scatter_from_owner are of the size equal to comm->size()

The expected size should be comm->size() + 1

Run the unit test compute_scatter_from_owner_counts_single_owner to find out more details.

@greole greole changed the base branch from dev to impl/host_wrapper July 15, 2024 09:34
Copy link
Collaborator

@greole greole left a comment

Choose a reason for hiding this comment

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

Looks good so far, but please remove unused code and use curly brace for for loops and if blocks

auto comm = exec->get_gko_mpi_host_comm();
EXPECT_EQ(comm->size(), 4);
Copy link
Collaborator

Choose a reason for hiding this comment

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

we still need a test if comm->size() works and returns a result that is > 1

Copy link
Collaborator Author

@chihta-wang chihta-wang Jul 15, 2024

Choose a reason for hiding this comment

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

Okay, but it is better to put this test outside of any specific unit test.
All the unit tests should not be run if the size of a communicator is not great than 1. For example, it should be checked during the construction of the fixture object.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

All functionalities of a communicator should be verified in the corresponding unit tests for communicator.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok I am fine with either approach, the main point is that it should be directly obvious that the test should fail if it is not run with sufficient number of ranks!

Comment on lines 81 to 82
for (int i = 0; i < comm_size; i++)
send_counts[i] = num_elements*i;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add curly braces here, even if it is correct notation without.

Suggested change
for (int i = 0; i < comm_size; i++)
send_counts[i] = num_elements*i;
for (int i = 0; i < comm_size; i++) {
send_counts[i] = num_elements*i;
}

// Scatter different number of elements from owner to each non-owner process
std::vector<int> send_counts(comm_size);

if (comm_rank == 0)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add curly braces here

unitTests/CommunicationPattern.C Outdated Show resolved Hide resolved
unitTests/CommunicationPattern.C Outdated Show resolved Hide resolved
chihta-wang and others added 22 commits July 15, 2024 20:34
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.
All processes in the communicator are owner processes.
for the case of only a single owner process so that any number of elements
can be set for the test
In the arrange section,
1. remove the vector of vector previously used for expected results
   Use a vector for the expected result instead.
2. Add vectors for the expected results of receive parts (recv_counts and recv_offsets)

In the assert section,
use vectors instead of vectors of vectors for both send and receive parts
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.
@greole greole force-pushed the impl/unit_tests_communication-pattern branch from 95aef04 to 6d09fb2 Compare July 15, 2024 18:49
@greole greole changed the title Impl/unit tests communication pattern implement additional unit tests for communication pattern Jul 16, 2024
@greole greole merged commit f420227 into impl/host_wrapper Jul 16, 2024
6 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.

2 participants