Quick Link Intel® MKL In Xcode* IDE: A Fortran Sample

Since version 10.x , Intel® Math Kernel Library for Mac OS* comes bundled with Intel® Fortan or C/C++ Compiler for Mac OS*, which was integrated into Xcode Integrated Development Enviornments after default installation. This provided us a quick link way to access MKL in Xcode IDE.

This tutorial is intended to show the quick way using XCode 4.0 and Intel® Fortran Composer XE for OS X*.  but we hope that it will be helpful for users of the other versions. The latest Intel® MKL 11.0 for Mac OS was integrated in Intel® Fortran Composer XE 2013 for OS X*,  Here is the fortran sample

For gernal link way, please refer to  
Compiling and linking MKL with Xcode*  
How to link application against Intel MKL using XCode IDE 
 
1.    Create a new Xcode* project

a)   Copy sample source code: dgemmx.f and common_func.f from <mkl install directory /examples/blas/source> to your work directory, for example, /Users/yhu5/blas.
b)   Launch the Xcode application, typically found in the Developer > Applications folder.
c)   In Xcode Menu, select File > New > New Project.... , The New Project Assistant window opens. Select Application in the left pane. Select a template, for example, Command Line Tool, and click Next. Name your project, for example, MKL_dgemm_f, and select a type C. Click Next. Specify a directory for your project , For example, /Users/yhu5/blas. Click Create.
 mkl1.png

d)     Xcode creates the named project directory, with an .xcodeproj extension and several new source files like main.c etc.  Remove main.c, etc. file  and add dgemmx.f and common_func.f into ‘Source' project folder.

 mkl2.png

Each Xcode project has its own Project Editor window that displays project source files, targets, and executables.

2. Setting MKL Options in Xcode IDE

In the Xcode project, select the target and click Build Setting. Under the Build Settings tab, click All. Scroll down until you see IFORT_MKL, Select "Use threaded Intel® Math Kernel Library (or "Use non-thread Intel @ Math Kernal Library.)

 mkl3.png

3. Build and Run the Project

Select Product > Build. Or Click the  ‘Run' button on project tools bar, the project will build successfully. 
But may run with error message dyld: Library not loaded: libmkl_intel_lp64.dylibmkl7.png

(other compiler errors, like files is not found or Open file failed, please change the path of the files and the code in dgemmx.f, line 49, OPEN(UNIT=1, FILE='/Users/xx/xx/dgemmx.d',STATUS='OLD' so Xcode can find them.)

4) Set Run Environment

Open the Scheme Editor, click the Scheme button in the Project Editor Toolbar and select Edit Scheme, Under the Arguments tab, add DYLD_LIBRARY_PATH as an environment variable.
Set the Value as the full path to the Intel compiler's /lib directory and MKL directory
DYLD_LIBRARY_PATH=/opt/intel/composer_xe_2013/compiler/lib:

 /opt/intel/composer_xe_2013/mkl/lib

mkl4.png

Click Run button again, you will get the result in Output box.

mkl5.png

5) Troubleshooting

 dyld: Library not loaded: libmkl_intel_lp64.dylib

Please either set the environment variable DYLD_LIBRARY_PATH in Xcode environment as step 4  or use mkl environment setting tool before run the executable file in Command line windows, i.e .

>source /opt/intel/composer_xe_2013/mkl/bin/mklvars.sh intel 64
> executable

Please refer to Intel Compiler User and Reference Guide =>Building Applications with Xcode* IDE"
or "Configuring the Apple Xcode* Developer Software to Link with Intel MKL" section in MKL user guide for more details. 
And refer to "Linking Your Application with Intel® MKL" section in the Getting Started document to understand which libraries required by your code.

Operating System:

Mac OS*
AttachmentSize
Download mkl-dgemm-f.tar.gz35.08 KB
For more complete information about compiler optimizations, see our Optimization Notice.