-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdomain_map_impl_v0.hpp
170 lines (138 loc) · 3.63 KB
/
domain_map_impl_v0.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include <hpx/lcos/future.hpp>
#include <vector>
#include <map>
#include <utility>
namespace hpx {
namespace partition {
namespace details{
template<typename T>
struct co_domain
{
};
template<>
struct co_domain<unsigned int>
{
public:
std::vector<unsigned int> indexes;
std::size_t size;
explicit co_domain() : indexes(0), size(0) {}
void add(const unsigned int& index)
{
indexes.emplace_back(index);
size++;
}
};
// partitioned_domain should be container
template<typename T>
struct partitioned_domain
{
};
template<>
struct partitioned_domain<co_domain<unsigned int> >
{
public:
typedef co_domain<unsigned int> value_type;
partitioned_domain()
{}
private:
std::vector<value_type> collection;
std::size_t size;
}
}
}
}
namespace hpx{
namespace partition {
template <typename T>
struct partition
{
};
template<>
struct partition<domain<unsigned int> >
{
typedef domain<unsigned int> domain_type;
partition()
{
static_assert(false,"partition should be called with domain");
}
partition(const domain<unsigned int>& domain )
:
ref_domain(domain)
{}
// map function should map the indexes of domain to co_domain
// map function will replaced by the EDSL
template <typename mapper>
partitioned_domain operator() (std::size_t buckets, mapper&& map) const
{
ref_domain.expand();
partitioned_domain values.reserve(buckets);
std::size_t limit(ref_domain.size());
std::size_t co_domain_index;
std::size_t check(0);
for(std::size_t i = 0;i < limit; i++)
{
check = map(ref_domain.range[i]);
HPX_ASSERT_MSG(check < buckets,"Map function will not map to invalid buckets");
co_domain_index = check;
values[co_domain_index].add(i);
}
return values;
}
private:
domain_type ref_domain;
};
}}
namespace hpx{
namespace domain_map{
struct domain_map
{
public:
domain_map()
{
HPX_ASSERT_MSG(false,"Domain_map should be initialized with partitioned_domain");
}
domain_map(const partitioned_domain& imp, hpx::id_type loc_ = hpx::find_here()) :
ref_partitioned_domain(imp),
localities_(loc_) {}
domain_map(const partitioned_domain& imp, hpx::id_type loc1, hpx::id_type loc2)
:
ref_partitioned_domain(imp),
localities_(loc1)
{
localities_.emplace_back(loc2);
}
domain_map(const partitioned_domain& imp, std::vector<hpx::id_type> loc_)
:
ref_partitioned_domain(imp),
localities_(loc_)
{}
hpx::future<void> construct_locality_map()
{
std::size_t index(0);
for(auto &id : localities_)
{
locality_map.emplace(std::make_pair(index,id));
index++;
}
}
// Mapper will be replaced by the EDSL as in partition
template<typename Mapper>
auto operator() (Mapper&& map)
{
std::size_t limit = ref_partitioned_domain.size();
std::size_t check(0);
hpx::id_type target_loc;
for(std::size_t i = 0;i < limit; i++)
{
check = map(i);
loc_ = locality_map[check];
domain_map.emplace(std::)
}
}
private:
partitioned_domain ref_partitioned_domain;
std::vector<hpx::id_type> localities_;
std::map<int,hpx::id_type> locality_map;
}
}
}