Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Christopher_R_3
Beginner
70 Views

Compiling a Shared Library with Offload Pragmas

Hey,

  I am having difficulties trying to compile simple programs with offload pragmas. I am testing out the tutorial found here http://www.drdobbs.com/parallel/programming-intels-xeon-phi-a-jumpstart/240144160?pgno=3 and if I change the compilation command for matrix.off to have -openmp (somehow he forgot it), -shared, and -fPIC I get segmentation faults. Note that if those are not in the compilation command (other than adding -openmp) everything works as it should. I cannot find any examples of people using offload pragmas in shared libraries to find out what else I need to try. Thanks.

0 Kudos
3 Replies
Kevin_D_Intel
Employee
70 Views

There is some information in the C++ User’s Guide under Using Libraries With Offloaded Code.

The -offload-build option is obsolete. The compiler will auto-detect offload language extensions and perform the necessary host and target compilations to enable offload. You can use the replacement (16.0 compiler) option, -qoffload, if you wish but that is the default. Only the shared library needs to be compiled for offload also.

For this example, split the source into two source files (e.g. matrix.c and main.c). This enables building matrix.c into a shared library with offload enabled. Then compile the files as shown below. I updated the compiler options to use for our latest 16.0 release. (-vec-report3 is deprecated so replace with: -qopt-report -qopt-report-phase=vec). I used the default (-qoffload) for matrix.c. The -diag-disable 10397 silences some remarks.

icc -mkl -O3 -openmp -fpic -diag-disable 10397 -Wno-unknown-pragmas -std=c99 -qopt-report -qopt-report-phase=vec -shared matrix.c -o libmatrix.so
icc -mkl -O3 -openmp -diag-disable 10397 -Wno-unknown-pragmas -std=c99 -qopt-report -qopt-report-phase=vec main.c -o matrix.shr -L. -lmatrix

When you run, make certain the appropriate path to the matrix shared library is present in both your LD_LIBRARY_PATH and MIC_LD_LIBRARY_PATH variables. In my case, I used the current directory (e.g. export MIC_LD_LIBRARY_PATH=$MIC_LD_LIBRARY_PATH:.).

The code should run. Here's an example.

$ icc -V
Intel(R) C Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 16.0.1.150 Build 20151021

$ icc -mkl -O3 -openmp -fpic -diag-disable 10397 -Wno-unknown-pragmas -std=c99 -qopt-report -qopt-report-phase=vec -shared matrix.c -o libmatrix.so

$ icc -mkl -O3 -openmp -diag-disable 10397 -Wno-unknown-pragmas -std=c99 -qopt-report -qopt-report-phase=vec main.c -o matrix.shr -L. -lmatrix

$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:.
$ export MIC_LD_LIBRARY_PATH=$MIC_LD_LIBRARY_PATH:.

$ ./matrix.shr 100 24 2
./matrix.shr nThreads 24 matrix 100 100 runtime 0.0102108 GFlop/s 0.195871 mklGflop 61.9979 NRMSD_error -nan

 

Christopher_R_3
Beginner
70 Views

Nice answer. This got the example code and my code working. You're the best!

Kevin_D_Intel
Employee
70 Views

Thank you for the kind words. Glad to hear that helped.

Reply