View on GitHub

Vistle

Distributed Data-parallel Scientific Visualization in VR

shm_impl.h
Go to the documentation of this file.
1#ifndef SHM_IMPL_H
2#define SHM_IMPL_H
3
4#include <boost/type_traits.hpp>
5#include <boost/mpl/find.hpp>
6#include <boost/mpl/size.hpp>
7#include <boost/mpl/push_back.hpp>
8#include <iostream>
9#include <cassert>
10
11#include "scalars.h"
12#include "celltreenode.h"
13#include "shm_array.h"
14
15#include "archives_config.h"
16
17namespace vistle {
18
19typedef boost::mpl::push_back<Scalars, CelltreeNode<sizeof(Index), 1>>::type VectorTypes1;
20typedef boost::mpl::push_back<VectorTypes1, CelltreeNode<sizeof(Index), 2>>::type VectorTypes2;
21typedef boost::mpl::push_back<VectorTypes2, CelltreeNode<sizeof(Index), 3>>::type VectorTypes;
22
23template<typename T, class allocator>
25{
26 const size_t pos = boost::mpl::find<VectorTypes, T>::type::pos::value;
27 static_assert(pos < boost::mpl::size<VectorTypes>::value, "Scalar type not found");
28 return pos;
29}
30
31template<typename T>
32const ShmVector<T> Shm::getArrayFromName(const std::string &name) const
33{
35
36 if (name.empty()) {
38 }
39
41
42 if (!arr) {
44 }
45 assert(arr->shmtype == ShmData::ARRAY);
46 if (array::typeId() != arr->type()) {
47 arr->unref();
49 }
50
51 auto ref = vistle::shm_array_ref<array>(name, arr);
52 arr->unref();
53 return ref;
54}
55
56template<class Archive>
57void shm_name_t::save(Archive &ar) const
58{
59 std::string n(name.data());
60 //std::cerr << "SHM_NAME_T save: '" << n << "'" << std::endl;
61 ar &V_NAME(ar, "shm_name_t", n);
62}
63
64template<class Archive>
65void shm_name_t::load(Archive &ar)
66{
67 std::string n;
68 ar &V_NAME(ar, "shm_name_t", n);
69 auto end = n.find('\0');
70 if (end != std::string::npos) {
71 n = n.substr(0, end);
72 }
73 if (n.size() < name.size()) {
74 std::copy(n.begin(), n.end(), name.data());
75 name[n.size()] = '\0';
76 } else {
77 std::cerr << "shm_name_t: name too long: " << n << " (" << n.size() << " chars)" << std::endl;
78 memset(name.data(), 0, name.size());
79 assert(n.size() < name.size());
80 }
81 //std::cerr << "SHM_NAME_T load: '" << name.data() << "'" << std::endl;
82}
83
84#ifdef NO_SHMEM
85#else
86template<typename T>
87typename managed_shm::segment_manager::template construct_proxy<T>::type shm<T>::construct(const std::string &name)
88{
89 return Shm::the().shm().construct<T>(name.c_str());
90}
91#endif
92
93} // namespace vistle
94
95#endif
#define V_NAME(ar, name, obj)
Definition: archives_config.h:441
friend struct shm
Definition: shm.h:131
static Shm & the()
Definition: shm.cpp:315
const ShmVector< T > getArrayFromName(const std::string &name) const
Definition: shm_impl.h:32
std::string name() const
Definition: shm.cpp:300
Definition: shm_reference.h:15
Definition: shm_array.h:19
static int typeId()
Definition: shm_impl.h:24
Definition: allobjects.cpp:30
boost::mpl::push_back< VectorTypes1, CelltreeNode< sizeof(Index), 2 > >::type VectorTypes2
Definition: shm_impl.h:20
boost::mpl::vector< char, signed char, unsigned char, int32_t, uint32_t, int64_t, uint64_t, float, double > Scalars
Definition: scalars.h:14
boost::mpl::push_back< Scalars, CelltreeNode< sizeof(Index), 1 > >::type VectorTypes1
Definition: shm_impl.h:19
boost::mpl::push_back< VectorTypes2, CelltreeNode< sizeof(Index), 3 > >::type VectorTypes
Definition: shm_impl.h:21
uint32_t Index
Definition: index.h:13
Definition: celltree.h:20
@ ARRAY
Definition: shmdata.h:16
void load(Archive &ar)
Definition: shm_impl.h:65
std::array< char, 32 > name
Definition: shmname.h:12
ARCHIVE_ACCESS_SPLIT void save(Archive &ar) const
static T * find_and_ref(const std::string &name)
Definition: shm.h:255
static managed_shm::segment_manager::template construct_proxy< T >::type construct(const std::string &name)
Definition: shm_impl.h:87