how to implement intel's tbb::blocked_range2d in C++
- by Hristo
I'm trying to parallelize nested for loops with parellel_for() and the blocked_range2d from Intel's TBB using C++. The for loops look like this:
for(int i = 0; i < N; ++i) {
for(int j = 0; j < E[i]; ++j) {
for(int k = 0; k < T; ++k) {
score[k] += delta(i, trRating[k][i], exRating[j][i]);
}
}
}
... and I am trying to do the following:
class LoopBody {
private:
int *myscore;
public:
LoopBody(int *score) {
myscore = score;
}
void operator()(const blocked_range2d<int> &r) const {
for(int i = r.rows().begin(); i != r.rows().end(); ++i);
for(int j = 0; j < E[i]; ++j) {
for(int k = r.cols().begin(); k != r.cols().end(); ++k) {
myscore[k] += foo(...); // uses i,j,k to look up indices in arrays
}
}
}
}
};
void computeScores(int score[]) {
parallel_for(blocked_range2d<int>(0, N, 0, T), LoopBody(score));
}
... but I am getting the following compile errors:
error: identifier "i" is undefined
for(int j = 0; j < E[i]; ++j) {
^
error: expected an identifier
};
^
I'm not really sure if I am doing this the right way, but any advice is appreciated. Also, this is my first time using Intel's TBB so I really don't know anything about it. Any ideas how make this work?
Thanks,
Hristo