I am trying to offload code the GPU using OpenMP 4+ directives. I am using ubuntu 16.04 with GCC 7.2 and for general cases it is working fine. My problem comes when I am trying to offload a code that has a call to the sqrtf function that is defined in "math.h". The troubeling code is this:
#pragma omp target teams distribute \map(to:posx[:n],posy[:n],posz[:n]) \map(from:frcx[:n],frcy[:n],frcz[:n])for (int i = 0; i < n; i++) { frcx[i] = 0.0f; frcy[i] = 0.0f; frcz[i] = 0.0f; for (int j = 0; j < n; j++) { float dx = posx[j] - posx[i]; float dy = posy[j] - posy[i]; float dz = posz[j] - posz[i]; float distSqr = dx*dx + dy*dy + dz*dz + SOFTENING; float invDist = 1.0f / sqrtf(distSqr); float invDist3 = invDist * invDist * invDist; frcx[i] += dx * invDist3; frcy[i] += dy * invDist3; frcz[i] += dz * invDist3; }}
When I try to compile it with:
$ gcc -Wall -O2 -march=native -mtune=native -fopenmp -o nbody_cpu_arrays_parallel_gpu common_funcs.c nbody_cpu_arrays_parallel_gpu.c -lmunresolved symbol sqrtfcollect2: error: ld returned 1 exit statusmkoffload: fatal error: x86_64-linux-gnu-accel-nvptx-none-gcc-7 returned 1 exit statuscompilation terminated.lto-wrapper: fatal error: /usr/lib/gcc/x86_64-linux-gnu/7//accel/nvptx-none/mkoffload returned 1 exit statuscompilation terminated./usr/bin/ld: error: lto-wrapper failedcollect2: error: ld returned 1 exit status
How can I make use of square root operations (or other mathematical functions) when offloading OMP code to GPUs?