Skip to main content

more options


Software Library: MKL

Please use the "Switch to Details" button to return to the lab instructions.

The goal of the previous lab was to run an executable in batch mode. In this section we will take a slight detour and use function calls to the Intel Math Kernel Library (MKL) in a program. The codes in this section of the lab will not be used for the remaining lab sections.

Prerequisites


  1. Read the Software module.
  2. You will need the following files, all copied in H:\users\your_userid\lab\ in the first lab section:
    • input file: cblas_dgemmx_w.d or dgemmx.d
    • batch scripts:
      • mklc.xml and mklc.bat or
      • mklf.xml and mklf.bat
    • source files:
      • cblas_dgemmx_w.c and common_func_w.c or
      • dgemmx_w.f and common_func.f
    • dll: libguide40.dll

Instructions for Visual Studio Compile and Link


C/C++

  1. Open Visual Studio 2005 and create a new Visual C++ Project mklc. In the "New Projects" window, choose Visual C++  | Win32 under "Porject Types" and Win32 Console Application under Templates.  Then enter the name as mklc and the location as the lab folder under your home directoryClick OK and then in the next window under Additional Settings click on Empty Project.
  2. Add cblas_dgemmx_w.c and common_func_w.c from your lab folder to the project's Source Files using the menu Project | Add existing Item....
  3. Add the include and library settings to Visual Studio. From the menu choose Tools | Options | Projects and Solutions | Visual C++ Directories. From the "Show directories for:" pull-down menu, choose the option:
    • "Include files":
      Below this selection choose the folder icon, which will give you an input box to add the directory C:\Program Files\Intel\MKL\8.0.1\include.
    • "Library files":
      Below this selection choose the folder icon, which will give you an input box to add the directories C:\Program File\Intel\MKL\8.0.1\ia32\lib and C:\Program Files\Intel\MKL\8.0.1\examples\lapack\lib.
  4. Go into Project | Properties to verify or set the following properties:
    • Make sure the configuration is what you want it to be.  The default of Debug is fine for lab purposes.
    • Add libraries to the project by expanding the Configuration Properties and underneath that Linker, and clicking on Input. In the right pane in Additional Dependencies, type the names of the libraries with a space between each name: libguide40.lib mkl_c.lib mkl_ia32.lib mkl_lapack.lib
  5. Compile and link the executable with Build | Build mklc.  There should be no errors.
  6. Copy the executable you just created (mklc.exe) from mklc\Debug to your lab directory H:\users\your_userid\lab\.

Fortran:

  1. Open Visual Studio 2005 and create a new Fortran Project mklf. In the Templates window choose an Intel Fortran Project | Console Application, entering the name as mklf and the location as the lab folder under your home directoryClick OK and then in the next window under Additional Settings click on Empty Project.
  2. Add dgemmx_w.f and common_func.f from your lab folder to the project's Source Files using the menu Project | Add existing Item....
  3. Add include and library settings to Visual Studio 2005. From the menu navigate Tools | Options | Intel Fortran | General
    • Include files:
      Add C:\Program Files\Intel\MKL\8.0.1\include if it is not already in the list of Includes.  You can do this by either by modifying the field to the right of "Libraries:" (all entries must be separated by semi-colons), or you can click on the "..." button to bring up a more readable view (one entry per line) and edit there. 
    • Library files:
      Add C:\Program File\Intel\MKL\8.0.1\ia32\lib and C:\Program Files\Intel\MKL\8.0.1\examples\lapack\lib if they are not already in the list of Libraries.  You can do this by either by modifying the field to the right of "Libraries:" (all entries must be separated by semi-colons), or you can click on the "..." button to bring up a more readable view (one entry per line) and edit there. 
  4. Navigate to Project | Properties | Linker | Input. Add the libraries to the project by typing
    libguide40.lib mkl_c.lib mkl_ia32.lib mkl_lapack.lib in Additional dependencies (spaces between the names are necessary). In Ignore Specific Library type libc.lib.
  5. Compile and link the executable with Build | Build mklf. There should be no errors.
  6. Copy the executable you just created (mklf.exe) from mklf\Debug to your lab directory H:\users\your_userid\lab\.

Instructions for Command-line Compile and Link

  • Open a command prompt window on a CTC windows login machine:
    Start | All Programs | Accessories | Command Prompt
  • Move to the directory where the source files are located:
    cd  H:\users\your_userid\lab

For Intel C/C++:

  1. call setup_intelc32
  2. call setup_mkl
  3. icl cblas_dgemmx_w.c common_func_w.c mkl_c.lib libguide40.lib mkl_ia32.lib mkl_lapack.lib
    There may be warning messages, but there should be no errors.
  4. You should now have an executable in H:\users\your_userid\lab\ called cblas_dgemmx_w.exe. Rename cblas_dgemmx_w.exe to mklc.exe, because the file mklc.bat used in batch has been written to execute mklc.exe

For Fortran:

  1. call setup_intelf32
  2. call setup_mkl
  3. ifort dgemmx_w.f common_func.f mkl_c.lib libguide40.lib mkl_ia32.lib mkl_lapack.lib
    There may be warning messages, but there should be no errors.
  4. You should now have an executable in H:\users\your_userid\lab\ called dgemmx_w.exe. Rename dgemmx_w.exe to mklf.exe, becasue the file mklf.bat used in batch has been written to execute mklf.exe.

Run in batch

  • Open a command prompt window on a CTC windows login machine:
    Start | All Programs | Accessories | Command Prompt
  • Move to the directory where the .xml and .bat files are located: 
    cd H:\users\your_userid\lab

C\C++:

  1. Edit mklc.xml. Substitue your logind ID for "your_userid". Review the command file, mklc.bat, so that you know what it does (no changes needed). 
  2. Submit the job to the batch scheduler: vsched -s mklc.xml.

Fortran:

  1. Edit mklf.bat. Substitue you logind ID for "your_userid". Review the command file, mklc.bat, so that you know what it does (no changes needed).
  2. Submit the job to the batch scheduler: vsched -s mklf.xml.

Results

C|C++:

  1. The file H:\users\your_userid\lab\output\mklc.stderr should be empty.
  2. The file H:\users\your_userid\lab\output\mklc.stdout should look like the output shown below.
     C B L A S _ D G E M M  EXAMPLE PROGRAM
     INPUT DATA
       M=2  N=5  K=4
       ALPHA=  0.5  BETA= -1.2
       TRANSA = CblasTrans  TRANSB = CblasTrans
       ORDER = CblasRowMajor
       ARRAY A   LDA=2
            1.500     2.220  
            6.300     9.000  
            1.000    -4.000  
            0.200     7.500  
       ARRAY B   LDB=4
            1.000     2.000     3.000     4.000  
            1.000     2.000     3.000     4.000  
            1.000     2.000     3.000     4.000  
            1.000     2.000     3.000     4.000  
            1.000     2.000     3.000     4.000  
       ARRAY C   LDC=5
            0.000     0.000     1.000     1.000     1.000  
            0.000     0.000     1.000     1.000     1.000  
     OUTPUT DATA
       ARRAY C
            8.950     8.950     7.750     7.750     7.750  
           19.110    19.110    17.910    17.910    17.910  
    

Fortran:

  1. The file H:\users\your_userid\lab\output\mklf.stderr should be empty.
  2. The file H:\users\your_userid\lab\output\mklf.stdout should look like the output shown below.
D G E M M  EXAMPLE PROGRAM
 
      INPUT DATA
       M=2  N=5  K=4
       ALPHA= 0.50  BETA=-1.20
       TRANSA=T  TRANSB=T
       ARRAY A   LDA=4
            1.500     2.220
            6.300     9.000
            1.000    -4.000
            0.200     7.500
       ARRAY B   LDB=5
            1.000     2.000     3.000     4.000
            1.000     2.000     3.000     4.000
            1.000     2.000     3.000     4.000
            1.000     2.000     3.000     4.000
            1.000     2.000     3.000     4.000
       ARRAY C   LDC=4
            0.000     0.000     1.000     1.000     1.000
            0.000     0.000     1.000     1.000     1.000
 
      OUTPUT DATA
       ARRAY C
            8.950     8.950     7.750     7.750     7.750
           19.110    19.110    17.910    17.910    17.910