3 #include <unordered_map> 4 #include <unordered_map> 8 #include "workerFddModule.h" 10 using std::chrono::system_clock;
11 using std::chrono::duration_cast;
12 using std::chrono::milliseconds;
14 void * faster::workerFdd::dLHandler[3][7] = {};
17 std::unordered_map<faster::fddType, int> faster::workerFdd::khAssign = std::unordered_map<fddType, int> ({
18 {0,0},{Char,1}, {Int,2}, {LongInt,3}, {Float,4}, {Double,5},{String,6}
21 std::unordered_map<faster::fddType, int> faster::workerFdd::hAssign = std::unordered_map<fddType, int>({
22 {Char,0}, {Int,0}, {LongInt,0}, {Float,0}, {Double,0},
23 {CharP,1},{IntP,1},{LongIntP,1},{FloatP,1},{DoubleP,1},{Custom,1},
24 {CharV,2},{IntV,2},{LongIntV,2},{FloatV,2},{DoubleV,2},{String,2},
27 std::unordered_map<char, void *> faster::workerFdd::funcTable[3][7];
30 void * faster::workerFdd::load(
const std::string libraryName){
34 void * hdlr = dlopen(libraryName.data(), RTLD_LAZY);
38 std::cerr <<
"\n\033[5m\033[91mERROR! \033[0m\033[38;5;202m"<< dlerror() <<
"\033[0m " << std::endl;
46 void faster::workerFdd::loadSym(dFuncName funcName,
const std::string symbolName){
47 void * symbl = dlsym(dLHandler[hAssign[type]][khAssign[keyType]], symbolName.data());
50 std::cerr <<
"\n\033[5m\033[91mERROR! \033[0m\033[38;5;202m"<< dlerror() <<
"\033[0m " << std::endl;
53 funcTable[hAssign[type]] [khAssign[keyType]] [funcName] = symbl;
56 void faster::workerFdd::loadLib(){
57 if ( dLHandler[hAssign[type]][0] )
61 dLHandler[hAssign[type]][0] = load(
"libfaster/libfasterWorkerPFdd.so");
63 if (type & (VECTOR | String))
64 dLHandler[hAssign[type]][0] = load(
"libfaster/libfasterWorkerCFdd.so");
66 dLHandler[hAssign[type]][0] = load(
"libfaster/libfasterWorkerSFdd.so");
71 void faster::workerFdd::loadLibI(){
72 if ( dLHandler[hAssign[type]][khAssign[keyType]] )
78 case Char: dLHandler[hAssign[type]][khAssign[keyType]] = load(
"libfaster/libfasterWorkerIPFddInstance0.so");
break;
79 case Int: dLHandler[hAssign[type]][khAssign[keyType]] = load(
"libfaster/libfasterWorkerIPFddInstance1.so");
break;
80 case LongInt: dLHandler[hAssign[type]][khAssign[keyType]] = load(
"libfaster/libfasterWorkerIPFddInstance2.so");
break;
81 case Float: dLHandler[hAssign[type]][khAssign[keyType]] = load(
"libfaster/libfasterWorkerIPFddInstance3.so");
break;
82 case Double: dLHandler[hAssign[type]][khAssign[keyType]] = load(
"libfaster/libfasterWorkerIPFddInstance4.so");
break;
83 case String: dLHandler[hAssign[type]][khAssign[keyType]] = load(
"libfaster/libfasterWorkerIPFddInstance5.so");
break;
86 if (type & (VECTOR | String))
88 case Char: dLHandler[hAssign[type]][khAssign[keyType]] = load(
"libfaster/libfasterWorkerIFddInstance6.so");
break;
89 case Int: dLHandler[hAssign[type]][khAssign[keyType]] = load(
"libfaster/libfasterWorkerIFddInstance7.so");
break;
90 case LongInt: dLHandler[hAssign[type]][khAssign[keyType]] = load(
"libfaster/libfasterWorkerIFddInstance8.so");
break;
91 case Float: dLHandler[hAssign[type]][khAssign[keyType]] = load(
"libfaster/libfasterWorkerIFddInstance9.so");
break;
92 case Double: dLHandler[hAssign[type]][khAssign[keyType]] = load(
"libfaster/libfasterWorkerIFddInstance10.so");
break;
93 case String: dLHandler[hAssign[type]][khAssign[keyType]] = load(
"libfaster/libfasterWorkerIFddInstance11.so");
break;
97 case Char: dLHandler[hAssign[type]][khAssign[keyType]] = load(
"libfaster/libfasterWorkerIFddInstance0.so");
break;
98 case Int: dLHandler[hAssign[type]][khAssign[keyType]] = load(
"libfaster/libfasterWorkerIFddInstance1.so");
break;
99 case LongInt: dLHandler[hAssign[type]][khAssign[keyType]] = load(
"libfaster/libfasterWorkerIFddInstance2.so");
break;
100 case Float: dLHandler[hAssign[type]][khAssign[keyType]] = load(
"libfaster/libfasterWorkerIFddInstance3.so");
break;
101 case Double: dLHandler[hAssign[type]][khAssign[keyType]] = load(
"libfaster/libfasterWorkerIFddInstance4.so");
break;
102 case String: dLHandler[hAssign[type]][khAssign[keyType]] = load(
"libfaster/libfasterWorkerIFddInstance5.so");
break;
109 void faster::workerFdd::loadSymbols(){
111 if (funcTable[hAssign[type]] [khAssign[keyType]] .size() != 0)
117 loadSym(NewWorkerSDL ,
"newWorkerSDL");
118 loadSym(DiscardWorkerDL ,
"discardWorkerDL");
120 loadSym(GetTypeDL ,
"getTypeDL");
121 loadSym(GetKeyTypeDL ,
"getKeyTypeDL");
124 loadSym(SetDataDL ,
"setDataDL");
125 loadSym(SetDataRawDL ,
"setDataRawDL");
128 loadSym(GetLineSizesDL ,
"getLineSizesDL");
130 loadSym(GetFddItemDL ,
"getFddItemDL");
131 loadSym(GetKeysDL ,
"getKeysDL");
132 loadSym(GetDataDL ,
"getDataDL");
133 loadSym(GetSizeDL ,
"getSizeDL");
134 loadSym(ItemSizeDL ,
"itemSizeDL");
135 loadSym(BaseSizeDL ,
"baseSizeDL");
136 loadSym(SetSizeDL ,
"setSizeDL");
138 loadSym(DeleteItemDL ,
"deleteItemDL");
139 loadSym(ShrinkDL ,
"shrinkDL");
143 loadSym(InsertDL ,
"insertDL");
144 loadSym(InsertListDL ,
"insertListDL");
146 loadSym(PreapplyDL ,
"preapplyDL");
148 loadSym(CollectDL ,
"collectDL");
149 loadSym(ExchangeDataByKeyDL,
"exchangeDataByKeyDL");
150 loadSym(GetKeyLocationDL,
"getKeyLocationsDL");
151 loadSym(GetUKeysDL ,
"getUKeysDL");
152 loadSym(SetUKeysDL ,
"setUKeysDL");
153 loadSym(GetKeyMapDL ,
"getKeyMapDL");
154 loadSym(SetKeyMapDL ,
"setKeyMapDL");
155 loadSym(WriteToFileDL ,
"writeToFileDL");
162 faster::workerFdd::workerFdd(
fddType t){
168 faster::workerFdd::workerFdd(
unsigned long int id,
fddType t,
size_t size) : workerFdd(t){
170 void * funcP = funcTable[hAssign[t]] [0] [NewWorkerSDL];
171 _fdd = ((workerFddBase * (*)(
unsigned long int,
fddType, size_t)) funcP)(
id, t, size);
173 faster::workerFdd::workerFdd(
unsigned long int id, fddType t) : workerFdd(id, t, size_t(0)){
178 faster::workerFdd::workerFdd(fddType kt, fddType t){
184 faster::workerFdd::workerFdd(
unsigned long int id, fddType kt, fddType t,
size_t size) : workerFdd(kt, t){
186 void * funcP = funcTable[hAssign[t]] [khAssign[kt]] [NewWorkerSDL];
187 _fdd = ((workerFddBase * (*)(
unsigned long int,
fddType, size_t)) funcP)(
id, t, size);
189 faster::workerFdd::workerFdd(
unsigned long int id, fddType kt, fddType t) : workerFdd(id, kt, t, 0){
193 faster::workerFdd::~workerFdd(){
194 void * funcP = funcTable[hAssign[type]] [khAssign[keyType]] [DiscardWorkerDL];
195 ((void (*) (workerFddBase *)) funcP)(_fdd);
200 void * funcP = funcTable[hAssign[type]] [khAssign[keyType]] [GetTypeDL];
201 return ((fddType (*)(workerFddBase *)) funcP)(_fdd);
205 void * funcP = funcTable[hAssign[type]] [khAssign[keyType]] [GetKeyTypeDL];
206 return ((fddType (*)(workerFddBase *)) funcP)(_fdd);
211 void * faster::workerFdd::getItem(
size_t address){
212 void * funcP = funcTable[hAssign[type]] [khAssign[keyType]] [GetFddItemDL];
213 return ((
void * (*)(workerFddBase *,
size_t)) funcP)(_fdd, address);
216 void * faster::workerFdd::getKeys(){
217 void * funcP = funcTable[hAssign[type]] [khAssign[keyType]] [GetKeysDL];
218 return ((
void * (*)(workerFddBase * fdd)) funcP)(_fdd);
221 void * faster::workerFdd::getData(){
222 void * funcP = funcTable[hAssign[type]] [khAssign[keyType]] [GetDataDL];
223 return ((
void * (*)(workerFddBase * fdd)) funcP)(_fdd);
226 size_t faster::workerFdd::getSize(){
227 void * funcP = funcTable[hAssign[type]] [khAssign[keyType]] [GetSizeDL];
228 return ((
size_t (*)(workerFddBase *)) funcP)(_fdd);
231 size_t faster::workerFdd::itemSize(){
232 void * funcP = funcTable[hAssign[type]] [khAssign[keyType]] [ItemSizeDL];
233 return ((
size_t (*)(workerFddBase *)) funcP)(_fdd);
236 size_t faster::workerFdd::baseSize(){
237 void * funcP = funcTable[hAssign[type]] [khAssign[keyType]] [BaseSizeDL];
238 return ((
size_t (*)(workerFddBase *)) funcP)(_fdd);
241 void faster::workerFdd::setSize(
size_t s){
242 void * funcP = funcTable[hAssign[type]] [khAssign[keyType]] [SetSizeDL];
243 return ((
void (*)(workerFddBase *,
size_t s)) funcP)(_fdd, s);
247 void faster::workerFdd::deleteItem(
void * item){
248 void * funcP = funcTable[hAssign[type]] [khAssign[keyType]] [DeleteItemDL];
249 ((void (*)(workerFddBase *,
void*)) funcP)(_fdd, item);
252 void faster::workerFdd::shrink(){
253 void * funcP = funcTable[hAssign[type]] [khAssign[keyType]] [ShrinkDL];
254 ((void (*)(workerFddBase *)) funcP)(_fdd);
258 void faster::workerFdd::setData(
void * data,
size_t size) {
259 void * funcP = funcTable[hAssign[type]] [khAssign[keyType]] [SetDataDL];
260 ((void (*)(workerFddBase *,
void*,
void*,
size_t*, size_t)) funcP)(_fdd, NULL, data, NULL, size);
263 void faster::workerFdd::setData(
void * data,
size_t * lineSizes,
size_t size) {
264 void * funcP = funcTable[hAssign[type]] [khAssign[keyType]] [SetDataDL];
265 ((void (*)(workerFddBase *,
void*,
void*,
size_t*, size_t)) funcP)(_fdd, NULL, data, lineSizes, size);
267 void faster::workerFdd::setData(
void * keys,
void * data,
size_t size) {
268 void * funcP = funcTable[hAssign[type]] [khAssign[keyType]] [SetDataDL];
269 ((void (*)(workerFddBase *,
void*,
void*,
size_t*, size_t)) funcP)(_fdd, keys, data, NULL, size);
272 void faster::workerFdd::setData(
void * keys,
void * data,
size_t * lineSizes,
size_t size) {
273 void * funcP = funcTable[hAssign[type]] [khAssign[keyType]] [SetDataDL];
274 ((void (*)(workerFddBase *,
void*,
void*,
size_t*, size_t)) funcP)(_fdd, keys, data, lineSizes, size);
279 void faster::workerFdd::setDataRaw(
void * data,
size_t size){
280 void * funcP = funcTable[hAssign[type]] [khAssign[keyType]] [SetDataRawDL];
281 ((void (*)(workerFddBase*,
void*,
void*,
size_t*, size_t)) funcP)(_fdd, NULL, data, NULL, size);
284 void faster::workerFdd::setDataRaw(
void * data,
size_t *lineSizes,
size_t size){
285 void * funcP = funcTable[hAssign[type]] [khAssign[keyType]] [SetDataRawDL];
286 ((void (*)(workerFddBase*,
void*,
void*,
size_t*, size_t)) funcP)(_fdd, NULL, data, lineSizes, size);
288 void faster::workerFdd::setDataRaw(
void * keys,
void * data,
size_t size){
289 void * funcP = funcTable[hAssign[type]] [khAssign[keyType]] [SetDataRawDL];
290 ((void (*)(workerFddBase*,
void*,
void*,
size_t*, size_t)) funcP)(_fdd, keys, data, NULL, size);
293 void faster::workerFdd::setDataRaw(
void * keys,
void * data,
size_t *lineSizes,
size_t size){
294 void * funcP = funcTable[hAssign[type]] [khAssign[keyType]] [SetDataRawDL];
295 ((void (*)(workerFddBase*,
void*,
void*,
size_t*, size_t)) funcP)(_fdd, keys, data, lineSizes, size);
299 size_t * faster::workerFdd::getLineSizes(){
300 void * funcP = funcTable[hAssign[type]] [khAssign[keyType]] [GetLineSizesDL];
301 return ((
size_t * (*)(workerFddBase *)) funcP)(_fdd);
306 void faster::workerFdd::insert(
void * k,
void * v,
size_t s){
307 void * funcP = funcTable[hAssign[type]] [khAssign[keyType]] [InsertDL];
308 ((void (*)(workerFddBase *,
void *,
void *, size_t)) funcP)(_fdd, k, v, s);
311 void faster::workerFdd::insertl(
void * v){
312 void * funcP = funcTable[hAssign[type]] [khAssign[keyType]] [InsertListDL];
313 ((void (*)(workerFddBase *,
void *)) funcP)(_fdd, v);
319 void faster::workerFdd::preapply(
unsigned long int id,
void * func,
fddOpType op, workerFddBase * dest, fastComm * comm){
320 void * funcP = funcTable[hAssign[type]] [khAssign[keyType]] [PreapplyDL];
321 ((void (*)(workerFddBase*,
unsigned long int id,
void*,
fddOpType, workerFddBase*, fastComm *)) funcP)(_fdd,
id, func, op, dest, comm);
325 void faster::workerFdd::collect(fastComm * comm){
326 void * funcP = funcTable[hAssign[type]] [khAssign[keyType]] [CollectDL];
327 ((void (*)(workerFddBase *, fastComm *)) funcP)(_fdd, comm);
329 void faster::workerFdd::exchangeDataByKey(fastComm *comm){
330 void * funcP = funcTable[hAssign[type]] [khAssign[keyType]] [ExchangeDataByKeyDL];
331 ((void (*)(workerFddBase *, fastComm *)) funcP)(_fdd, comm);
333 std::vector< std::vector<void*> > * faster::workerFdd::getKeyLocations() {
334 void * funcP = funcTable[hAssign[type]] [khAssign[keyType]] [GetKeyLocationDL];
335 return (std::vector< std::vector<void*> > *) ((
void * (*) (workerFddBase *)) funcP)(_fdd);
338 void * faster::workerFdd::getUKeys() {
339 void * funcP = funcTable[hAssign[type]] [khAssign[keyType]] [GetUKeysDL];
340 return ((
void * (*) (workerFddBase *)) funcP)(_fdd);
342 void faster::workerFdd::setUKeys(
void * uk) {
343 void * funcP = funcTable[hAssign[type]] [khAssign[keyType]] [SetUKeysDL];
344 (( void (*) (workerFddBase *,
void*)) funcP)(_fdd, uk);
346 void * faster::workerFdd::getKeyMap() {
347 void * funcP = funcTable[hAssign[type]] [khAssign[keyType]] [GetKeyMapDL];
348 return ((
void * (*) (workerFddBase *)) funcP)(_fdd);
350 void faster::workerFdd::setKeyMap(
void * km) {
351 void * funcP = funcTable[hAssign[type]] [khAssign[keyType]] [SetKeyMapDL];
352 (( void (*) (workerFddBase *,
void*)) funcP)(_fdd, km);
355 void faster::workerFdd::writeToFile(
void * path,
size_t procId,
void * sufix){
356 void * funcP = funcTable[hAssign[type]] [khAssign[keyType]] [WriteToFileDL];
357 (( void (*) (workerFddBase *,
void*,
size_t procId,
void*)) funcP)(_fdd, path, procId, sufix);
unsigned int fddOpType
Dataset operation type.
unsigned int fddType
Dataset type.