How can I use openmp in android studio

I am using android-ndk-r10d for c ++ coding in android studio. Now I want to use openmp and I add codes to Android.mk:

LOCAL_CFLAGS += -fopenmp
LOCAL_LDFLAGS += -fopenmp

      

and add codes to myapp.cpp:

#include <omp.h>
#pragma omp parallel for
for(int i = 1, ii = 0; i < outImage[0]->height; i+=2, ii = i>>1) {
 /* Do work... */
}

      

but gradle build with error only because of [#pragma omp parallel for] How can I handle the syntax error?

+3


source to share


1 answer


Maybe the compiler doesn't like the complex structure of the for () statement. OpenMP likes to know the number of steps ahead of time. Also I doubt that OpenMP can deal with 2 loop variables (i and ii). Try a simple loop with fixed limits like



int kmax = (outImage[0]->height - 1) / 2; // not sure this is right

#pragma omp parallel for
for( int k=0; k<kmax; k++)
{
    int i=k*2 + 1; // not sure this is right
    int ii = i>>1;
    /* Do work ... */
}

      

0


source







All Articles