English 中文(简体)
翻新建筑区的任务
原标题:Tasks on Thread Building Blocks
  • 时间:2010-08-03 13:11:22
  •  标签:
  • c++
  • tbb

这里的例子有:

#include <iostream>
#include <list>
#include <tbb/task.h>
#include <tbb/task_group.h>
#include <stdlib.h>
#include <boost/thread.hpp>

using namespace tbb;

 long fib(long a)
{
  if (a < 2) return 1;

  return fib(a - 1) + fib(a - 2);
}

class PrintTask 
{
public:
    void operator()()
    {
        std::cout << "hi world!: " <<  boost::this_thread::get_id() << std::endl;

        fib(50);
    }
};

int main(int argc, char** argv)
{     
    task_group group;

    for (int i = 0; i < 100; ++i)
    {
      group.run(PrintTask());
    }      

    group.wait();

    return(0);
}

在此,我计算一个大的纤维素序列,只是模拟非锁定的计算。 我猜测,这部法典将产生两个以上的线索(我的计算机是核心2Duo),但只要求开展第一和第二项任务。 这是猜测的吗?

最佳回答

是的,这是预期的行为。

TBB是一家图书馆,旨在把手工业守则相平行。 官方文件指出,你应当利用另一个图书馆(例如校对)来完成这些任务(或加强:在你看来已经准备好)。

就最大限度的绩效而言,与你的核心相比,没有什么意义,因为涉及一些重大间接费用(不仅仅是环境变化,而且还包括冲积海滩等)。

EDIT: You can read about it in the Tutorial. Specifically, in section 1.2 "Benefits" it states

Intel® Threading Building Blocks targets threading for performance. Most general-purpose threading packages support many different kinds of threading, such as threading for asynchronous events in graphical user interfaces. As a result, general-purpose packages tend to be low-level tools that provide a foundation, not a solution. Instead, Intel® Threading Building Blocks focuses on the particular goal of parallelizing computationally intensive work, delivering higher-level, simpler solutions.

以及

Intel® Threading Building Blocks is compatible with other threading packages. Because the library is not designed to address all threading problems, it can coexist seamlessly with other threading packages.

问题回答

大规模多面阻塞行为(结果:滥用)是多处的反家长,可能会造成不良行为,因为它会错失。 此外,TBB保留了实施集团的权利,然而,无论它喜欢什么东西,它都会pa。 如果你只拥有双重核心,而且你要求开展繁重的工作,那么它为什么会铺开两条以上线? 职业顾问办公室和其他用具将 ha忙地用剩余的背景时间。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签