Intel® oneAPI Threading Building Blocks
2422 Discussions

## Continuation Beginner
119 Views
Hello,
First of all I am new to tbb so excuse me if my question seems easy.
I have this process that I want to parallelize. Simply, I have a bunch of nodes that represent an odrinary differential equation (so the number of computations made by each node is important). Those node are interconnected and I want to solve all of them for each time step. I found a way to write the problem using a single loop if I can resend a finished computation in the ready pool.
Here is the idea I had:
1. Create a dummy parent
2. The dummy parent generates N children(I can not use the tree architecture for various reasons)
3. Spawning the tasks
4. Depending on a double condition (Have I reached the final time? && Am I too fast?), update the internal state of each child and send it back in the ready pool of the parent.
To do so, I used the following implementation:
NNODE = NNode;
AllResults=ResultIN;
root->NNODE = NNode;
root->AllResults = AllResults;
}
int count = 1;
for (int ii = 0; ii < NNODE; ii++) {
++count;
listT.push_back(
}
set_ref_count(count);
spawn_and_wait_for_all(listT);
return NULL;
}
return scalable_allocator ().allocate(1);
}
IND = idx;
sum = 0;
TF = 10;
T = 0;
}
bool OK = true;
//printf("IND:%d\\n",IND);
for (int ii=0;ii
{
if (ii!=IND)
OK=false;
}
if (OK) {
for (int ii = 0; ii < 10; ii++)
sum += 1;
printf(
"Node IND:%d\\t t:%d\\t tf:%d\\t sum:%d \\tNNODE:%d \\n",
IND, T, TF, sum, NNode);
T++;
if (T < TF)
recycle_as_child_of(*parent());
else
return NULL;
} else {
recycle_as_child_of(*parent());
}
return this;
}
#include "tbb/scalable_allocator.h"
#include "tbb/tick_count.h"
#include "tbb/concurrent_vector.h"
#include
#include
#include
#include
const bool tbbmalloc = true;
const bool stdmalloc = false;
using namespace tbb;
using namespace std;
typedef concurrent_vector > IntAVector;
public:
int NNODE;
IntAVector* AllResults;
};
public:
int IND;
int sum;
int TF;
int T;
};
#endif /* NETWORKCLASSTASK_HPP_ */
int main (){
int NNode=20;
IntAVector AllResults;
AllResults.reserve(NNode);
for (int ii=0;ii
AllResults[ii]=0;
my_root.execute();
return 0;
} 