-
Notifications
You must be signed in to change notification settings - Fork 1
/
laik_vector_comm_overlapping_overlapping.cc
146 lines (113 loc) · 4.93 KB
/
laik_vector_comm_overlapping_overlapping.cc
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
#include"laik_vector_comm_overlapping_overlapping.h"
#include <laik_partitioners.h>
#include <lulesh.h>
#include <limits.h>
#include <type_traits>
#include <string.h>
// ///////////////////////////////////////////////////////////
// implementation of laik_vector with overlapping partitioning
// (node partitioning)
// ///////////////////////////////////////////////////////////
template <typename T>
laik_vector_comm_overlapping_overlapping<T>::laik_vector_comm_overlapping_overlapping(Laik_Instance *inst,
Laik_Group*world,
Laik_Space* indexSpace,
Laik_Partitioning *p1, Laik_Partitioning *p2,
Laik_Transition* t1, Laik_Transition* t2,
Laik_ReductionOperation operation):laik_vector<T>(inst,world, indexSpace, p1, p2, t1,t2, operation){}
template <typename T>
void laik_vector_comm_overlapping_overlapping<T>::resize(int count){
this->size = count;
if (std::is_same <T, double>::value) {
this->data = laik_new_data(this->indexSpace, laik_Double );
}
else if (std::is_same <T, int>::value){
this->data = laik_new_data(this->indexSpace, laik_Int64 );
}
// use the reservation API to precalculate the pointers
Laik_Reservation* reservation = laik_reservation_new(this->data);
laik_reservation_add(reservation, this->p1);
laik_reservation_alloc(reservation);
laik_data_use_reservation(this->data, reservation);
// precalculate the transition object
this->as1 = laik_calc_actions(this->data, this->t1, reservation, reservation);
this->as2 = laik_calc_actions(this->data, this->t2, reservation, reservation);
// go through the slices to just allocate the memory
laik_switchto_partitioning(this->data, this->p1, LAIK_DF_None, this->reduction_operation );
Laik_TaskRange* tr = laik_my_range(this->p1, 0);
const Laik_Range* r = laik_taskrange_get_range(tr);
this -> count = laik_range_size(r);
this -> state = 0;
this -> precalculate_base_pointers();
}
/*
double& laik_vector_comm_overlapping_overlapping::operator [](int idx){
return *(this -> overlapping_pointers[idx]);
}
*/
template <typename T>
T* laik_vector_comm_overlapping_overlapping<T>::calc_pointer(int idx){
uint64_t cnt;
T* base;
int i = (idx % (this->count*this->count) ) % this->count;
int l_idx = i;
int slice = idx/this->count;
laik_get_map_1d(this->data, slice, (void **)&base, &cnt);
return base+l_idx;
}
template <typename T>
void laik_vector_comm_overlapping_overlapping<T>::precalculate_base_pointers(){
if (this->pointer_cache != nullptr) free (this->pointer_cache);
this->pointer_cache = (T**) malloc (this->size * sizeof(T*));
for (int i = 0; i < this->size; ++i) {
this->pointer_cache [i] = calc_pointer(i);
}
}
template <typename T>
void laik_vector_comm_overlapping_overlapping<T>::switch_to_p1(){
laik_exec_actions(this->as1);
//laik_exec_transition(data,t1);
//laik_switchto_phase(data, p1, Laik_DataFlow
// ( LAIK_DF_ReduceOut | LAIK_DF_Sum ) );
}
template <typename T>
void laik_vector_comm_overlapping_overlapping<T>::switch_to_p2(){
laik_exec_actions(this->as2);
//laik_exec_transition(data,t2);
//laik_switchto_phase(data, p1, LAIK_DF_CopyIn);
}
template <typename T>
void laik_vector_comm_overlapping_overlapping<T>::migrate(Laik_Group* new_group, Laik_Partitioning* p_new_1, Laik_Partitioning* p_new_2, Laik_Transition* t_new_1, Laik_Transition* t_new_2){
uint64_t cnt;
int* base;
//int slice = 0;
laik_switchto_partitioning(this->data, this->p1, LAIK_DF_None, LAIK_RO_Min);
Laik_Reservation* reservation = laik_reservation_new(this->data);
laik_reservation_add(reservation, p_new_1);
laik_reservation_alloc(reservation);
laik_data_use_reservation(this->data, reservation);
laik_switchto_partitioning(this->data, p_new_1, LAIK_DF_Preserve, LAIK_RO_Min);
if (laik_myid(new_group)< 0) {
return;
}
this->as1 = laik_calc_actions(this->data, t_new_1, reservation, reservation);
this->as2 = laik_calc_actions(this->data, t_new_2, reservation, reservation);
this -> p1=p_new_1;
this -> p2=p_new_2;
this -> t1=t_new_1;
this -> t2=t_new_2;
this -> world = new_group;
if (laik_myid(this->world)<0)
return ;
laik_switchto_partitioning(this->data, this->p1, LAIK_DF_None, LAIK_RO_Min );
int nRanges = laik_my_rangecount(this->p1);
for (int n = 0; n < nRanges; n++)
{
laik_get_map_1d(this->data, n, (void **)&base, &cnt);
}
laik_switchto_partitioning(this->data, this->p2, LAIK_DF_Preserve, LAIK_RO_Min);
this -> count = cnt;
this -> state = 0;
this -> precalculate_base_pointers();
}
template class laik_vector_comm_overlapping_overlapping<double>;