小编And*_*rii的帖子

C++ 0x线程没有加速

我编写了一个程序,用于使用c ++ 0x线程搜索数组中的最大值(用于学习目的).为了实现,我使用了标准线程未来的类.但是,并行化功能不断显示与非并行化相同或更差的运行时间.

代码如下.我试图将数据存储在一维数组,多维数组中,最后得到几个数组.但是,没有选择取得好成绩.我试图从Eclipse和命令行编译和运行我的代码,仍然没有成功.我也尝试过类似的测试而不使用数组.并行化只提高了20%的速度.从我的角度来看,我运行非常简单的并行程序,没有锁和几乎没有资源共享(每个线程在他自己的数组上运行).什么是瓶颈?

我的机器配备2.2 GHz英特尔酷睿i7处理器和8 GB内存,运行Ubuntu 12.04.

const int n = 100000000;

int a[n], b[n], c[n], d[n];

int find_max_usual() {
    int res = 0;
    for (int i = 0; i < n; ++i) {
        res = max(res, a[i]);
        res = max(res, b[i]);
        res = max(res, c[i]);
        res = max(res, d[i]);
    }
    return res;
}

int find_max(int *a) {
    int res = 0;
    for (int i = 0; i < n; ++i)
        res = max(res, a[i]); …
Run Code Online (Sandbox Code Playgroud)

c++ parallel-processing multithreading future c++11

8
推荐指数
1
解决办法
1081
查看次数

标签 统计

c++ ×1

c++11 ×1

future ×1

multithreading ×1

parallel-processing ×1