简体   繁体   English

tbb:task_scheduler_init自定义分配器?

[英]tbb:task_scheduler_init custom allocator?

So I am trying to use parallel for each.. I have code where I do: 所以我试图为每个使用并行。

Source s;..
parallel_for_each(begin(_allocs), end(_allocs), [&s] (Allocs_t::value_type allocation) {
  // cool stuff with allocation
}

This works, and works well. 这行得通,而且效果很好。 however, I've seen in many posts that I should call tbb:task_scheduler_init before scheduling tasks. 但是,我在很多帖子中都看到在计划任务之前应该调用tbb:task_scheduler_init。

The problem is that I override malloc and calloc and I can't have the init call malloc and calloc(which it does..) So the questions are: 问题是我覆盖了malloc和calloc,而无法进行init调用malloc和calloc(确实如此。)所以问题是:

  1. why does it work well? 为什么运作良好? DOES it work well? 它运作良好吗?
  2. is there a way to give intel a specific allocator for all its purposes? 有没有办法为所有目的赋予Intel特定的分配器?

Thanks 谢谢

Instantiation of tbb:task_scheduler_init object is optional. tbb:task_scheduler_init对象的实例化是可选的。 TBB has lazy auto-initialization mechanism which constructs everything on the first call to TBB algorithms/scheduler. TBB具有惰性自动初始化机制,该机制可在首次调用TBB算法/调度程序时构造所有内容。 Auto-initialization is equal to construction of a global task_scheduler_init object just before your first call to TBB. 自动初始化等于在您首次调用TBB之前构造一个全局task_scheduler_init对象。

Of course, if you need to override the default number of threads, specify the scope where TBB should be initialized, or specify the size of the stack for workers, explicit initialization is unavoidable. 当然,如果您需要覆盖默认的线程数,指定应初始化TBB的范围或为工作人员指定堆栈的大小,则显式初始化是不可避免的。

TBB scheduler uses either its own scalable allocator (tbbmalloc.dll, libtbbmalloc.so ..) if found nearby to tbb binaries, or it falls back to using malloc otherwise. 如果在tbb二进制文件附近发现,TBB调度程序将使用其自己的可扩展分配器(tbbmalloc.dll,libtbbmalloc.so ..),否则将退回使用malloc。 There is no way to explicitly specify any other allocator to be used by the scheduler (unlike TBB containers which have corresponding template argument). 无法显式指定调度程序要使用的任何其他分配器(与具有相应模板参数的TBB容器不同)。

Given all the above, I think you have two [combinable] options: 鉴于以上所有,我认为您有两个[combinable]选项:

  1. Ensure that TBB scheduler uses its own allocator, so you don't have to worry about correct replacement of malloc for TBB. 确保TBB调度程序使用其自己的分配器,因此您不必担心为TBB正确替换malloc。
  2. Or/and, ensure that the only task_scheduler_init is created and destroyed at the points (scope) where malloc/free are in consistent state. 或/并且,请确保在malloc / free处于一致状态的点(作用域)上创建并销毁了唯一的task_scheduler_init。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM