Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

OpenMP 4.5 array reduction not working under Intel C++ 17.1.132

Marcin_M_
Beginner
1,762 Views

Hi,

According to the OpenMP website, Intel C++ 2017 supports OpenMP 4.5: http://www.openmp.org/resources/openmp-compilers/

I created an OpenMP 4.5 compliant code, which compiles fine under GCC 6.3.1:

    vector<double> res(n);
    double* results = res.data();

    #pragma omp parallel for reduction(+: results[:n])
    for(int s = 0; s < n; ++s) {
        // do something
    }

    return res;

This triggers a compilation error:

/home/marmstrz/pw-brandes/brandes.cpp(15): error: no matching declaration for this reduction
      #pragma omp parallel for reduction(+: results[:n])

Why doesn't this work with the Intel compiler?

0 Kudos
4 Replies
Judith_W_Intel
Employee
1,762 Views

 

It works fine for me with our latest supported 17.0 compiler. I only see the error with the 16.0 compiler.

sptel42-171> cat openmp.cpp
#include <vector>
using namespace std;

vector<double> foo(int n) {
  vector<double> res(n);
  double* results = res.data();

#pragma omp parallel for reduction(+: results[:n])
   for(int s = 0; s < n; ++s) {
         // do something
   }
   return res;
}
sptel42-172> icpc -qopenmp -c openmp.cpp
sptel42-173> which icpc
/site/spt/usr13/jward4/workspaces/17_0cfe/dev/build_objs/efi2linux_debug/bin/icpc
sptel42-174>

0 Kudos
Marcin_M_
Beginner
1,762 Views

What is the version of your compiler? Mine:

$ icpc --version
icpc (ICC) 17.0.1 20161005

$ which icpc
/opt/intel/compilers_and_libraries_2017.1.132/linux/bin/intel64/icpc


 

0 Kudos
Fogerty__Shane
Beginner
1,762 Views

Was there ever any resolution to this? I am experiencing the same thing.

I get the error:

error: no matching declaration for this reduction
    #pragma omp parallel for reduction(+:a[0:N]) private(j)
 

when trying to compile (with Intel 17.0.0 or 17.0.4) the OpenMP 4.5 example from http://www.openmp.org/wp-content/uploads/openmp-examples-4.5.0.pdf at the bottom of page 238. I can compile with gcc. I copy the code here:

 
#include <stdio.h>
#define N 100

void init(int n, float (*b));

int main(){

int i,j;
float a, b;

init(N,b);

for(i=0; i<N; i++) a=0.0e0;

#pragma omp parallel for reduction(+:a[0:N]) private(j)
for(i=0; i<N; i++){
  for(j=0; j<N; j++){
    a +=  b;
  }
}

printf(" a[0] a[N-1]: %f %f\n", a[0], a[N-1]);

return 0;
}
0 Kudos
Sheridan-Methven__Ol
1,762 Views

I am experiencing the same problems. I have gcc version 7.2.0 and have tried compiling the following with icc versions 17.0.1 (20161005) and 18.0.0 (20170811). Currently it only compiles using the version 18.0.0 of icc. Using gcc works fine.

(icc version 18.0.0)user:temp$ icc -qopenmp -std=c99 demo.c -o demo

 

(gcc version 7.2.0)mimic:temp% gcc -fopenmp -std=c99 demo.c -o demo

 

(icc version 17.0.1)mimic:temp% icc -qopenmp -std=c99 demo.c -o demo

demo.c(9): error: no matching declaration for this reduction
  #pragma omp parallel for reduction(+:results[:n])
                                       ^

compilation aborted for demo.c (code 2)

 

The C code is for demo.c is 

 

#include <stdio.h>
#include <stdlib.h>
#include <omp.h>

int main()
{
    unsigned int n = 5;
    double *results = (double *) calloc(n, sizeof(double));

#pragma omp parallel for reduction(+: results[:n])
    for (int s = 0; s < n; ++s)
    {
        results += 1 << s;
    }

    double res = 0;
    for (int i = 0; i < n; i++)
    {
        res += results;
    }
    printf("The sum is %f\n", res);
    return 0;
}

 

0 Kudos
Reply