- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I'm trying to run example of parallel_sort function presented in the reference manual in chapter 3.10 parallel_sort Template Function and everytime I run it, it crashes with segmentation fault.
I'm using TBB 2.1 installed from package for Ubuntu 9.10 64-bit with GCC 4.4.1.
1) Here is example program:
#include
#include
using namespace tbb;
int main()
{
const int N = 100000;
float a
for( int i = 0; i < N; i++ ) {
a = std::sin((double)i);
}
parallel_sort(a, a + N);
}
2) Compilation commands, I tried both:
g++ -O2 -DNDEBUG -o sort_array sort_array.cpp -ltbb
g++ -O0 -g -DTBB_USE_DEBUG -o sort_array sort_array.cpp -ltbb
3) Backtrace from GDB:
$ gdb ./sort_array
(gdb) run
Starting program: /home/mloskot/workshop/tbb/parallel_sort/sort_array
[Thread debugging using libthread_db enabled]
Program received signal SIGSEGV, Segmentation fault.
tbb::task_group_context::init (this=0x7ffffff9c4e0) at ../../src/tbb/task.cpp:3124
3124 ../../src/tbb/task.cpp: No such file or directory.
in ../../src/tbb/task.cpp
(gdb) bt
#0 tbb::task_group_context::init (this=0x7ffffff9c4e0) at ../../src/tbb/task.cpp:3124
#1 0x00000000004013ff in task_group_context (this=0x7ffffff9c4e0, relation_with_parent=tbb::task_group_context::bound)
at /usr/include/tbb/task.h:284
#2 0x0000000000401be4 in tbb::internal::parallel_quick_sort
end=0x7fffffffe120, comp=...) at /usr/include/tbb/parallel_sort.h:155
#3 0x0000000000401b23 in tbb::parallel_sort
comp=...) at /usr/include/tbb/parallel_sort.h:203
#4 0x0000000000401ab3 in tbb::parallel_sort
at /usr/include/tbb/parallel_sort.h:219
#5 0x0000000000401363 in main () at sort_array.cpp:12
I tested similar example but based on std::vector and it crashes in the same way:
#include
#include
#include
using namespace tbb;
int main()
{
const int N = 100000;
std::vector
for( int i = 0; i < N; i++ )
{
a = std::sin(double(i));
}
parallel_sort(a.begin(), a.end());
}
Could anyone help me to find to where is the problem? In TBB or in my environenment/installation?
I tried to find similar reports in the archive but noting comes out for parallel_sort and segmentation fault
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Since you use TBB 2.1, you have to initialize TBB first. Include tbb/task_scheduler_init.h into the source file, and add the following line to the very beginning of main():
task_scheduler_init TBBinit;
In TBB 2.2, initialization became optional. Ask the package maintainer for a newer version.
BTW, you would get more meaningful diagnostics if you linked with the debug version of TBB (-ltbb_debug), in case it is provided in the package you use.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Since you use TBB 2.1, you have to initialize TBB first. Include tbb/task_scheduler_init.h into the source file, and add the following line to the very beginning of main():
task_scheduler_init TBBinit;
In TBB 2.2, initialization became optional. Ask the package maintainer for a newer version.
BTW, you would get more meaningful diagnostics if you linked with the debug version of TBB (-ltbb_debug), in case it is provided in the package you use.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Alex,
Your suggestion solves the problem, of course. Reading newer docs and using older library, I missed thatimportant change and that before 2.2 the scheduler initialization is required.
Regarding linking to debug version of the library, I can't do it because this binary is not provided in the Ubuntu 9.10 packages I'm using now. However, the upcoming Ubuntu 10.04 does bring TBB 2.2.
Thank you very much.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
But, there is also libtbb-dev and libtbb2-dbg packages whichyou could download and install - I guess some of those should contain the debug version.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
thanks for this awesome stuff shared here,..its very nice and useful one ,....
i appreciate this helpful material placed here,...

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