parallel_sort example throws segmentation fault

parallel_sort example throws segmentation fault

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[N];
for( int i = 0; i a[i] = 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 > (begin=0x7ffffff9c6a0,
end=0x7fffffffe120, comp=...) at /usr/include/tbb/parallel_sort.h:155
#3 0x0000000000401b23 in tbb::parallel_sort > (begin=0x7ffffff9c6a0, end=0x7fffffffe120,
comp=...) at /usr/include/tbb/parallel_sort.h:203
#4 0x0000000000401ab3 in tbb::parallel_sort (begin=0x7ffffff9c6a0, end=0x7fffffffe120)
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 a(N);
for( int i = 0; i {
a[i] = 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

6 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
Best Reply

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.

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.

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.

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.

Yes, I know about these related packages. I have a all of them installed in fact. The libtbb2-dbg is debugging symbols only package but, AFAIK, it's not a different configuration of the library binary.

hi Mateusz Loskot,...
thanks for this awesome stuff shared here,..its very nice and useful one ,....
i appreciate this helpful material placed here,...

Leave a Comment

Please sign in to add a comment. Not a member? Join today