Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Bomble__Laetitia
Beginner
82 Views

Using MKL on a mixed c++/Fortran code

Jump to solution

Hello,

I have a code that is a mix of c++ and fortran (c++ is calling fortran as library). The Fortran part was using netlib lapack library. I would like to  move to MKL library.

I use GNU compiler (gfortran for fortran part, g++ for cpp and linking the whole).

I compile each part with the proper  compilation  option ( -fdefault-integer-8 -m64  -I/ for fortran file and -DMKL_ILP64 -m64 -I for c++).  For the linking line I put options of fortran and cpp.

The compilation succeed all right. The problem is when I execute: the cpp code call the fortran code giving it arguments. The integer arguments have now a issue, they are not passed properly and take wrong values.

Is it because of the -fdefault-integer-8 fortran option? Does it make cpp and fortran integer incompatible?

Thanks for insights

0 Kudos

Accepted Solutions
mecej4
Black Belt
55 Views

Laetitia, as a user you can choose whether to use 8-byte integer arguments (ILP64 model) or 4-byte integer arguments (LP64), and MKL supports both choices. So do GNU Fortran and C/C++, provided you use the correct options and your code is written with an awareness of the two models (LP64/ILP64).

Using 8-byte integers when they are not really required for the current applications does have performance penalties, both in memory consumption and run times.

I routinely use MKL on Windows and Linux using the LP64 model.

View solution in original post

5 Replies
mecej4
Black Belt
72 Views

You did not state so explicitly, but you seem to be using a Linux system. Correct?

You are calling Fortran subprograms from C/C++, and the Fortran subprograms are, in turn, calling MKL or Lapack routines, passing 8-byte integer arguments. You notice that those 8-byte integer arguments have incorrect values when the Fortran routines are entered. Since this occurs prior to calling the MKL or Lapack routines, the issue has nothing to do with whether you use MKL or Lapack from Netlib or elsewhere.

When it appeared that things were working correctly, were you passing 8-byte integers from C++ to Fortran? Do you declare the relevant variables as 8-byte integers in the C++ code?

Do you really require 8-byte integers? Are you aware that the option -DMKL_ILP64 will have no effect on your compiled C++ code unless there are embedded preprocessor directives in your C++ source files to make the integer arguments to Lapack calls to be 8-byte integers if MKL_ILP64 is defined or has the value TRUE?

 

Bomble__Laetitia
Beginner
67 Views

Hi, Thank for your answer

 

>You did not state so explicitly, but you seem to be using a Linux system. Correct?

yes, indeed

>. Since this occurs prior to calling the MKL or Lapack routines, the issue has nothing to do with whether you use MKL or Lapack from Netlib or elsewhere.

well I was not having this problem when using netlib. And with netlib I was not using 8 bytes integer, I added this option because it os needed to compile with mkl.

>Do you declare the relevant variables as 8-byte integers in the C++ code?

hum, not sure... the cpp part is huge and not mine, to be honest I don't get it well, I'll try to investigate.

>Do you really require 8-byte integers?

MKL compile with gfortran require it (https://software.intel.com/content/www/us/en/develop/tools/oneapi/components/onemkl/link-line-adviso...).

> Are you aware that the option -DMKL_ILP64 will have no effect on your compiled C++ code unless there are embedded preprocessor directives in your C++ source files to make the integer arguments to Lapack calls to be 8-byte integers if MKL_ILP64 is defined or has the value TRUE?

No I am not. However I compile cpp with mkl for a try but it should be useless right? Cause it's the fortran part that is calling MKL not the cpp part.

Thank you very much for your insights.

mecej4
Black Belt
56 Views

Laetitia, as a user you can choose whether to use 8-byte integer arguments (ILP64 model) or 4-byte integer arguments (LP64), and MKL supports both choices. So do GNU Fortran and C/C++, provided you use the correct options and your code is written with an awareness of the two models (LP64/ILP64).

Using 8-byte integers when they are not really required for the current applications does have performance penalties, both in memory consumption and run times.

I routinely use MKL on Windows and Linux using the LP64 model.

View solution in original post

Bomble__Laetitia
Beginner
47 Views

>Laetitia, as a user you can choose whether to have to use 8-byte integer arguments (ILP64 model) or 4-byte integer arguments (LP64), and MKL supports both choice

Indeed! I missed that point. Thank you very much.  It execute very well know.

Best

RahulV_intel
Moderator
32 Views

Hi @Bomble__Laetitia,

 

As rightly pointed out by @mecej4, MKL supports both 4-byte/8-byte integer arguments.

Since your issue is resolved, I will go ahead and close this thread from my end. Further discussions on this thread will be considered community only.

 

Thanks,

Rahul