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

Additive read distributed #1650

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open

Conversation

fritzgoebel
Copy link
Collaborator

@fritzgoebel fritzgoebel commented Jul 16, 2024

This PR adds an option to communicate overlap in the distributed matrix' read_distributed. If the option is used, nonzero entries present in multiple ranks are added up on the owning rank rather than thrown away in read_distributed.

This can be useful e.g. if in a domain decomposed finite element setting, each rank assembles their local contribution to a global system matrix and when assembling the global system matrix information on the subdomain boundaries has to be exchanged.

TODO:

  • Implement reference kernel tests
  • Implement device kernels
  • Implement device kernel tests

@ginkgo-bot ginkgo-bot added the mod:all This touches all Ginkgo modules. label Jul 16, 2024
@fritzgoebel fritzgoebel added is:new-feature A request or implementation of a feature that does not exist yet. 1:ST:WIP This PR is a work in progress. Not ready for review. type:distributed-functionality labels Jul 16, 2024
@fritzgoebel fritzgoebel self-assigned this Jul 23, 2024
@fritzgoebel fritzgoebel removed the 1:ST:WIP This PR is a work in progress. Not ready for review. label Jul 23, 2024
@fritzgoebel fritzgoebel marked this pull request as ready for review July 23, 2024 15:24
@fritzgoebel fritzgoebel added the 1:ST:ready-for-review This PR is ready for review label Jul 23, 2024
@MarcelKoch MarcelKoch self-requested a review August 8, 2024 11:58
Copy link
Member

@MarcelKoch MarcelKoch left a comment

Choose a reason for hiding this comment

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

Mostly smaller stuff. Only the communication change would be significant, if that would be done.

* - local_only does not communicate any overlap but ignores all non-local
* indices.
*/
enum class assembly { communicate, local_only };
Copy link
Member

Choose a reason for hiding this comment

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

nit:

Suggested change
enum class assembly { communicate, local_only };
enum class assembly_mode { communicate, local_only };

exec->copy_from(exec, n_recv, overlap_recv_values.get_data(),
all_values.get_data() + num_entries);
all_data = device_matrix_data<value_type, global_index_type>{
exec, global_dim, all_row_idxs, all_col_idxs, all_values};
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
exec, global_dim, all_row_idxs, all_col_idxs, all_values};
exec, global_dim, std::move(all_row_idxs), std::move(all_col_idxs), std::move(all_values)};

otherwise we would have copies.

Comment on lines +300 to +305
array<global_index_type> overlap_send_row_idxs{exec, n_send};
array<global_index_type> overlap_send_col_idxs{exec, n_send};
array<value_type> overlap_send_values{exec, n_send};
array<global_index_type> overlap_recv_row_idxs{exec, n_recv};
array<global_index_type> overlap_recv_col_idxs{exec, n_recv};
array<value_type> overlap_recv_values{exec, n_recv};
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
array<global_index_type> overlap_send_row_idxs{exec, n_send};
array<global_index_type> overlap_send_col_idxs{exec, n_send};
array<value_type> overlap_send_values{exec, n_send};
array<global_index_type> overlap_recv_row_idxs{exec, n_recv};
array<global_index_type> overlap_recv_col_idxs{exec, n_recv};
array<value_type> overlap_recv_values{exec, n_recv};
device_matrix_data<value_type, global_index_type> overlap_send_data{exec, n_send};
device_matrix_data<value_type, global_index_type> overlap_recv_data{exec, n_send};

A bit less repetitive.

overlap_recv_values.set_executor(exec);
}

array<global_index_type> all_row_idxs{exec, num_entries + n_recv};
Copy link
Member

Choose a reason for hiding this comment

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

num_entries + n_recv means that the full device_matrix_data also contains the elements that were sent to other processes right? But I realized, that we can't modify the input matrix data, so we have to work with it anyway.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, but they get ignored when the local and non_local matrices are created, just as before.

if (assembly_type == assembly::communicate) {
size_type num_entries = data.get_num_stored_elements();
size_type num_parts = comm.size();
array<comm_index_type> overlap_count{exec, num_parts};
Copy link
Member

Choose a reason for hiding this comment

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

nit:

Suggested change
array<comm_index_type> overlap_count{exec, num_parts};
array<comm_index_type> send_sizes{exec, num_parts};

IMO using overlap here is not ideal, since that implies a bidirectional communication, but we don't require that. Instead I would just use send and recv respectively.

gko::kernels::reference::distributed_matrix::count_overlap_entries(
this->ref, input, partition.get(), i, overlap_count,
overlap_positions, original_positions);
GKO_ASSERT_ARRAY_EQ(overlap_count, overlap_count_ref[i]);
Copy link
Member

Choose a reason for hiding this comment

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

nit

Suggested change
GKO_ASSERT_ARRAY_EQ(overlap_count, overlap_count_ref[i]);
GKO_ASSERT_ARRAY_EQ(overlap_count, overlap_count_ref[i]);

{
using lit = typename TestFixture::local_index_type;
using git = typename TestFixture::global_index_type;
using vt = typename TestFixture::value_type;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
using vt = typename TestFixture::value_type;

using lit = typename TestFixture::local_index_type;
using git = typename TestFixture::global_index_type;
using vt = typename TestFixture::value_type;
using ca = gko::array<comm_index_type>;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
using ca = gko::array<comm_index_type>;

this->ref, input, partition.get(), i, overlap_positions[i],
original_positions[i], overlap_row_idxs, overlap_col_idxs,
overlap_values);
GKO_ASSERT_ARRAY_EQ(overlap_row_idxs, overlap_row_idxs_ref[i]);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
GKO_ASSERT_ARRAY_EQ(overlap_row_idxs, overlap_row_idxs_ref[i]);
GKO_ASSERT_ARRAY_EQ(overlap_row_idxs, overlap_row_idxs_ref[i]);

overlap_row_idxs.resize_and_reset(num_entries);
overlap_col_idxs.resize_and_reset(num_entries);
overlap_values.resize_and_reset(num_entries);
gko::kernels::reference::distributed_matrix::fill_overlap_send_buffers(
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
gko::kernels::reference::distributed_matrix::fill_overlap_send_buffers(
gko::kernels::reference::distributed_matrix::fill_overlap_send_buffers(

@MarcelKoch MarcelKoch added this to the Ginkgo 1.9.0 milestone Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1:ST:ready-for-review This PR is ready for review is:new-feature A request or implementation of a feature that does not exist yet. mod:all This touches all Ginkgo modules. type:distributed-functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants