- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
What is the best way to optimize the cycle
cilk_for(i=0;i<n;i++){
x=x<0?0:x;
}
or somethings like that?
Thanks, Fabio
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
With cilk_for, it's important to make the induction variable local to each worker (thus C99 or C++):
cilk_for(int i=0;..... (there are lots of myths about appropriate data types)
icpc should tell you about this locality requirement (why not icc?).
If you want combined simd and multi-core parallelism, you must write it out with each i performing an array section using extended array notation, preferably cache aligned. This may require AVX2 if it's an integer data type.
Intel compiler should optimize the alternative written with std::max(), while gcc doesn't offer vectorization of std::max, but, unlike the Intel compiler, offers vectorization with fmax et al. under -ffast-math (-ffinite-math-only). If it weren't for these differences among compilers, I'd recommend max() [min] where it fits.
I'd say consider omp parallel for simd with Intel compiler; it's a bit simpler and more capable, although some similar considerations apply, along with the issues about using OpenMP and Cilk(tm) Plus in the same application.
コピーされたリンク
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
With cilk_for, it's important to make the induction variable local to each worker (thus C99 or C++):
cilk_for(int i=0;..... (there are lots of myths about appropriate data types)
icpc should tell you about this locality requirement (why not icc?).
If you want combined simd and multi-core parallelism, you must write it out with each i performing an array section using extended array notation, preferably cache aligned. This may require AVX2 if it's an integer data type.
Intel compiler should optimize the alternative written with std::max(), while gcc doesn't offer vectorization of std::max, but, unlike the Intel compiler, offers vectorization with fmax et al. under -ffast-math (-ffinite-math-only). If it weren't for these differences among compilers, I'd recommend max() [min] where it fits.
I'd say consider omp parallel for simd with Intel compiler; it's a bit simpler and more capable, although some similar considerations apply, along with the issues about using OpenMP and Cilk(tm) Plus in the same application.
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
Hi Tim,
first, Thanks!
then: I've not used local counter for the whole code and the parallelization works fine.
I'm guessing if standard C allows for local counter declaration, the same as C++. However
this is not important.
Coming back to the important issue, some suggestions you gave me are a bit obscures
(that is my fault) so I need to investigate a bit deeper the way to exploit parallel/vector
capability of processor(s) through programming and icc command line.
Thanks a lot.
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
You must set -std=c99 in order to accept cilk_for(int i;...
There is significant performance loss when sharing the loop counter among a large number of workers. I guessed wrongly originally that cilk_for would automatically privatize, until I got the message under C++ and checked performance.