Forum > Packages and Libraries

intel Mkl Oneapi (library usage)

(1/3) > >>

sedsil:
Dear All,
I used to use Turbo Pascal. I am a new user of Lazarus 4.0. I can not resolve to add the Intel MKL library to Lazarus. On the windows 10, I have defined PATH  "C:\Program Files (x86)\Intel\oneAPI\mkl\latest\bin". This folder contains mkl_rt.2.dll and mkl_rt.dll. my code is like that: ********************************************
program MKLEigenSolver;
{$mode objfpc}{$H+}
{$APPTYPE CONSOLE}

uses
  Windows, SysUtils;

type
  TLAPACKE_dsyev = function(layout: Integer; jobz, uplo: Char;
                           n: Integer; a: PDouble; lda: Integer;
                           w: PDouble): Integer; cdecl;

const
  MKL_PATH = 'C:\Program Files (x86)\Intel\oneAPI\mkl\latest\bin\';
  LAPACK_ROW_MAJOR = 101;

var
  hMKL: HMODULE;
  dsyevFunc: TLAPACKE_dsyev;
  A: array[0..8] of Double = (
    4.0, 1.0, 0.5,
    1.0, 3.0, 1.0,
    0.5, 1.0, 2.0
  );
  W: array[0..2] of Double;
  i: Integer;

begin
  try
    // Load only the main MKL DLL
    WriteLn('Loading MKL runtime...');

    // Try loading in preferred order
    hMKL := LoadLibrary(PChar(MKL_PATH + 'mkl_rt.2.dll'));
    if hMKL = 0 then
      hMKL := LoadLibrary(PChar(MKL_PATH + 'mkl_rt.dll'));

    if hMKL = 0 then
    begin
      WriteLn('ERROR: Failed to load MKL runtime library');
      WriteLn('Please ensure either mkl_rt.2.dll or mkl_rt.dll exists in:');
      WriteLn(MKL_PATH);
      ReadLn;
      Exit;
    end;

    // Get function pointer
    WriteLn('Locating dsyev function...');
    dsyevFunc := TLAPACKE_dsyev(GetProcAddress(hMKL, 'LAPACKE_dsyev'));
    if not Assigned(dsyevFunc) then
    begin
      WriteLn('ERROR: Failed to find required function');
      FreeLibrary(hMKL);
      ReadLn;
      Exit;
    end;

    // Compute eigenvalues
    WriteLn('Calculating eigenvalues...');
    if dsyevFunc(LAPACK_ROW_MAJOR, 'N', 'U', 3, @A[0], 3, @W[0]) = 0 then
    begin
      WriteLn(#13#10'RESULTS:');
      for i := 0 to 2 do
        WriteLn(Format('λ%d = %.6f', [i+1, W]));
    end
    else
      WriteLn('ERROR: Eigenvalue computation failed');

  except
    on E: Exception do
      WriteLn('FATAL ERROR: ', E.ClassName, ' -> ', E.Message);
  end;

  if hMKL <> 0 then
    FreeLibrary(hMKL);

  WriteLn(#13#10'Press Enter to exit...');
  ReadLn;
end.
***************************************
the output for the error message is attached. Could you direct me to solve this matter?

marcov:
Maybe the library needs some initializer? Some exception occurs in the DLL.

Zvoni:

--- Quote ---C:\Program Files (x86)\Intel\oneAPI\mkl\latest\bin
--- End quote ---
32-Bit vs. 64-Bit?
What's the Compile-Target?

EDIT: Ignore the above. Just saw his LoadLibrary-Call, which apparently works.
So my money is on wrong native FreePascal-Types used.
Maybe use ctypes-unit and its types?

marcov:

--- Quote from: Zvoni on July 03, 2025, 01:53:36 pm ---
--- Quote ---C:\Program Files (x86)\Intel\oneAPI\mkl\latest\bin
--- End quote ---
32-Bit vs. 64-Bit?
What's the Compile-Target?

--- End quote ---

No, then the library wouldn't load and loadlibrary and getprocaddress calls would fail

Zvoni:

--- Quote from: marcov on July 03, 2025, 01:55:49 pm ---
--- Quote from: Zvoni on July 03, 2025, 01:53:36 pm ---
--- Quote ---C:\Program Files (x86)\Intel\oneAPI\mkl\latest\bin
--- End quote ---
32-Bit vs. 64-Bit?
What's the Compile-Target?

--- End quote ---

No, then the library wouldn't load and loadlibrary and getprocaddress calls would fail

--- End quote ---
Yeah, see my edit above. Noticed that, too

I've found this in the lapacke_config.h-file

--- Code: C  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---#ifndef lapack_int   #if defined(LAPACK_ILP64)   #define lapack_int              long   #else   #define lapack_int              int#endif

Navigation

[0] Message Index

[#] Next page

Go to full version