SpECTRE  v2024.09.29
Parallel::GlobalCache< Metavariables > Class Template Reference

A Charm++ chare that caches global data once per Charm++ node. More...

#include <GlobalCache.hpp>

Public Types

using proxy_type = CProxy_GlobalCache< Metavariables >
 
using main_proxy_type = CProxy_Main< Metavariables >
 
using metavariables = Metavariables
 Access to the Metavariables template parameter.
 
using component_list = typename Metavariables::component_list
 Typelist of the ParallelComponents stored in the GlobalCache.
 
using chare_type = Parallel::Algorithms::Nodegroup
 
using const_tags_list = get_const_global_cache_tags< Metavariables >
 
using ConstTagsTuple = tuples::tagged_tuple_from_typelist< const_tags_list >
 
using ConstTagsStorage = ConstTagsTuple
 
using mutable_tags_list = get_mutable_global_cache_tags< Metavariables >
 
using MutableTagsTuple = tuples::tagged_tuple_from_typelist< mutable_tags_list >
 
using MutableTagsStorage = tuples::tagged_tuple_from_typelist< get_mutable_global_cache_tag_storage< Metavariables > >
 

Public Member Functions

 GlobalCache (ConstTagsTuple const_global_cache, MutableTagsTuple mutable_global_cache={}, std::vector< size_t > procs_per_node={1}, const int my_proc=0, const int my_node=0, const int my_local_rank=0)
 Constructor meant to be used in the ActionTesting framework.
 
 GlobalCache (ConstTagsTuple const_global_cache, MutableTagsTuple mutable_global_cache, std::optional< main_proxy_type > main_proxy)
 Constructor meant to be used in charm-aware settings (with a Main proxy).
 
 GlobalCache (CkMigrateMessage *msg)
 
void set_parallel_components (ParallelComponentTuple &&parallel_components, const CkCallback &callback)
 Entry method to set the ParallelComponents (should only be called once)
 
template<typename GlobalCacheTag , typename Function >
bool mutable_cache_item_is_ready (const Parallel::ArrayComponentId &array_component_id, const Function &function)
 Returns whether the object referred to by GlobalCacheTag (which must be a mutable cache tag) is ready to be accessed by a get call. More...
 
template<typename GlobalCacheTag , typename Function , typename... Args>
void mutate (const std::tuple< Args... > &args)
 Mutates the non-const object identified by GlobalCacheTag. More...
 
void compute_size_for_memory_monitor (const double time)
 Entry method that computes the size of the local branch of the GlobalCache and sends it to the MemoryMonitor parallel component. More...
 
void set_resource_info (const Parallel::ResourceInfo< Metavariables > &resource_info)
 Entry method that will set the value of the Parallel::Tags::ResourceInfo tag to the value passed in (if the tag exists in the GlobalCache) More...
 
const Parallel::ResourceInfo< Metavariables > & get_resource_info () const
 Retrieve the resource_info.
 
proxy_type get_this_proxy ()
 Retrieve the proxy to the global cache.
 
void pup (PUP::er &p) override
 
std::optional< main_proxy_type > get_main_proxy ()
 Retrieve the proxy to the Main chare (or std::nullopt if the proxy has not been set, i.e. we are not charm-aware).
 
int number_of_procs () const
 Wrappers for charm++ informational functions. More...
 
int number_of_nodes () const
 Number of nodes.
 
int procs_on_node (const int node_index) const
 Number of processing elements on the given node.
 
int first_proc_on_node (const int node_index) const
 Index of first processing element on the given node.
 
int node_of (const int proc_index) const
 Index of the node for the given processing element.
 
int local_rank_of (const int proc_index) const
 The local index for the given processing element on its node.
 
int my_proc () const
 Index of my processing element.
 
int my_node () const
 Index of my node.
 
int my_local_rank () const
 The local index of my processing element on my node. This is in the interval 0, ..., procs_on_node(my_node()) - 1.
 

Static Public Attributes

static constexpr bool is_mocked = GlobalCache_detail::mock_global_cache
 

Friends

template<typename GlobalCacheTag , typename MV >
auto get (const GlobalCache< MV > &cache) -> const GlobalCache_detail::type_for_get< GlobalCacheTag, MV > &
 
template<typename ParallelComponentTag , typename MV >
auto get_parallel_component (GlobalCache< MV > &cache) -> Parallel::proxy_from_parallel_component< GlobalCache_detail::get_component_if_mocked< typename MV::component_list, ParallelComponentTag > > &
 
template<typename ParallelComponentTag , typename MV >
auto get_parallel_component (const GlobalCache< MV > &cache) -> const Parallel::proxy_from_parallel_component< GlobalCache_detail::get_component_if_mocked< typename MV::component_list, ParallelComponentTag > > &
 

Detailed Description

template<typename Metavariables>
class Parallel::GlobalCache< Metavariables >

A Charm++ chare that caches global data once per Charm++ node.

Details

There are two types of global data that are stored; const data and mutable data. Once the GlobalCache is created, const data cannot be edited but mutable data can be edited using Parallel::mutate.

The template parameter Metavariables must define the following type aliases:

  • component_list typelist of ParallelComponents
  • const_global_cache_tags (possibly empty) typelist of tags of constant data
  • mutable_global_cache_tags (possibly empty) typelist of tags of non-constant data

The tag lists for the const items added to the GlobalCache is created by combining the following tag lists:

  • Metavariables::const_global_cache_tags which should contain only those tags that cannot be added from the other tag lists below.
  • Component::const_global_cache_tags for each Component in Metavariables::component_list which should contain the tags needed by any simple actions called on the Component, as well as tags need by the allocate_array function of an array component. The type alias may be omitted for an empty list.
  • Action::const_global_cache_tags for each Action in the phase_dependent_action_list of each Component of Metavariables::component_list which should contain the tags needed by that Action. The type alias may be omitted for an empty list.

The tag lists for the mutable items added to the GlobalCache is created by combining exactly the same tag lists as for the const items, except with const_global_cache_tags replaced by mutable_global_cache_tags.

The tags in the const_global_cache_tags and mutable_global_cache_tags type lists are db::SimpleTags that have a using option_tags type alias and a static function create_from_options that are used to create the constant data (or initial mutable data) from input file options.

References to const items in the GlobalCache are also added to the db::DataBox of each Component in the Metavariables::component_list with the same tag with which they were inserted into the GlobalCache. References to mutable items in the GlobalCache are not added to the db::DataBox.

Since mutable data is stored once per Charm++ node, we require that data structures held by mutable tags have some sort of thread-safety. Particularly, we require data structures in mutable tags be Single Producer-Multiple Consumer. This means that the data structure should be readable/accessible by multiple threads at once, even while being mutated (multiple consumer), but will not be edited/mutated simultaneously on multiple threads (single producer).

Member Function Documentation

◆ compute_size_for_memory_monitor()

template<typename Metavariables >
void Parallel::GlobalCache< Metavariables >::compute_size_for_memory_monitor ( const double  time)

Entry method that computes the size of the local branch of the GlobalCache and sends it to the MemoryMonitor parallel component.

Note
This can only be called if the MemoryMonitor component is in the component_list of the metavariables. Also can't be called in the testing framework. Trying to do either of these will result in an ERROR.

◆ mutable_cache_item_is_ready()

template<typename Metavariables >
template<typename GlobalCacheTag , typename Function >
bool Parallel::GlobalCache< Metavariables >::mutable_cache_item_is_ready ( const Parallel::ArrayComponentId array_component_id,
const Function &  function 
)

Returns whether the object referred to by GlobalCacheTag (which must be a mutable cache tag) is ready to be accessed by a get call.

Details

function is a user-defined invokable that:

  • takes one argument: a const reference to the object referred to by the GlobalCacheTag.
  • if the data is ready, returns a default constructed std::unique_ptr<CallBack>
  • if the data is not ready, returns a std::unique_ptr<CallBack>, where the Callback will re-invoke the current action on the current parallel component. This callback should be a Parallel::PerformAlgorithmCallback. Other types of callbacks are not supported at this time.
Warning
The function may be called twice so it should not modify any state in its scope.
Warning
If there has already been a callback registered for the given array_component_id, then the callback returned by function will not be registered or called.

◆ mutate()

template<typename Metavariables >
template<typename GlobalCacheTag , typename Function , typename... Args>
void Parallel::GlobalCache< Metavariables >::mutate ( const std::tuple< Args... > &  args)

Mutates the non-const object identified by GlobalCacheTag.

Requires: GlobalCacheTag is a tag in mutable_global_cache_tags defined by the Metavariables and in Actions.

Internally calls Function::apply(), where Function is a user-defined struct and Function::apply() is a user-defined static function that mutates the object. Function::apply() takes as its first argument a gsl::not_null pointer to the object named by the GlobalCacheTag (or if that object is a std::unique_ptr<T>, a gsl::not_null<T*>), and takes the contents of args as subsequent arguments.

◆ number_of_procs()

template<typename Metavariables >
int Parallel::GlobalCache< Metavariables >::number_of_procs

Wrappers for charm++ informational functions.

Number of processing elements

◆ set_resource_info()

template<typename Metavariables >
void Parallel::GlobalCache< Metavariables >::set_resource_info ( const Parallel::ResourceInfo< Metavariables > &  resource_info)

Entry method that will set the value of the Parallel::Tags::ResourceInfo tag to the value passed in (if the tag exists in the GlobalCache)

This is only meant to be called once.


The documentation for this class was generated from the following file: