-
Notifications
You must be signed in to change notification settings - Fork 191
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
Add SendDataToElement action for nodegroup elements #6041
Merged
nilsdeppe
merged 2 commits into
sxs-collaboration:develop
from
nilsdeppe:add_threading_16
Jun 1, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// Distributed under the MIT License. | ||
// See LICENSE.txt for details. | ||
|
||
#pragma once | ||
|
||
#include <cstddef> | ||
#include <mutex> | ||
#include <type_traits> | ||
#include <utility> | ||
|
||
#include "DataStructures/DataBox/DataBox.hpp" | ||
#include "Domain/Structure/ElementId.hpp" | ||
#include "Evolution/DiscontinuousGalerkin/AtomicInboxBoundaryData.hpp" | ||
#include "Parallel/ArrayCollection/ReceiveDataForElement.hpp" | ||
#include "Parallel/ArrayCollection/Tags/ElementLocations.hpp" | ||
#include "Parallel/GlobalCache.hpp" | ||
#include "Parallel/Info.hpp" | ||
#include "Parallel/NodeLock.hpp" | ||
#include "Utilities/Gsl.hpp" | ||
#include "Utilities/TaggedTuple.hpp" | ||
|
||
namespace Parallel::Actions { | ||
/*! | ||
* \brief A local synchronous action where data is communicated to neighbor | ||
* elements. | ||
* | ||
* If the inbox tag type is an `evolution::dg::AtomicInboxBoundaryData` then | ||
* remote insert for elements on the same node is done in a lock-free manner | ||
* between the sender and receiver elements, and in a wait-free manner between | ||
* different sender elements to the same receiver element. | ||
* | ||
* The number of messages needed to take the next time step on the receiver | ||
* element is kept track of and a message is sent to the parallel runtime | ||
* system (e.g. Charm++) only when the receiver/neighbor element has all the | ||
* data it needs to take the next time step. This is done so as to reduce | ||
* pressure on the runtime system by sending fewer messages. | ||
*/ | ||
struct SendDataToElement { | ||
using return_type = void; | ||
|
||
template <typename ParallelComponent, typename DbTagList, size_t Dim, | ||
typename ReceiveTag, typename ReceiveData, typename Metavariables> | ||
static return_type apply( | ||
db::DataBox<DbTagList>& box, | ||
const gsl::not_null<Parallel::NodeLock*> /*node_lock*/, | ||
const gsl::not_null<Parallel::GlobalCache<Metavariables>*> cache, | ||
const ReceiveTag& /*meta*/, const ElementId<Dim>& element_to_execute_on, | ||
typename ReceiveTag::temporal_id instance, ReceiveData&& receive_data) { | ||
const size_t my_node = Parallel::my_node<size_t>(*cache); | ||
auto& element = db::get_mutable_reference< | ||
typename ParallelComponent::element_collection_tag>( | ||
make_not_null(&box)) | ||
.at(element_to_execute_on); | ||
// While we don't mutate the value, we want to avoid locking the DataBox | ||
// and the nodegroup by using `db::get_mutable_reference`. If/when we | ||
// start dynamically inserting and removing elements, we'll need to update | ||
// how we handle this. For example, we might need the containers to have | ||
// strong stability guarantees. | ||
const size_t node_of_element = | ||
db::get_mutable_reference<Parallel::Tags::ElementLocations<Dim>>( | ||
make_not_null(&box)) | ||
.at(element_to_execute_on); | ||
auto& my_proxy = | ||
Parallel::get_parallel_component<ParallelComponent>(*cache); | ||
if (node_of_element == my_node) { | ||
[[maybe_unused]] size_t count = 0; | ||
if constexpr (std::is_same_v<evolution::dg::AtomicInboxBoundaryData<Dim>, | ||
typename ReceiveTag::type>) { | ||
count = ReceiveTag::insert_into_inbox( | ||
make_not_null(&tuples::get<ReceiveTag>(element.inboxes())), | ||
instance, std::forward<ReceiveData>(receive_data)); | ||
} else { | ||
// Scope so that we minimize how long we lock the inbox. | ||
std::lock_guard inbox_lock(element.inbox_lock()); | ||
count = ReceiveTag::insert_into_inbox( | ||
make_not_null(&tuples::get<ReceiveTag>(element.inboxes())), | ||
instance, std::forward<ReceiveData>(receive_data)); | ||
} | ||
// A lower bound for the number of neighbors is | ||
// `2 * Dim - number_of_block_boundaries`, which doesn't give us the | ||
// exact minimum number of sends we need to do, but gets us close in most | ||
// cases. If we really wanted to we could also add the number of | ||
// directions that don't have external boundaries in our neighbors block. | ||
// if (count >= | ||
// (2 * Dim - element_to_execute_on.number_of_block_boundaries())) { | ||
Parallel::threaded_action<Parallel::Actions::ReceiveDataForElement<>>( | ||
my_proxy[node_of_element], element_to_execute_on); | ||
// } | ||
} else { | ||
Parallel::threaded_action<Parallel::Actions::ReceiveDataForElement<>>( | ||
my_proxy[node_of_element], ReceiveTag{}, element_to_execute_on, | ||
instance, std::forward<ReceiveData>(receive_data)); | ||
} | ||
} | ||
}; | ||
} // namespace Parallel::Actions |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did you mean to leave this if commented out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, because this is the bookkeeping code I talked with Will about to minimize communication. I want to get the rest in before I get the counting sorted out completely :)