7 #include "fastCommBuffer.h" 11 faster::worker::worker(fastComm * c,
void ** ft, std::vector< std::tuple<void*, size_t, int> > & globalTable){
16 fddList.reserve(1024);
17 this->globalTable = &globalTable;
20 faster::worker::~worker(){
24 void faster::worker::discardFDD(
unsigned long int id){
29 void faster::worker::setFDDData(
unsigned long int id,
void * data,
size_t size){
30 workerFddBase * fdd = fddList[id];
32 if (fdd == NULL) { std::cerr <<
"\nERROR: Could not find FDD!"; exit(201); }
34 fdd->setDataRaw( data, size );
36 void faster::worker::setFDDIData(
unsigned long int id,
void * keys,
void * data,
size_t size){
37 workerFddBase * fdd = fddList[id];
39 if (fdd == NULL) { std::cerr <<
"\nERROR: Could not find FDD!"; exit(201); }
41 fdd->setDataRaw( keys, data, size );
44 void faster::worker::setFDDData(
unsigned long int id,
void * data,
size_t * lineSizes,
size_t size){
45 workerFddBase * fdd = fddList[id];
47 if (fdd == NULL) { std::cerr <<
"\nERROR: Could not find FDD!"; exit(201); }
49 fdd->setDataRaw( data, lineSizes, size );
52 void faster::worker::setFDDIData(
unsigned long int id,
void * keys,
void * data,
size_t * lineSizes,
size_t size){
53 workerFddBase * fdd = fddList[id];
55 if (fdd == NULL) { std::cerr <<
"\nERROR: Could not find FDD!"; exit(201); }
57 fdd->setDataRaw( keys, data, lineSizes, size );
70 void faster::worker::calibrate(){
71 using std::chrono::system_clock;
72 using std::chrono::duration_cast;
73 using std::chrono::milliseconds;
75 fastCommBuffer &buffer = comm->getResultBuffer();
76 const int TESTVECSIZE = 1000000;
82 auto start = system_clock::now();
83 auto end = system_clock::now();
87 std::vector<double> v(TESTVECSIZE, 0);
92 start = system_clock::now();
96 #pragma omp for schedule(static,100) 97 for (
size_t i = 0; i < 4000000; ++i){
98 for (
size_t j = 1; j < 5; ++j){
104 a += v[ size_t( i * 20011 ) % TESTVECSIZE ];
105 v [ size_t( i * 4099 ) % TESTVECSIZE ] = a;
109 end = system_clock::now();
111 auto duration = duration_cast<milliseconds>(end - start);
113 buffer << size_t(duration.count());
114 buffer << getProcStat();
118 comm->sendTaskResult();
121 void faster::worker::writeFDDFile(
unsigned long int id, std::string &path, std::string &sufix){
122 using std::chrono::system_clock;
123 using std::chrono::duration_cast;
124 using std::chrono::milliseconds;
127 fastCommBuffer &buffer = comm->getResultBuffer();
128 workerFddBase * src = fddList[id];
133 auto start = system_clock::now();
134 auto end = system_clock::now();
136 src->writeToFile(&path, comm->getProcId(), &sufix);
138 auto duration = duration_cast<milliseconds>(end - start);
140 buffer << size_t(duration.count());
141 buffer << getProcStat();
145 comm->sendTaskResult();
148 void resizeVector(std::tuple<void *, size_t, int> & var UNUSED){
151 void faster::worker::updateGlobals(fastTask &task){
152 for (
size_t i = 0; i < task.globals.size(); i++){
153 int type = std::get<2>(task.globals[i]);
154 size_t s = std::get<1>(task.globals[i]);
157 resizeVector((*globalTable)[i]);
160 char ** v = (
char **) std::get<0>((*globalTable)[i]);
165 std::get<0>(task.globals[i]),
170 std::get<0>((*globalTable)[i]),
171 std::get<0>(task.globals[i]),
176 delete [] (
char*) std::get<0>(task.globals[i]);
180 void faster::worker::solve(fastTask &task){
183 if (task.operationType == OP_Calibrate){
188 workerFddBase * src = fddList[task.srcFDD];
189 workerFddBase * dest = NULL;
191 if (src == NULL) { std::cerr <<
"\nERROR: Could not find FDD " << task.srcFDD <<
" !"; exit(201); }
193 if ( task.operationType & OP_GENERICMAP)
194 dest = fddList[task.destFDD];
196 if ( task.functionId != -1 )
197 src->preapply(task.id, funcTable[task.functionId], task.operationType, dest, comm);
199 src->preapply(task.id, NULL, task.operationType, dest, comm);
202 void faster::worker::collect(
unsigned long int id){
203 workerFddBase * fdd = fddList[id];
205 if (fdd == NULL) { std::cerr <<
"\nERROR: Could not find FDD " <<
id <<
" !"; exit(202); }