- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello peoples!
So basically I have a int vector called primes:
[bash]vectorprimes;[/bash]
It is filled up with parallely generated primes. Now, I need to sort them. I tried using parallel_sort, but it screwed up. I've tried using pointers, iterators, pointers to iterators, etc.
Can anyone help?
Thanks!
Link Copied
6 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Last time I checked, "parallely" was not a word. :-)
As for the programming issue, please ask a real question with usable information (and preferably without assigning blame to others).
(Added after #4) Smiley, parentheses.
As for the programming issue, please ask a real question with usable information (and preferably without assigning blame to others).
(Added after #4) Smiley, parentheses.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oops, double post. Use the post after this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oops.
Well, here's what I've tried:
[bash]vector::iterator b = primes.begin(), e = primes.end(); parallel_sort(b,e); ============== parallel_sort(primes.begin(), primes.end()); ============== // I know this doesn't work parallel_sort(primes.front(), primes.back()); ============== // I know this doesn't work vector ::iterator b = primes.begin(), e = primes.end(); int *be = &(*b), *en = &(*e); parallel_sort(*be,*en); ============== vector ::iterator b = primes.begin(), e = primes.end(); parallel_sort(*b,*e);
==============
// Parallel qsort fail
parallel_for(0, 3, [=](int z) { qsort((void *)(primes.front() + z * ((primes.size())/4)), (primes.size())/4, sizeof(int), compare); }); parallel_for(0, 1, [=](int y) { qsort((void *)(primes.front() + y * ((primes.size())/2)), (primes.size())/2, sizeof(int), compare); }); qsort((void *)primes.front(), primes.size(), sizeof(int), compare); [/bash]
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What does "fail" mean: doesn't compile/link, wrong outcome, ...? Does anything change if you use tbb::parallel_sort instead of the parallel_sort by itself? front() and back() wouldn't work, nor would *begin() and *last(). I think I'll skip the parallel_for ones... Does "compare" provide "<" to qsort() or did you want something else? Have you tried the example in the Reference, and what happened?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You should be able to use tbb::parallel_sort just like std::sort as long as the operations on the type are thread-safe. Here's a transcript of a complete example on Linux.
[cpp]$ cat primes.cpp #include "tbb/tbb.h" #include#include int main() { std::vector primes; primes.push_back(3); primes.push_back(7); primes.push_back(5); primes.push_back(2); tbb::parallel_sort( primes.begin(), primes.end() ); for( size_t i=0; i << std::endl; return 0; } $ gcc primes.cpp -ltbb $ a.out 2 3 5 7 [/cpp]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oops, it turned out that my cout was in the wrong place, thus outputting the wrong results. Thanks everyone!

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