title: How to use omp parallel for and omp simd together?
body: <p>I want to test <code>#pragma omp parallel for</code> and <code>#pragma omp simd</code> for a simple matrix addition program. When I use each of them separately, I get no error and it seems fine. But, I want to test how much performance can be gained using both of them. If I use <code>#pragma omp parallel for</code> before the outer loop and <code>#pragma omp simd</code> before the inner loop I get no error as well. The error occures when I use both of them before the outer loop. I get an error at runtime not compile time. <code>ICC</code> and <code>GCC</code> return error but <code>Clang</code> doesn't. It might be because <code>Clang</code> regect the parallelization. In my experiments, Clang does not parallelize and run the program with only one thread.</p>
  
  <p>The program is here:</p>
  
  
  
  <pre><code>#include &lt;stdio.h&gt;
  //#include &lt;x86intrin.h&gt;
  #define N 512
  #define M N
  
  int __attribute__(( aligned(32))) a[N][M],
      __attribute__(( aligned(32))) b[N][M],
      __attribute__(( aligned(32))) c_result[N][M];
  
  int main()
  {
      int i, j;
      #pragma omp parallel for
      #pragma omp simd
      for( i=0;i&lt;N;i++){
          for(j=0;j&lt;M;j++){
              c_result[i][j]= a[i][j] + b[i][j];
          }
      }
  
      return 0;
  }
  </code></pre>
  
  <p>The error for:
  ICC:</p>
  
  <blockquote>
    <p>IMP1.c(20): error: omp directive is not followed by a parallelizable
    for loop      #pragma omp parallel for    ^</p>
    
    <p>compilation aborted for IMP1.c (code 2)</p>
  </blockquote>
  
  <p>GCC:</p>
  
  <blockquote>
    <p>IMP1.c: In function ‘main’: </p>
    
    <p>IMP1.c:21:10: error: for statement
    expected before ‘#pragma’   #pragma omp simd</p>
  </blockquote>
  
  <p>Because in my other testes <code>pragma omp simd</code> for outer loop gets better performance I need to put that there (don't I?).</p>
  
  <p>Platform: Intel Core i7 6700 HQ, Fedora 27</p>
  
  <p>Tested compilers: ICC 18, GCC 7.2, Clang 5</p>
  
  <p>Compiler command line: </p>
  
  <p><code>icc -O3 -qopenmp -xHOST -no-vec</code></p>
  
  <p><code>gcc -O3 -fopenmp -march=native -fno-tree-vectorize -fno-tree-slp-vectorize</code></p>
  
  <p><code>clang -O3 -fopenmp=libgomp -march=native -fno-vectorize -fno-slp-vectorize</code></p>