- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi ,
Here is a serial implementation of a simple example describing the task at hand :
const int numIter = 1e8;
std::vector<double> Vector(1000,0);
for(int i = 0 ; i < numIter ; i++ )
{
const int randomIndex = 1 + rand() % 1000;
Vector[randomIndex] += i*3.14;
}
I'm new to TBB, and i would appreciate some help with how to parallelize this code for best performances.
Thanks
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Thanks for reaching out to us.
You can use construct in TBB to parallelize the code. Such as parallel_for,parallel_reduce, etc..
Please refer to the below link for more details:
https://oneapi-src.github.io/oneTBB/main/tbb_userguide/parallel_for_os.html
You can also refer to the ProTBB Textbook for more details.
Please refer to the below parallel code using oneTBB.
#include<iostream>
#include<vector>
#include <tbb/parallel_for.h>
int main()
{
const int numIter = 1e8;
std::vector<double> Vector(1000, 0);
tbb::parallel_for(tbb::blocked_range<int>(0, numIter),
[&](tbb::blocked_range<int> r)
{
for (int i = r.begin(); i < r.end(); ++i)
{
const int randomIndex = 1 + rand() % 1000;
Vector[randomIndex] += i * 3.14;
}
});
return 0;
}
Thanks & Regards,
Noorjahan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
We haven't heard back from you. Could you please provide an update on your issue?
Thanks & Regards,
Noorjahan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I have not heard back from you, so I will close this inquiry now. If you need further assistance, please post a new question.
Thanks & Regards,
Noorjahan.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page