Developer Reference

Intel® oneAPI Math Kernel Library LAPACK Examples

ID 766877
Date 12/20/2021
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

Compiling and Building C Examples

When using an ANSI C compiler, the C example calls the LAPACK routine in lowercase with no underscore:

dgesv

oneMKL defines the dgesv routine using the standard Fortran-style: dgesv_ (lowercase, trailing underscore) on Linux* OS, or _DGESV (uppercase, leading underscore) on Windows* OS. Another LAPACK binary, such as the one compiled from Netlib Fortran reference code, may define only the Fortran entry points. If you want to link a C example against such a binary, you need to redefine the C routine name to avoid an unresolved external reference, for example:

  • On Linux* OS:

    <cc> <compiler options> 
    	 -Ddgesv=dgesv_ dgesv_ex.c <link line>
    <cc> <compiler options> 
    	 -Dzgelsd=zgelsd_ zgelsd_ex.c <link line>
  • On Windows* OS:

    <cc> <compiler options> 
    	 -Ddgesv=DGESV dgesv_ex.c <link line>
    <cc> <compiler options> 
    	 -Dzgelsd=ZGELSD zgelsd_ex.c <link line>

where <cc> is a C compiler, dgesv_ex.c and zgelsd_ex.c are oneMKL LAPACK C examples, and <link line> contains linker options and arguments, including the LAPACK library files required for your application.

To compile and build an example:

  1. If needed, redefine the routine to avoid an unresolved external reference.
  2. Run the mklvars script to set the required environment variables.
  3. Build the application using an ANSI C compiler. See the following example lines for reference:
    • with Intel® C++ Compiler, you can use

      icc -mkl cgesv_ex.c on Linux* OS, or

      icl /Qmkl cgesv_ex.c on Windows* OS.

      See the Linking Your Application with the Intel Math Kernel Library section of the oneMKL Developer Guide for more information on linking with the oneMKL.

    • with third-party compilers, you can use

      cc -fopenmp -m64 -I${MKLROOT}/include cgesv_ex.c -Wl,--no-as-needed -L${MKLROOT}/lib/intel64 -lmkl_intel_lp64 -lmkl_core -lmkl_gnu_thread -lpthread -lm -ldl to compile with the GNU* C/C++ compiler on Linux* OS, or

      cl cgesv_ex.c /link mkl_intel_lp64_dll.lib mkl_core_dll.lib mkl_intel_thread_dll.lib libiomp5md.lib to compile with the 64-bit version of the Microsoft* C/C++ compiler on Windows* OS.

      NOTE:
      The examples above are linking dynamically against 64-bit oneMKL library files. To create a custom link line, use the oneMKL Link Line Advisor or refer to the oneMKL Developer Guide, section Linking Your Application with the Intel oneAPI Math Kernel Library.

See Also