如何静态链接到 TBB?

2022-01-11 00:00:00 linker c++ tbb

如何将 intel 的 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?

谢谢

推荐答案

强烈不推荐:

是否有提供静态链接库的 TBB 版本?

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

TBB 未作为静态链接库提供,原因如下*:

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

大多数库在本地运行.例如,英特尔(R) MKL FFT 转换数组.FFT 有多少个副本无关紧要.多个副本和版本可以毫无困难地共存.但是一些库控制程序范围的资源,例如内存和处理器.例如,垃圾收集器控制整个程序的内存分配.类似地,TBB 控制跨程序的任务调度.为了有效地完成工作,这些中的每一个都必须是单例;也就是说,有一个可以协调整个程序的活动的唯一实例.在单个程序中允许 k 个 TBB 调度程序实例将导致软件线程的数量是硬件线程的 k 倍.该程序将低效运行,因为机器将被超额订阅 k 倍,导致更多的上下文切换、缓存争用和内存消耗.此外,当嵌套并行性源自不同调度程序的嵌套调用时,TBB 对嵌套并行性的有效支持将被否定.

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!

我们决定省略 TBB 的静态链接版本的决定很大程度上受到了我们的 OpenMP 经验的影响.与 TBB 一样,OpenMP 也尝试跨程序进行调度.曾经提供过静态版本的 OpenMP 运行时,它一直是重复调度程序引起的问题的源头.我们认为最好不要重蹈覆辙.作为这些考虑的有效性的间接证明,我们可以指出 Microsoft Visual C++ 仅通过动态库提供 OpenMP 支持这一事实.

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.

来源:http://www.threadingbuildingblocks.org/faq/11#stash.t3BrizFQ.dpuf

相关文章