1 #include <tjutils/tjthread.h>
2 #include <tjutils/tjlog.h>
5 template<
typename In,
typename Out,
typename Local>
12 ODINLOG(odinlog,normalDebug) <<
"catched process signal, cont=" << tloop->cont << STD_endl;
13 if(!tloop->cont)
break;
15 ODINLOG(odinlog,normalDebug) <<
"processing thread " << begin <<
"/" << end << STD_endl;
17 status=tloop->kernel(*tloop->in_cache, *out_cache, local, begin, end);
19 ODINLOG(odinlog,normalDebug) <<
"signaling finished=" << status << STD_endl;
29 template<
typename In,
typename Out,
typename Local>
36 ODINLOG(odinlog,normalDebug) <<
"numof_threads=" << numof_threads << STD_endl;
38 threads.resize(numof_threads-1);
39 unsigned int onesize=loopsize/numof_threads;
40 unsigned int rest=loopsize%numof_threads;
42 for(
unsigned int i=0; i<(numof_threads-1); i++) {
43 threads[i]=
new WorkThread(
this);
44 threads[i]->begin=count;
47 threads[i]->end=count;
52 if((numof_threads-1)<rest) count++;
59 template<
typename In,
typename Out,
typename Local>
64 for(
unsigned int i=0; i<threads.size(); i++) {
65 threads[i]->process.signal();
73 template<
typename In,
typename Out,
typename Local>
78 return kernel(in, outvec[0], mainlocal, mainbegin, mainend);
81 unsigned int nthreads=threads.size();
83 outvec.resize(nthreads+1);
89 for(
unsigned int i=0; i<nthreads; i++) {
90 threads[i]->out_cache=&(outvec[i]);
91 threads[i]->status=
true;
92 threads[i]->process.signal();
96 bool result=kernel(in, outvec[nthreads], mainlocal, mainbegin, mainend);
99 for(
unsigned int i=0; i<nthreads; i++) {
100 threads[i]->finished.wait();
101 threads[i]->finished.reset();
102 if(!threads[i]->status) result=
false;
104 ODINLOG(odinlog,normalDebug) <<
"finished.wait() done" << STD_endl;
bool execute(const In &in, STD_vector< Out > &outvec)
bool init(unsigned int numof_threads, unsigned int loopsize)