- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Through push_back API of concurrent vector container, I tried to push_back around (10000000) my custom objects, my sample application is a single threaded application.
I tested push_back API, through two tbb versions , first one is old tbb (version libtbb2.4.2~20130725) & second one is new oneapi tbb (version oneapi-tbb-2021.5.0-lin.tgz).
Through oneapi tbb (oneapi-tbb-2021.5.0-lin.tgz)),Time taken by push_back API in pushing 10000000 custom objects is approximately twice than time taken by push_back API of old tbb (libtbb2.4.2~20130725).
I am using Ubuntu 20.04.5 version on my desktop PC. As per my view, time taken by latest oneapi tbb APIs should be less than (or equal) to the time taken by old tbb APIs.
Pls suggest.
Regards,
Pritam
Link Copied
- « Previous
-
- 1
- 2
- Next »
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
My last answer was not correct. The concurrent_vector is not contiguous, like a std::vector, but it does keep track of the index internally. And because it does that, its operator- is implemented in constant time, not O(n).
So, you can compute (it - v.begin()) in constant time, which would be equal to the index
#include <iostream>
#include <oneapi/tbb.h>
int main(int argc, char** argv){
tbb::concurrent_vector<int> conc_vec;
tbb::concurrent_vector<int>::iterator it;
int index_of_pushed_element;
int size = 10;
tbb::parallel_for(5, size, 1, [&](int i){
it = conc_vec.push_back(i);
index_of_pushed_element = (it - conc_vec.begin());
std::cout << "index_of_pushed_element = " << index_of_pushed_element << "\n";
});
for(int i = 0; i < conc_vec.size(); i++)
printf(" %d", conc_vec[i]);
printf("\n");
}
produces:
icpx tbb_concurrent_v.cpp -tbb
./a.out
index_of_pushed_element = 0
index_of_pushed_element = 1
index_of_pushed_element = 2
index_of_pushed_element = 3
index_of_pushed_element = 4
5 6 7 8 9
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Please let us know if last post answered your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Has the information provided above helped? If yes, could you please confirm whether we can close this thread from our end?
Thanks and Regards,
Pendyala Sesha Srinivas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
We have not heard back from you. I assume that your issue is resolved. If you need any additional information, please post a new question -- ideally in a new thread -- this thread will no longer be monitored by Intel.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- « Previous
-
- 1
- 2
- Next »