Community
cancel
Showing results for 
Search instead for 
Did you mean: 
french__john
Beginner
268 Views

Very Basic MKL Installation Help Needed -- VS 2017

Please help me get from zero to "Hello World" with the marvelous MKL.

Using LAPACK appears to be a great starting point because I also want to integrate some data curve fitting into an ongoing C++ console application project.

The Visual Studio 2017 Community Property Pages > Configuration Properties lists the "Intel Performance Libraries" category ... Thus I am hopeful the library "installation" is correct and that correctly specifying properties and library paths will perform the necessary magic.

I have "guessed" at these properties  >>

Use Intel MKL: Sequential

Use MPI Library: Intel(R) MPI

The following four .bat files are found here  >> C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2018.1.156\windows\bin

(1) compilervars.bat, (2) compilervars_arch.bat, (3) iclvars.bat, and (4) ipsxe-comp-vars.bat.

How do you choose which .bat file is correct? And (*really dumb*) is "run as administrator" within File Explorer a proper launch point ... or must the .bat file somehow be associated with the particular project? I run my project from within Visual Studio and my command line skills are almost nil. Perhaps the proper .bat file can be listed as an include file and thus properly initialize the project upon execution?

All assistance much appreciated!

 

0 Kudos
9 Replies
TimP
Black Belt
268 Views

The Intel software tools shortcuts installed with your releases should run all those .bat scripts, at least those relevant to what you have installed.  Location of the scripts varies with your Windows version (as Microsoft insisted Intel must do), although the startmenu8 application makes it much the same among versions.

If you have installed only the free MKL, they may be relevant only to putting the MKL .dll library in your PATH.  For command line linking, use of the MKL link advisor applet is relevant.

Ying_H_Intel
Employee
268 Views

Hi John, 
 
​Welcome on board :).  MKL provide all kind of  documentation to help user to use MKL.  
 
 
other doc: MKL getting start:  https://software.intel.com/en-us/get-started-with-mkl-for-windows ;  and MKL user guide etc. 
 
 
​All of the bat file are help to setting environment of intel software tools, any of them should be ok for MKL.  If you install MKl correctly in MSVS 2017,  then you don't need to run those bat files.    
Best Regards,
Ying    
french__john
Beginner
268 Views

Thank you for the comments and links.

I had previously made a beginner's effort with using the MKL link advisor applet and explored the MKL user guide as well as some other links that describe the MKL capabilities and installation. The MKL capabilities are extraordinary and some day I hope to be utilizing threading and various hand shaking(?) options. For now I am wanting success with using LAPACK in its C++ form via the examples Intel has provided. The expertise of the members here is light years beyond my skill set. So please bare with me as I stumble through the description of my problems. Upon success ... I will offer a  summary aimed at helping other complete novices; however, even that will benefit from review as the terminology and precision required is very challenging. It is challenging to drink from a knowledge firehose when only able to handle a sip.

My very limited library experience does include using spline routines found in ALGLIB. I have MKL and VS 2017 installed on the C: drive and usually store all my source code on another drive (drive G:) where I store raw data (info) and my work. (Word & Excel documents, C++ projects, etc.). This data / OS & program drive separation may contribute to some of my difficulties ... so I have also created an MKL test project on the C drive and am having the same difficulties.

ALGLIB Comments (This is "Working")

To succeed with ALGLIB I did the following >>

The ALGLIB was treated as "data" and placed on the G: drive (path shown below).

Within the project Settings I added the path "G:\jtfre\C++ Library Files\ALGLIB\cpp\src" to each of:  a) Include Directories, b) Library Directories, and c) Source Directories. The "src" folder includes both ALGLIB header files and .cpp files. Providing just the path was sufficient for the header files and I was not forced to import the ALGLIB headers into the project. However, I only had success after importing all of the ALGLIB's .cpp source files individually into the project. I was able to place these source files in a filter (folder) I named "AlgLib Source Files". Even the ALGLIB routines not being utilized had to be imported. I guess to match each header file. And there was so much header file cross referencing ... I gave up trying to sort out some type of minimum necessary group of headers and source files. There were some online guidance stating to import all of the library files. Without this online help ... I had no chance at success. 

There was much stumbling about to arrive at the above and the bottom line is ALGLIB is working. I am enjoying the spline capabilities using alglib::spline1dbuildcubic() and alglib::spline1dcalc(). Also created static place holders of type alglib::spline1dinterpolant for each spline and static place holders of type alglib::real_1d_array for each spline's AX and AY arrays. This allows each spline to be built and stored then followed by multiple calls to the calculation routine. The ability to specify each spline's endpoints 1st derivative is very powerful. The ALGLIB spline capabilities far exceed what I am am currently using.

MKL Comments (Help Needed!)

The MKL was installed on the C: drive.

Then VS 2017 Community was installed on C: drive. The integration is apparent in that within a project's Property Settings the option of "Intel Performance Libraries" is present. I have selected the "Sequential" option under "Use Intel(R) MKL".

An MKL example source file was placed into two new projects (one on each drive). (This  file duplicated below.) The only modification is the addition of "//" on the top line to comment out the non-executable line.

Observed is this error >>

1>c:\users\jtfre\source\repos\test_mkl_2.cpp(27): fatal error C1083: Cannot open include file: 'mkl.h': No such file or directory
I find mkl.h in this path >> C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2018\windows\mkl\include

I have added the mkl.h as an existing item.

The mkl.h "includes" other header files ... so I also added all of them to the project as well.

Checking the mkl.h header files properties shows the it is not excluded.

The above path has been added to a) Include Directories, b) Library Directories, and c) Source Directories.

Still the error persists.

Many hours of searching over several days ... to no avail. :(

 

The example >>

//==============================================================
//
// SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT,
//
// Copyright 2016 Intel Corporation
//
// THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT
// NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS.
//
// =============================================================
/*******************************************************************************
*   This example computes real matrix C=alpha*A*B+beta*C using Intel(R) MKL 
*   function dgemm, where A, B, and C are matrices and alpha and beta are 
*   scalars in double precision. 
*
*   In this simple example, practices such as memory management, data alignment, 
*   and I/O that are necessary for good programming style and high MKL 
*   performance are omitted to improve readability.
********************************************************************************/
 
#define min(x,y) (((x) < (y)) ? (x) : (y))
 
#include <stdio.h>
#include <stdlib.h>
#include "mkl.h"
 
int main()
{
    double *A, *B, *C;
    int m, n, p, i, j;
    double alpha, beta;
 
    printf ("\n This example computes real matrix C=alpha*A*B+beta*C using \n"
            " Intel(R) MKL function dgemm, where A, B, and  C are matrices and \n"
            " alpha and beta are double precision scalars\n\n");
 
    m = 2000, p = 200, n = 1000;
    printf (" Initializing data for matrix multiplication C=A*B for matrix \n"
            " A(%ix%i) and matrix B(%ix%i)\n\n", m, p, p, n);
    alpha = 1.0; beta = 0.0;
 
    printf (" Allocating memory for matrices aligned on 64-byte boundary for better \n"
            " performance \n\n");
    A = (double *)mkl_malloc( m*p*sizeof( double ), 64 );
    B = (double *)mkl_malloc( p*n*sizeof( double ), 64 );
    C = (double *)mkl_malloc( m*n*sizeof( double ), 64 );
    if (A == NULL || B == NULL || C == NULL) {
        printf( "\n ERROR: Can't allocate memory for matrices. Aborting... \n\n");
        mkl_free(A);
        mkl_free(B);
        mkl_free(C);
        return 1;
    }
 
    printf (" Intializing matrix data \n\n");
    for (i = 0; i < (m*p); i++) {
        A = (double)(i+1);
    }
 
    for (i = 0; i < (p*n); i++) {
        B = (double)(-i-1);
    }
 
    for (i = 0; i < (m*n); i++) {
        C = 0.0;
    }
 
    printf (" Computing matrix product using Intel(R) MKL dgemm function via CBLAS interface \n\n");
    cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, 
                m, n, p, alpha, A, p, B, n, beta, C, n);
    printf ("\n Computations completed.\n\n");
 
    printf (" Top left corner of matrix A: \n");
    for (i=0; i<min(m,6); i++) {
        for (j=0; j<min(p,6); j++) {
            printf ("%12.0f", A[j+i*p]);
        }
        printf ("\n");
    }
 
    printf ("\n Top left corner of matrix B: \n");
    for (i=0; i<min(p,6); i++) {
        for (j=0; j<min(n,6); j++) {
            printf ("%12.0f", B[j+i*n]);
        }
        printf ("\n");
    }
    
    printf ("\n Top left corner of matrix C: \n");
    for (i=0; i<min(m,6); i++) {
        for (j=0; j<min(n,6); j++) {
            printf ("%12.5G", C[j+i*n]);
        }
        printf ("\n");
    }
 
    printf ("\n Deallocating memory \n\n");
    mkl_free(A);
    mkl_free(B);
    mkl_free(C);
 
    printf (" Example completed. \n\n");
    return 0;
}
 

 

Ying_H_Intel
Employee
268 Views

Hi John,

From your description, it seems you have add MKL include path C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2018\windows\mkl\include in your projects's property :  Include Directories,  but the compiler still report : fatal error C1083: Cannot open include file: 'mkl.h': No such file or directory. 

May you please attach your solution file here or  Online Service Center  so we can see the exact problem.

Best Regards,

Ying

french__john
Beginner
268 Views

Ying --

The .sln file is attached.

*Thank you* (and any others) for taking the time investigating this problem.

The .sln file reflects attempts I have made to resolve the problem and it is not as clean as possible.

My novice level mistakes or omissions are most likely the culprit.

For me ... each incremental exploration of the MKL is upping my game considerably and I am very grateful for the assistance.

-- John

french__john
Beginner
268 Views

I think I have stumbled upon a fix for the LAPACK usage in my specific case.

Within:    Settings > C/C++ > Preprocessor > Preprocessor Definitions

The following was added:

ADD_;HAVE_LAPACK_CONFIG_H;LAPACK_COMPLEX_STRUCTURE;

Making the entire preprocessor definitions setting:

ADD_;HAVE_LAPACK_CONFIG_H;LAPACK_COMPLEX_STRUCTURE;WIN32;NDEBUG;_CONSOLE;_USE_MATH_DEFINES;%(PreprocessorDefinitions)

This fix was found here >>  http://icl.cs.utk.edu/lapack-forum/archives/lapack/msg01612.html

------------------------------------------------------------------------------

Should these preprocessor definitions be automatically added when one invokes the MKL usage?

Specifically, when one goes into Settings >> Intel Performance Libraries >> Intel (R) Math Kernel Library >> Use Intel (R) MKL ... and sets the option to "sequential" (as I have done) ... then the above is required(?) and the additional definitions inclusion can hopefully be automated.

Are same/similar definitions also needed for the MKL options "parallel" and "cluster"?

Within the MKL ... are other than LAPACK routines in need of similar definitions? i.e. Deep Neural Network Functions, Statistical Functions, etc.

These questions are way beyond my skill set/experience.

I again thank everyone who spent time reading through my challenging situation ... especially those who responded above!

french__john
Beginner
268 Views

Please pardon my premature suggestion a "fix" was found. (Fighting a bout of flu does not make for the clearest of thinking.)

I realized afterwards that I had circumvented the process of using only the "Intel Performance Library" settings/switches. The fix I referred to only worked because I jumped back into another of several "test" projects and that one had an auxiliary folder containing an old, stand alone collection of LAPACK library files and library links in the settings.

Trying again with the below example resulted in failure.

I am hoping is that an experienced programmer will create a new and empty C++ project in VS 2017 using the single file example below and document the steps necessary to get all the linking and settings working correctly.

Step #1: New, empty C++ project.

Step #2: Create C++ file and copy example into it. Add file to project.

Step #3: Configuration Properties > Intel Performance Libraries > Intel (R) Math Kernel Library > Use Intel (R) MKL > Sequential

Additional Steps ???

This example is an Intel published example and I think its solution is one that is most common for simpler cases of data curve fitting using polynomials. Note: I prefer using a single right side Y value vector and slight modification of the code to print the coefficients ... but just keeping with the exact example "as is" is a best starting point.

I am hopeful that implementation of the high end numerical methods provided by Intel is made much simpler. They can teach as well as perform ... but only once one learns enough to join the journey.

=====================================

The following provides the specific curve fitting example that I think is a great starting point >>

1) https://software.intel.com/sites/products/documentation/doclib/mkl_sa/11...

2) Then click/select in left column menu "Routines and Examples Index"

3) Find "?gesv" in the column labelled "Routines" ... and then click/select "dgesv" in the column labeled "Examples".

=====================================

Ying_H_Intel
Employee
268 Views

Hi John,

Step #3: Configuration Properties > Intel Performance Libraries > Intel (R) Math Kernel Library > Use Intel (R) MKL > Sequential

originally, the step 3 should be fine to link all mkl into your project. 

But maybe there is integration error, between intel software and MSVC.  please see integration to MVSC 2017.

So You may switch off the step 3, then  try manually link your application with mkl follow by this KB article recipe, i hope this help.

thanks,

Ying

Ying_H_Intel
Employee
268 Views

Hi John, 

I attach one sample solution for your reference in the thread. 

 https://software.intel.com/en-us/forums/intel-math-kernel-library/topic/753946#comment-1916791

Best Regards,

Ying