ttg 1.0.0
Template Task Graph (TTG): flowgraph-based programming model for high-performance distributed-memory algorithms
Loading...
Searching...
No Matches
parsec_data.h
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-3-Clause
2#ifndef TTG_PARSEC_PARSEC_DATA_H
3#define TTG_PARSEC_PARSEC_DATA_H
4
5#include "ttg/parsec/buffer.h"
6#include "ttg/buffer.h"
7
8namespace ttg_parsec::detail {
9 template<typename Value, typename Fn>
10 void foreach_parsec_data(Value&& value, Fn&& fn) {
11 /* protect for non-serializable types, allowed if the TT has no device op */
12 if constexpr (ttg::detail::has_buffer_apply_v<Value>) {
13 ttg::detail::buffer_apply(value, [&]<typename B>(B&& b){
14 parsec_data_t *data = detail::get_parsec_data(b);
15 if (nullptr != data) {
16 fn(data);
17 }
18 });
19 }
20 }
21
27 inline std::tuple<int, parsec_data_copy_t*> find_device_copy(parsec_data_t* data) {
28 parsec_atomic_lock(&data->lock);
29 int version = data->device_copies[0]->version; // default to host
30 int device = 0;
31 parsec_data_copy_t* device_copy = nullptr;
32 for (int i = 1; i < parsec_nb_devices; ++i) {
33 if (data->device_copies[i] == nullptr) continue;
34 if (data->device_copies[i]->version >= version) {
35 device = i;
36 version = data->device_copies[i]->version;
37 device_copy = data->device_copies[i];
38 }
39 }
40 if (device != 0) {
41 /* add a reader to the device copy */
42 parsec_atomic_fetch_add_int32(&device_copy->readers, 1);
43 }
44 parsec_atomic_unlock(&data->lock);
45 return {device, device_copy};
46 }
47} // namespace ttg_parsec::detail
48
49#endif // TTG_PARSEC_PARSEC_DATA_H
void buffer_apply(T &&t, Fn &&fn)
Definition buffer.h:152
std::tuple< int, parsec_data_copy_t * > find_device_copy(parsec_data_t *data)
Definition parsec_data.h:27
void foreach_parsec_data(Value &&value, Fn &&fn)
Definition parsec_data.h:10
parsec_data_t * get_parsec_data(const ttg_parsec::Buffer< T, A > &db)
Definition buffer.h:638
N.B. contains values of F_n and F_{n-1}.
Definition fibonacci.cc:6