Generic Collect Data

Header file: <libs/observers/generic_collect_data.hpp> [source]

template<typename Store, typename T>
struct XarrayAndViews

Struct to 1) manage collecting data into a view in host memory by copying data from the device execution space and 2) manage how to write this data to an Xarray for a variable in a dataset.

This struct manages an Xarray, a view in host memory and a mirror view in device memory in order to collect data for a variable from the execution space and write it to an Xarray in a dataset.

Template Parameters:
  • Store – The type of the data store in the Xarray.

  • T – The type of the data in the Xarray.

Public Types

using viewh_data = Buffer<T>::viewh_buffer

type of view for h_data

using mirrorviewd_data = Buffer<T>::mirrorviewd_buffer

mirror view type for d_data

Public Functions

inline XarrayAndViews(const XarrayZarrArray<Store, T> xzarr, const size_t dataview_size)

Constructs a new XarrayAndViews object.

Parameters:
  • xzarr – The Xarray with Zarr backend object.

  • dataview_size – The size of the views for collecting data.

Public Members

XarrayZarrArray<Store, T> xzarr

Xarray with Zarr backend to write h_data to

viewh_data h_data

view on host used to collect some data for the Xarray

mirrorviewd_data d_data

mirror view of h_data on device

template<typename Store, typename T, typename FunctorFunc>
class GenericCollectData

Generic class satisyfing the CollectDataForDataset concept to collect data for a variable and write it to an Xarray in a dataset.

This class provides a functor to collect data into a view in device memory for a single variable from superdroplets and/or gridboxes (to be used in a parallel range policy loop over gridboxes and/or superdroplets). It also provides functions to then write that collected data to an Xarray in a dataset.

Template Parameters:
  • Store – The type of the data store of the dataset.

  • T – The type of the data in the Xarray.

  • FunctorFunc – Type to act as a functor in a Kokkos parallel range policy loop for collecting data for a variable from gridbxoes and/or superdroplets

Public Functions

inline GenericCollectData(const FunctorFunc ffunc, const XarrayZarrArray<Store, T> xzarr, const size_t dataview_size)

Constructs a new GenericCollectData object.

The dataview_size should match the number of elements to collect when ffunc is called during a Kokkos::parallel_for loop which uses a range policy over gridboxes and/or superdroplets.

Parameters:
  • ffunc – Function-like object for the functor to collect data.

  • xzarr – The Xarray object in a dataset to write for a variable data to.

  • dataview_size – The size of the view to collect data (number of elements).

inline Functor get_functor(const viewd_constgbx d_gbxs, const viewd_constsupers totsupers) const

Returns the functor for collecting data.

Parameters:
  • d_gbxs – The view of gridboxes on device.

  • totsupers – The view of superdroplets on device.

Returns:

The functor object to use during a Kokkos:parallel_for range policy loop.

inline void reallocate_views(const size_t size) const

Reallocates the views with a new size.

The size of the view should match the number of elements to collect when ffunc is called during a Kokkos::parallel_for loop which uses a range policy over gridboxes and/or superdroplets.

Parameters:

size – The new size of the views on device and host.

inline void write_to_arrays(const Dataset<Store> &dataset) const

Deep copies data for an array from the device view to the host and then writes it to an array in the dataset.

Parameters:

dataset – The dataset to write data to.

inline void write_to_ragged_arrays(const Dataset<Store> &dataset) const

Deep copies data for a ragged array from the device view to the host and then writes it to a ragged array in the dataset.

Parameters:

dataset – The dataset to write data to.

inline void write_arrayshapes(const Dataset<Store> &dataset) const

Calls a function to write the shape of an array to the dataset.

Parameters:

dataset – The dataset to write array shape to.

inline void write_ragged_arrayshapes(const Dataset<Store> &dataset) const

Calls a function to write the shape of a ragged array to the dataset.

Parameters:

dataset – The dataset to write array shape to.

Private Members

FunctorFunc ffunc

functor to collect data into a view during a parallel range policy loop

std::shared_ptr<XarrayAndViews<Store, T>> ptr

pointer to xarray and views to collect data

struct Functor

Generic wrapper to use FunctorFunc type to collect data into a view in device memory during a Kokkos::parallel_for loop with a range policy.

Public Types

using mirrorviewd_data = XarrayAndViews<Store, T>::mirrorviewd_data

Public Functions

inline Functor(FunctorFunc ffunc, const viewd_constgbx d_gbxs, const viewd_constsupers totsupers, mirrorviewd_data d_data)
inline void operator()(const size_t nn) const

Adapter from signature of Kokkos::parallel_for with a range policy to call to FunctorFunc type for collecting data into d_data from gridboxes and/or superdroplets.

Parameters:

nn – The index of the data element.

Public Members

FunctorFunc ffunc

functor to collect data into d_data during parallel loop

viewd_constgbx d_gbxs

view of gridboxes on device

viewd_constsupers totsupers

view of superdroplets on device

mirrorviewd_data d_data

mirror view on device for data to collect