OpenMP开销计算 [英] OpenMP overhead calculation
问题描述
给定n个线程,有没有一种方法可以计算在OpenMP中实现特定指令所需的开销量(例如,周期数).
Given n threads, is there a way that I can calculate the amount of overhead (e.g. # of cycles) that is required to implement a specific directive in OpenMP.
例如,给出下面的代码
#pragma omp parallel
{
#pragma omp for
for( int i=0 ; i < m ; i++ )
a[i] = b[i] + c[i];
}
我能以某种方式计算创建这些线程需要多少开销吗?
Can I calculate somehow how much overhead is required to create these threads?
推荐答案
是的,可以.请查看 EPCC基准.尽管此代码有些陈旧,但它可以测量OpenMP构造的各种开销,包括omp parallel for
和omp critical
.
Yes, you can. Please take a look at EPCC benchmark. Although this code is a bit older, it measures the various overhead of OpenMP's constructs, including omp parallel for
and omp critical
.
基本方法在某种程度上非常简单明了.您在没有任何OpenMP的情况下测量基线 serial 时间,仅包含要测量的OpenMP编译指示.然后,减去经过的时间.这正是EPCC基准衡量开销的方式.参见"syncbench.c"之类的资源.
Basic approach is somewhat very simple and straightforward. You measure a baseline serial time without any OpenMP, and just include a OpenMP pragma that you want to measure. Then, subtract the elapsed times. This is exactly how EPCC benchmark measures the overhead. See the source like 'syncbench.c'.
请注意,间接费用表示为时间,而不是周期数.我也尝试测量周期数,但是由于同步,OpenMP并行构造的开销可能包括阻塞的时间.因此,周期数可能无法反映OpenMP的实际开销.
Please note that the overhead is expressed as time, rather than the # of cycles. I also tried to measure # of cycles, but OpenMP parallel constructs' overhead may include blocked time due to synchronizations. Hence, # of cycles may not reflect the real overhead of OpenMP.
这篇关于OpenMP开销计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!