1 #ifndef LIBFASTER_FASTCONTEXT_H
2 #define LIBFASTER_FASTCONTEXT_H
13 #include "definitions.h"
16 #include "fastScheduler.h"
18 using std::chrono::system_clock;
25 template <
typename K,
typename T>
37 _allowDataBalancing =
false;
43 void allowDataBalancing(){
44 _allowDataBalancing =
true;
48 bool _allowDataBalancing;
56 template <
class T>
friend class fdd;
57 template <
class T>
friend class fddCore;
58 template <
class K,
class T>
friend class iFddCore;
59 template <
class K,
class T>
friend class indexedFdd;
68 void registerFunction(
void * funcP);
69 void registerFunction(
void * funcP,
const std::string name);
71 void registerGlobal(T * varP);
83 unsigned long int numFDDs;
86 std::vector< fddBase * > fddList;
87 std::vector<void*> funcTable;
88 std::vector<std::string> funcName;
89 std::vector< std::pair<void*, size_t> > globalTable;
95 int findFunc(
void * funcP);
97 unsigned long int _createFDD(
fddBase * ref, fddType type,
const std::vector<size_t> * dataAlloc);
98 unsigned long int _createIFDD(
fddBase * ref, fddType kTypeCode, fddType tTypeCode,
const std::vector<size_t> * dataAlloc);
99 unsigned long int createFDD(
fddBase * ref,
size_t typeCode);
100 unsigned long int createFDD(
fddBase * ref,
size_t typeCode,
const std::vector<size_t> & dataAlloc);
101 unsigned long int createPFDD(
fddBase * ref,
size_t typeCode);
102 unsigned long int createPFDD(
fddBase * ref,
size_t typeCode,
const std::vector<size_t> & dataAlloc);
103 unsigned long int createIFDD(
fddBase * ref,
size_t kTypeCode,
size_t tTypeCode);
104 unsigned long int createIFDD(
fddBase * ref,
size_t kTypeCode,
size_t tTypeCode,
const std::vector<size_t> & dataAlloc);
105 unsigned long int createIPFDD(
fddBase * ref,
size_t kTypeCode,
size_t tTypeCode);
106 unsigned long int createIPFDD(
fddBase * ref,
size_t kTypeCode,
size_t tTypeCode,
const std::vector<size_t> & dataAlloc);
107 unsigned long int createFddGroup(
fddBase * ref, std::vector<fddBase*> & fdds);
109 unsigned long int readFDD(
fddBase * ref,
const char * fileName);
110 void getFDDInfo(
size_t & size, std::vector<size_t> & dataAlloc);
112 int numProcs(){
return comm->numProcs; }
115 unsigned long int enqueueTask(fddOpType opT,
unsigned long int idSrc,
unsigned long int idRes,
int funcId,
size_t size);
116 unsigned long int enqueueTask(fddOpType opT,
unsigned long int id,
size_t size);
119 std::vector< std::pair<void *, size_t> > recvTaskResult(
unsigned long int &tid,
unsigned long int &sid, system_clock::time_point & start);
121 template <
typename K>
122 void sendKeyMap(
unsigned long id, std::unordered_map<K, int> & keyMap);
123 template <
typename K>
124 void sendCogroupData(
unsigned long id, std::unordered_map<K, int> & keyMap, std::vector<bool> & flags);
127 template <
typename Z,
typename FDD>
128 void collectFDD(Z & ret, FDD * fddP){
131 comm->sendCollect(fddP->getId());
134 comm->recvFDDDataCollect(ret);
142 template <
typename T>
143 void parallelize(
unsigned long int id, T * data,
size_t size){
147 for (
int i = 1; i < comm->numProcs; ++i){
148 int dataPerProc = size/(comm->numProcs - 1);
149 int rem = size % (comm->numProcs -1);
154 comm->sendFDDSetData(
id, i, &data[offset], dataPerProc);
155 offset += dataPerProc;
158 comm->waitForReq(comm->numProcs - 1);
161 template <
typename K,
typename T>
162 void parallelizeI(
unsigned long int id, K * keys, T * data,
size_t size){
166 for (
int i = 1; i < comm->numProcs; ++i){
167 int dataPerProc = size/(comm->numProcs - 1);
168 int rem = size % (comm->numProcs -1);
173 comm->sendFDDSetIData(
id, i, &keys[offset], &data[offset], dataPerProc);
174 offset += dataPerProc;
177 comm->waitForReq(comm->numProcs - 1);
182 template <
typename T>
183 void parallelize(
unsigned long int id, T ** data,
size_t * dataSizes,
size_t size){
187 for (
int i = 1; i < comm->numProcs; ++i){
188 int dataPerProc = size/ (comm->numProcs - 1);
189 int rem = size % (comm->numProcs -1);
194 comm->sendFDDSetData(
id, i, &data[offset], &dataSizes[offset], dataPerProc);
195 offset += dataPerProc;
198 comm->waitForReq(comm->numProcs - 1);
201 template <
typename K,
typename T>
202 void parallelizeI(
unsigned long int id, K * keys, T ** data,
size_t * dataSizes,
size_t size){
206 for (
int i = 1; i < comm->numProcs; ++i){
207 int dataPerProc = size/ (comm->numProcs - 1);
208 int rem = size % (comm->numProcs -1);
213 comm->sendFDDSetIData(
id, i, &keys[offset], &data[offset], &dataSizes[offset], dataPerProc);
214 offset += dataPerProc;
217 comm->waitForReq(comm->numProcs - 1);
222 std::vector<size_t> getAllocation(
size_t size);
224 void discardFDD(
unsigned long int id);
229 void fastContext::registerGlobal(T * varP){
230 std::pair<void*, size_t> globalReg ;
231 globalReg.first = varP;
232 globalReg.second =
sizeof(T);
233 globalTable.insert( globalTable.end(), globalReg );
236 template <
typename K>
237 void fastContext::sendKeyMap(
unsigned long tid, std::unordered_map<K, int> & keyMap){
238 comm->sendKeyMap(tid, keyMap);
240 template <
typename K>
241 void fastContext::sendCogroupData(
unsigned long tid, std::unordered_map<K, int> & keyMap, std::vector<bool> &flags){
242 comm->sendCogroupData(tid, keyMap, flags);
Definition: fastComm.h:116
Definition: fastContext.h:26
Definition: fastContext.h:54
Definition: groupedFdd.h:13
Definition: fastScheduler.h:14
Definition: groupedFdd.h:55
Definition: fastContext.h:23
Definition: _workerFdd.h:11
Definition: fastTask.h:11
Definition: fastContext.h:32