I've been in the habit of using __MIC__ to tell the compiler how to vectorize (or not) e.g.
#if __MIC__
a(:n)= pack(b(:n),b(:n)>0)
#else
j= 0
do i= 1,n
if(b(i) > 0.)then
j= j+1
a(j)= b(i)
endif
enddo
#endif
or (for the case where the compiler vectorizes for AVX but loses performance)
#if ! __MIC__
!dir$ novector
#endif
Now that compilers support AVX512, it appears that additional macros will be needed, e.g.
#if (! __KNC__) && (! __AVX512F__)
Is there a better way? Now that both ifort and gfortran are excessively aggressive sometimes about vectorization, I've introduced some conditional real,volatile :: declarations, but this is getting ugly.
I've been going through source code to remove conditional compilations where the latest Intel compilers make the right decision about vectorization, but it seems unlikely that compilers will get any better on this.