libfaster API Documentation  Development Version
Super fast distributted computing
workerIPFdd.cpp
1 #include <tuple>
2 #include <iostream>
3 
4 #include "_workerIFdd.h"
5 #include "indexedFddStorageExtern.cpp"
6 #include "fastComm.h"
7 
8 // -------------------------- worker<K,T*> specialization -------------------------- //
9 
10 // REDUCE
11 template <typename K, typename T>
12 std::tuple<K,T*,size_t> faster::_workerIFdd<K,T*>::reduce (IPreduceIPFunctionP<K,T> reduceFunc){
13  T ** d = this->localData->getData();
14  std::tuple<K,T*,size_t> resultT;
15  size_t s = this->localData->getSize();
16  size_t * ils = this->localData->getLineSizes();
17  K * ik = this->localData->getKeys();
18  //std::cerr << "START " << id << " " << s << " | ";
19 
20  #pragma omp parallel
21  {
22  int nT = omp_get_num_threads();
23  int tN = omp_get_thread_num();
24  std::tuple<K,T*,size_t> partResult (ik[tN], d[tN], ils[tN]);
25  T * b, * a;
26  size_t aSize, bSize;
27  K aKey, bKey;
28 
29  #pragma omp for
30  for (int i = nT; i < s; ++i){
31  aKey = std::get<0>(partResult);
32  a = std::get<1>(partResult);
33  aSize = std::get<2>(partResult);
34  b = d[i];
35  bKey = ik[i];
36  bSize = ils[i];
37 
38  partResult = reduceFunc( aKey, a, aSize, bKey, b, bSize );
39 
40  delete [] a;
41  delete [] b;
42  }
43  #pragma omp master
44  resultT = partResult;
45 
46  #pragma omp barrier
47 
48  #pragma omp critical
49  if (omp_get_thread_num() != 0){
50  aKey = std::get<0>(resultT);
51  a = std::get<1>(resultT);
52  aSize = std::get<2>(resultT);
53 
54  bKey = std::get<0>(partResult);
55  b = std::get<1>(partResult);
56  bSize = std::get<2>(partResult);
57 
58  resultT = reduceFunc(aKey, a, aSize, bKey, b, bSize);
59 
60  delete [] a;
61  delete [] b;
62  }
63  }
64  //std::cerr << "END ";
65  return resultT;
66 }
67 
68 template <typename K, typename T>
69 std::tuple<K,T*,size_t> faster::_workerIFdd<K,T*>::bulkReduce (IPbulkReduceIPFunctionP<K,T> bulkReduceFunc){
70  K * ik = this->localData->getKeys();
71  return bulkReduceFunc(ik, this->localData->getData(), this->localData->getLineSizes(), this->localData->getSize());
72 }
73 
74 
75 template <typename K, typename T>
76 void faster::_workerIFdd<K,T*>::applyIndependent(void * func, fddOpType op, fastCommBuffer & buffer){
77  std::tuple<K,T*,size_t> r;
78 
79  switch (op){
80  case OP_Reduce:
81  r = reduce(( IPreduceIPFunctionP<K,T> ) func);
82  //std::cerr << "Reduce " ;
83  break;
84  case OP_BulkReduce:
85  r = bulkReduce(( IPbulkReduceIPFunctionP<K,T> ) func);
86  //std::cerr << "BulkReduce ";
87  break;
88  }
89 
90  buffer << r;
91 }
92 
93 
94 // -------------------------- Public Functions ------------------------ //
95 
96 
97 
98 template <typename K, typename T>
99 void faster::_workerIFdd<K,T*>::setData(K * keys, T ** data, size_t *lineSizes, size_t size){
100  this->localData->setData(keys, data, lineSizes, size);
101 }
102 
103 
104 template <typename K, typename T>
105 void faster::_workerIFdd<K,T*>::setDataRaw(void * keys, void * data, size_t *lineSizes, size_t size) {
106  this->localData->setDataRaw(keys, data, lineSizes, size);
107 }
108 
109 template <typename K, typename T>
111  return this->localData->getLineSizes();
112 }
113 
114 
115 template <typename K, typename T>
116 void faster::_workerIFdd<K,T*>::insert(void * k, void * in, size_t s){
117  this->localData->insert(*(K *) k, (T*&) in, s);
118 }
119 template <typename K, typename T>
120 void faster::_workerIFdd<K,T*>::insertl(void * in){
121  insert( *(std::deque<std::tuple<K,T*, size_t>>*) in);
122 }
123 
124 
125 
126 
127 template <typename K, typename T>
128 void faster::_workerIFdd<K,T*>::insert(K & key, T* & in, size_t s){
129  this->localData->insert(key, in, s);
130 }
131 
132 template <typename K, typename T>
133 void faster::_workerIFdd<K,T*>::insert(std::deque< std::tuple<K, T*, size_t> > & in){
134  typename std::deque< std::tuple<K, T*, size_t> >::iterator it;
135 
136  if (this->localData->getSize() < in.size())
137  this->localData->grow(in.size());
138 
139  for ( it = in.begin(); it != in.end(); it++)
140  this->localData->insert(std::get<0>(*it), std::get<1>(*it), std::get<2>(*it));
141 }
142 
143 
144 template <typename K, typename T>
145 void faster::_workerIFdd<K,T*>::apply(void * func, fddOpType op, workerFddBase * dest, fastCommBuffer & buffer){
146  if (op & OP_GENERICMAP)
147  applyDependent(func, op, dest);
148  else
149  applyIndependent(func, op, buffer);
150 }
151 
152 
153 
154 template <typename K, typename T>
155 void faster::_workerIFdd<K,T*>::collect(fastComm * comm) {
156  comm->sendFDDDataCollect(this->id, this->localData->getKeys(), this->localData->getData(), this->localData->getLineSizes(), this->localData->getSize());
157 };
158 
159 
160 /*
161 extern template class faster::_workerIFdd<char, char>;
162 extern template class faster::_workerIFdd<char, int>;
163 extern template class faster::_workerIFdd<char, long int>;
164 extern template class faster::_workerIFdd<char, float>;
165 extern template class faster::_workerIFdd<char, double>;
166 template class faster::_workerIFdd<char, char*>;
167 template class faster::_workerIFdd<char, int*>;
168 template class faster::_workerIFdd<char, long int*>;
169 template class faster::_workerIFdd<char, float*>;
170 template class faster::_workerIFdd<char, double*>;
171 extern template class faster::_workerIFdd<char, std::string>;
172 extern template class faster::_workerIFdd<char, std::vector<char>>;
173 extern template class faster::_workerIFdd<char, std::vector<int>>;
174 extern template class faster::_workerIFdd<char, std::vector<long int>>;
175 extern template class faster::_workerIFdd<char, std::vector<float>>;
176 extern template class faster::_workerIFdd<char, std::vector<double>>;
177 
178 extern template class faster::_workerIFdd<int, char>;
179 extern template class faster::_workerIFdd<int, int>;
180 extern template class faster::_workerIFdd<int, long int>;
181 extern template class faster::_workerIFdd<int, float>;
182 extern template class faster::_workerIFdd<int, double>;
183 template class faster::_workerIFdd<int, char*>;
184 template class faster::_workerIFdd<int, int*>;
185 template class faster::_workerIFdd<int, long int*>;
186 template class faster::_workerIFdd<int, float*>;
187 template class faster::_workerIFdd<int, double*>;
188 extern template class faster::_workerIFdd<int, std::string>;
189 extern template class faster::_workerIFdd<int, std::vector<char>>;
190 extern template class faster::_workerIFdd<int, std::vector<int>>;
191 extern template class faster::_workerIFdd<int, std::vector<long int>>;
192 extern template class faster::_workerIFdd<int, std::vector<float>>;
193 extern template class faster::_workerIFdd<int, std::vector<double>>;
194 
195 extern template class faster::_workerIFdd<long int, char>;
196 extern template class faster::_workerIFdd<long int, int>;
197 extern template class faster::_workerIFdd<long int, long int>;
198 extern template class faster::_workerIFdd<long int, float>;
199 extern template class faster::_workerIFdd<long int, double>;
200 template class faster::_workerIFdd<long int, char*>;
201 template class faster::_workerIFdd<long int, int*>;
202 template class faster::_workerIFdd<long int, long int*>;
203 template class faster::_workerIFdd<long int, float*>;
204 template class faster::_workerIFdd<long int, double*>;
205 extern template class faster::_workerIFdd<long int, std::string>;
206 extern template class faster::_workerIFdd<long, std::vector<char>>;
207 extern template class faster::_workerIFdd<long, std::vector<int>>;
208 extern template class faster::_workerIFdd<long, std::vector<long int>>;
209 extern template class faster::_workerIFdd<long, std::vector<float>>;
210 extern template class faster::_workerIFdd<long, std::vector<double>>;
211 
212 extern template class faster::_workerIFdd<float, char>;
213 extern template class faster::_workerIFdd<float, int>;
214 extern template class faster::_workerIFdd<float, long int>;
215 extern template class faster::_workerIFdd<float, float>;
216 extern template class faster::_workerIFdd<float, double>;
217 template class faster::_workerIFdd<float, char*>;
218 template class faster::_workerIFdd<float, int*>;
219 template class faster::_workerIFdd<float, long int*>;
220 template class faster::_workerIFdd<float, float*>;
221 template class faster::_workerIFdd<float, double*>;
222 extern template class faster::_workerIFdd<float, std::string>;
223 extern template class faster::_workerIFdd<float, std::vector<char>>;
224 extern template class faster::_workerIFdd<float, std::vector<int>>;
225 extern template class faster::_workerIFdd<float, std::vector<long int>>;
226 extern template class faster::_workerIFdd<float, std::vector<float>>;
227 extern template class faster::_workerIFdd<float, std::vector<double>>;
228 
229 extern template class faster::_workerIFdd<double, char>;
230 extern template class faster::_workerIFdd<double, int>;
231 extern template class faster::_workerIFdd<double, long int>;
232 extern template class faster::_workerIFdd<double, float>;
233 extern template class faster::_workerIFdd<double, double>;
234 template class faster::_workerIFdd<double, char*>;
235 template class faster::_workerIFdd<double, int*>;
236 template class faster::_workerIFdd<double, long int*>;
237 template class faster::_workerIFdd<double, float*>;
238 template class faster::_workerIFdd<double, double*>;
239 extern template class faster::_workerIFdd<double, std::string>;
240 extern template class faster::_workerIFdd<double, std::vector<char>>;
241 extern template class faster::_workerIFdd<double, std::vector<int>>;
242 extern template class faster::_workerIFdd<double, std::vector<long int>>;
243 extern template class faster::_workerIFdd<double, std::vector<float>>;
244 extern template class faster::_workerIFdd<double, std::vector<double>>;
245 
246 extern template class faster::_workerIFdd<std::string, char>;
247 extern template class faster::_workerIFdd<std::string, int>;
248 extern template class faster::_workerIFdd<std::string, long int>;
249 extern template class faster::_workerIFdd<std::string, float>;
250 extern template class faster::_workerIFdd<std::string, double>;
251 template class faster::_workerIFdd<std::string, char*>;
252 template class faster::_workerIFdd<std::string, int*>;
253 template class faster::_workerIFdd<std::string, long int*>;
254 template class faster::_workerIFdd<std::string, float*>;
255 template class faster::_workerIFdd<std::string, double*>;
256 extern template class faster::_workerIFdd<std::string, std::string>;
257 extern template class faster::_workerIFdd<std::string, std::vector<char>>;
258 extern template class faster::_workerIFdd<std::string, std::vector<int>>;
259 extern template class faster::_workerIFdd<std::string, std::vector<long int>>;
260 extern template class faster::_workerIFdd<std::string, std::vector<float>>;
261 extern template class faster::_workerIFdd<std::string, std::vector<double>>;
262 */
unsigned int fddOpType
Dataset operation type.
Definition: definitions.h:41