Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intel's pragma simd vs OpenMP's pragma omp simd

The Intel compiler allows us to vectorize loops via

#pragma simd
for ( ... )

However, you also have the option to do this with OpenMP 4's directive:

#pragma omp simd
for ( ... )

Is there any difference between the two?

like image 216
user2052436 Avatar asked Dec 24 '22 09:12

user2052436


2 Answers

For all intents and purposes they should be identical. The difference is that the OpenMP 4.0 #pragma omp simd directive is portable and should work with other compilers that support OpenMP 4.0 as well as Intel's.

Furthemore, there are several clauses in the OpenMP version which allow you to vectorize instructions in a more robust manner (safelen(), linear(), aligned(), reduction(), and collapse() come to mind).

like image 143
NoseKnowsAll Avatar answered Mar 06 '23 22:03

NoseKnowsAll


#pragma simd

- is positioned as a part of Intel C++ Cilk SIMD extensions (along with Array Notation). This positioning looks slightly strange, because Cilk is not for Fortran, while Fortran Compiler supports mostly identical directive simd.

#pragma omp simd 

- is a part of OpenMP standard, so it's naturally more portable across Compiler and Platforms.

Normally Intel rolls out new capabilities in Cilk first and in OpenMP second. The reason is very natural: it takes time to accept something as part of OpenMP standard. For example simdlen has only been added in OpenMP4.5 in November 2015, while identical clause (vectorlength) has been part of Cilk pragma 3 or 4 years ago already. simdlen vs. vectorlength highlights another observation that some pragma clauses syntax may differ between simd and omp simd.

So, if you need portability across compilers, use OpenMP pragma. But if it's more important for you to get access to new simd compiler capabilities as early as possible, then you may prefer or optionally use Cilk (proprietary) pragma. All the same arguments and considerations are equally applicable to #pragma omp declare simd vs. #pragma declare simd (which should answer your potential second question).

Reference of "Cilk" pragma simd clauses is available here: https://software.intel.com/en-us/node/524555 (I think it's slightly out of date; I've heard about new capabilities of pragma simd not reflected in this link yet).

like image 27
zam Avatar answered Mar 06 '23 20:03

zam