使用OpenMP线程重新初始化向量要快得多吗? [英] Is it much faster to re-initialize a vector using OpenMP threads?

查看:55
本文介绍了使用OpenMP线程重新初始化向量要快得多吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用OpenMP库进行并行计算.我使用C ++向量,其大小通常为1 * 10 ^ 5.在执行迭代过程时,我需要将这些大型向量(不是线程专用的,而是全局范围的)重新初始化为初始值.使用#pragma omp或#pragma omp single可以更快地做到这一点?

I'm using OpenMP libraries for parallel computing. I use C++ vectors, whose size is usually in the order of 1*10^5. While going through iteration process, I need to re-initialize a bunch of these large vectors(not thread private but global scope) to a initial value. which is the faster way to do this?, using #pragma omp for or #pragma omp single?

推荐答案

一般的答案将是取决于,您必须测量",因为C ++中的初始化取决于类型,可能是琐碎的或非常昂贵的.您没有提供太多详细信息,因此您必须猜测一下.
如果一个类具有计算上昂贵的构造函数,那么并行化工作 可能是值得的.

The general answer would need to be "it depends, you have to measure" since initialization in C++ can be, depending on the type, trivial or very expensive. You did not provide an awful lot of detail, so one has to guess a bit.
If a class has a computionally expensive constructor, parallelizing work may very well be worth it.

您的特定措辞初始化为价值"表明您的载体具有POD(例如,整数?).我会假设是这种情况.

Your specific wording "initialize to value" suggests that your vector holds POD (say, for example, integers?). I will assume that this is the case.

假设这样,并行化几乎肯定会不会更快.此操作受内存带宽的约束,并且一个CPU线程应该能够将内存带宽饱和到大约99%.

Assuming this, parallelizing will almost certainly not be any faster. This operation is bound by memory bandwidth, and one CPU thread should be able to saturate memory bandwidth to approximately 99%.

但是,由于多种原因,并行化可能会非常慢(我将不做详细说明,可以说这不太可能更快).

Parallelizing may however very well be slower, due to several reasons (which I'm not going to elaborate, enough being said that it's unlikely to be faster).

这篇关于使用OpenMP线程重新初始化向量要快得多吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆