Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to statically link to TBB?

Tags:

c++

linker

tbb

How can I statically link the intel's TBB libraries to my application? I know all the caveats such as unfair load distribution of the scheduler, but I don't need the scheduler, just the containers, so it's ok.

Anyways I know this can be done, although its undocumented, however I just can't seem to find the way to do it right now (although I've seen it before somewhere).

So does anyone know or have any clues?

thanks

like image 569
Robert Gould Avatar asked Mar 12 '09 11:03

Robert Gould


3 Answers

This is strongly not recommended:

Is there a version of TBB that provides statically linked libraries?

TBB is not provided as a statically linked library, for the following reasons*:

Most libraries operate locally. For example, an Intel(R) MKL FFT transforms an array. It is irrelevant how many copies of the FFT there are. Multiple copies and versions can coexist without difficulty. But some libraries control program-wide resources, such as memory and processors. For example, garbage collectors control memory allocation across a program. Analogously, TBB controls scheduling of tasks across a program. To do their job effectively, each of these must be a singleton; that is, have a sole instance that can coordinate activities across the entire program. Allowing k instances of the TBB scheduler in a single program would cause there to be k times as many software threads as hardware threads. The program would operate inefficiently, because the machine would be oversubscribed by a factor of k, causing more context switching, cache contention, and memory consumption. Furthermore, TBB's efficient support for nested parallelism would be negated when nested parallelism arose from nested invocations of distinct schedulers.

The most practical solution for creating a program-wide singleton is a dynamic shared library that contains the singleton. Of course if the schedulers could cooperate, we would not need a singleton. But that cooperation requires a centralized agent to communicate through; that is, a singleton!

Our decision to omit a statically linkable version of TBB was strongly influenced by our OpenMP experience. Like TBB, OpenMP also tries to schedule across a program. A static version of the OpenMP run-time was once provided, and it has been a constant source of problems arising from duplicate schedulers. We think it best not to repeat that history. As an indirect proof of the validity of these considerations, we could point to the fact that Microsoft Visual C++ only provides OpenMP support via dynamic libraries.

Source: http://www.threadingbuildingblocks.org/faq/11#sthash.t3BrizFQ.dpuf

like image 113
Yoav Avatar answered Oct 03 '22 16:10

Yoav


EDIT - Changed to use extra_inc. Thanks Jeff!

Build with the following parameter:

make extra_inc=big_iron.inc

The static libraries will be built. See the caveats in build/big_iron.inc.

like image 8
sourcedelica Avatar answered Oct 03 '22 17:10

sourcedelica


Build static libraries from source

After acquiring the source code from https://www.threadingbuildingblocks.org/, build TBB like this:

make extra_inc=big_iron.inc

If you need extra options, then instead build like this:

make extra_inc=big_iron.inc <extra options>

Running multiple TBB programs per node

If you run a multiprocessing application, e.g. using MPI, you may need to explicitly initialize the TBB scheduler with the appropriate number of threads to avoid oversubscription.

An example of this in a large application can be found in https://github.com/m-a-d-n-e-s-s/madness/blob/master/src/madness/world/thread.cc.

Comment on documentation

This feature has been available for many years (since at least 2013), although it is not documented for the reasons described in other answers.

Historical note

This feature was originally developed because IBM Blue Gene and Cray supercomputers either did not support shared libraries or did not perform well when using them, due to the lack of a locally mounted filesystem.

like image 5
Jeff Hammond Avatar answered Oct 03 '22 16:10

Jeff Hammond