openfast icon indicating copy to clipboard operation
openfast copied to clipboard

Simulink Issue with Visual Studio 2022 and Intel oneAPI 2025.1 (IFX)

Open arthursfs opened this issue 8 months ago • 32 comments

Dear all,

This is a compilation of some notes and issues during the installation of Openfast. The guide that I'm working with is this.

I'm using:

  • Windows 11
  • Visual Studio Community 2022 (LTSC 17.12)
  • Intel Fortran (2025.1.0.602)
  • Git

Also, the following is considered:

  • The compatibility issues between Visual Studio and Intel Fortran are taken into account (as noted by Bonnie Jonkman in issue #1133)
  • The release/debug configuration follows:

Image

So, the notes:

First, one note on the prerequisites. The Intel Fortran Compiler should be downloaded either as part of the toolkit or a stand-alone version with the oneAPI Math Kernel Library. The stand-alone version alone will result in an error in the build step (step 7 of the guide).

Second, after the build is complete, the top of the create_FAST_SFunc.m file reads as follows

% - The 'includeDir' variable must specify the directory that contains the following header files: % "FAST_Library.h", "OpenFOAM_Types.h", "SuperController_Types.h", and "ExtLoadsDX_Types.h"

Actually, the "SuperController_Types.h", and "ExtLoadsDX_Types.h" directories are defined in the lines that follow:

'-I../../../modules/supercontroller/src', ... % needed for visual studio builds to find "SuperController_Types.h" '-I../../../modules/extloads/src', ... % needed for visual studio builds to find "ExtLoadsDX_Types.h"

And there is no path defined for the header "OpenFOAM_Types.h".

arthursfs avatar Apr 18 '25 17:04 arthursfs

Now, in relation to the bug itself. My problem is that when I define a S_function in Simulink, the parameter S-func name defined as FAST_Sfunc does not work. Simulink tells me: Error:Error in S-function 'untitled/S-Function': S-Function 'FAST_Sfunc' does not exist

arthursfs avatar Apr 18 '25 17:04 arthursfs

Which OpenFAST version are you using?

andrew-platt avatar Apr 18 '25 17:04 andrew-platt

Hi, I am using the last one, obtained with git clone

arthursfs avatar Apr 18 '25 17:04 arthursfs

I assume then that you are using the main branch. When did you clone it?

andrew-platt avatar Apr 18 '25 17:04 andrew-platt

openfast /h returns the following:

OpenFAST-v4.0.3-dirty Compile Info:

  • Compiler: Intel(R) Fortran Compiler 20250100
  • Architecture: 64 bit
  • Precision: single
  • OpenMP: No
  • Date: Apr 18 2025
  • Time: 17:11:59 Execution Info:
  • Date: 04/18/2025
  • Time: 18:50:17+0100

I cloned it a week ago.

arthursfs avatar Apr 18 '25 17:04 arthursfs

I'm not sure how soon I can get to debugging this (I don't have a good windows setup to try it on at the moment).

andrew-platt avatar Apr 18 '25 18:04 andrew-platt

Hi,

I can give more information if needed

arthursfs avatar Apr 22 '25 07:04 arthursfs

Generally, if Simulink is telling you an S-Function doesn't exist, I would check that the Matlab path (or current directory) is set properly so that it can find the file it's looking for. In your case, it needs to find FAST_SFunc.mexw64.

bjonkman avatar Apr 23 '25 14:04 bjonkman

Hi,

Sorry, I am having a different error now that I restarted the system. I think now this issue has some similarities with mine. I will reproduce the steps, to see if it sheds some light on my problem

First, I am executing create_FAST_SFunc.m. The output is the following message:

Image

and thus, the folder content is:

Image

Now, when configuring the S-function

Image

The following error appears:

Image

arthursfs avatar Apr 23 '25 18:04 arthursfs

That error indicates that the S-Function cannot find all of its dependent DLLs. FAST_SFunc.mexw64 depends on OpenFAST-Simulink_x64.dll, so that DLL will also need to be on the Matlab path.

bjonkman avatar Apr 23 '25 19:04 bjonkman

Hi, I added the folder with the dll to the path, ran create_FAST_SFunc.m again, but got the same message

arthursfs avatar Apr 24 '25 04:04 arthursfs

To give more information, here follows create_FAST_SFunc.m and the folder with the DLL, that was added to the path:

create_FAST_SFunc.m:

%% INSTRUCTIONS
% This script is used to manually build a Simulink mex file on Windows with Visual Studio. It uses the openfastlib shared
% library (.dll).
%
% If you are using Windows and building with CMake, do not use this script.  Instead use cmake to build the FAST_SFunc.mexXXXX directly.
%
% If you are not using Windows, do not use this script.  Instead use cmake to build the FAST_SFunc.mexXXXX directly.
%
% Alternative building with CMAKE:
% specify -DBUILD_OPENFAST_SIMULINK_API=ON when running cmake
%  - "make FAST_SFunc" will place the resulting mex file at <build-dir>/glue-codes/simulink/FAST_SFunc.mexXXXX
%  - "make install" will place the resulting mex file at install/bin/FAST_SFunc.mexXXXX
%
%
% Before running this script, you must have compiled OpenFAST for Simulink to create a DLL (i.e., a shared library .lib).
% - If the Visual Studio Solution file contained in the vs-build directory was used to create the DLL on Windows,
%   make sure `built_with_visualStudio` is set to true.
% - The name of the library that was generated must match the `libname` variable below
%   and should be located in the directory specified by `libDir`.
% - The `includeDir` variable must specify the directory that contains the following header files:
%   "FAST_Library.h", "OpenFOAM_Types.h", "SuperController_Types.h", and "ExtLoadsDX_Types.h" 
%
% Run `mex -setup` in Matlab to configure a C compiler if you have not already done so.

mexname = 'FAST_SFunc'; % base name of the resulting mex file

built_with_visualStudio = true; %if the libraries were built with cmake, set to false


if (ispc && built_with_visualStudio)   
%% defaults for visual studio builds:

libDir = 'C:\Users\ascolarif\code\openfast\build\bin';
includeDir = 'C:\Users\ascolarif\code\openfast\modules\openfast-library\src';  % needed for visual studio builds to find "FAST_Library.h"
outDir = 'C:\Users\ascolarif\code\openfast\glue-codes\simulink\src';
    
switch computer('arch')
    case 'win64'
        % this is set up for files generated using the x64 configuration of vs-build
        libName = 'OpenFAST-Simulink_x64';

    case 'win32' 
        % this is set up for files generated using the x86
        % configuration of vs-build (win32 will work only on older versions of Matlab)
        libName = 'OpenFAST-Simulink_Win32';
end

else    
%% defaults for cmake builds:

   fprintf( '\n----------------------------\n' );
   fprintf( 'Do not use this script with Mac/Linux.  Follow the CMake instructions at the top of the script instead.' );
   fprintf( '\n----------------------------\n' );

end



if ispc () % Windows PC
   %% BUILD COMMAND
   fprintf( '\n----------------------------\n' );
   fprintf( 'Creating %s\n\n', [outDir filesep mexname '.' mexext] );


    mex('-largeArrayDims', ...
        ... % '-v', ... %add this line for "verbose" output (for debugging)
        ['-L' libDir], ...
        ['-l' libName], ...
        ['-I' includeDir], ...
        '-I../../../modules/supercontroller/src', ... % needed for visual studio builds to find "SuperController_Types.h"
        '-I../../../modules/externalinflow/src',  ... % needed for visual studio builds to find "ExternalInflow_Types.h"
        '-I../../../modules/extloads/src', ... % needed for visual studio builds to find "ExtLoadsDX_Types.h"
        '-outdir', outDir, ...
        ['COMPFLAGS=$COMPFLAGS -MT -DS_FUNCTION_NAME=' mexname], ...
        '-output', mexname, ...
        'FAST_SFunc.c');

end

DLL folder:

Image

arthursfs avatar Apr 24 '25 04:04 arthursfs

Hi, I added the folder with the dll to the path, ran create_FAST_SFunc.m again, but got the same message

Ah, actually it works if I change the directory to where the .DLL is. Just adding it to the path didn't work.

The message now is:

Image

The dialog box accept three parameters. However, I am following this article and didn't understand the relation between the block I/O and these parameters. Is this clarified somewhere?

arthursfs avatar Apr 24 '25 05:04 arthursfs

In the OpenLoop example, I see that the question above is answered:

Image

However, Matlab crashes when the model is executed.

arthursfs avatar Apr 24 '25 08:04 arthursfs

The OpenLoop example is crashing?

andrew-platt avatar Apr 25 '25 18:04 andrew-platt

The OpenLoop example is crashing?

Yes

arthursfs avatar Apr 25 '25 18:04 arthursfs

When that happens, does it close simulink in the process, or does it display an error message?

andrew-platt avatar Apr 25 '25 19:04 andrew-platt

When that happens, does it close simulink in the process, or does it display an error message?

It closes Simulink

arthursfs avatar Apr 25 '25 20:04 arthursfs

This may be an issue related to the IFX compiler, specifically on the Windows platform. We are looking into it, but won't know exactly what the issue is for a bit.

andrew-platt avatar Apr 25 '25 20:04 andrew-platt

Does the simulation run for a bit before closing simulink, or does it close immediately?

If it runs for a bit before closing, then it could be due to a an error while running the simulation. In that case Simulink is closing before letting you know about the error. (related PR #2671)

andrew-platt avatar Apr 25 '25 20:04 andrew-platt

Which version of MATLAB are you using? I didn't see it listed in the thread, but i may have missed it. Check https://www.mathworks.com/support/requirements/previous-releases.html and see if it is compatible with OneAPI 2025.1 as listed in the links in the Compiler column of the table.

deslaughter avatar Apr 25 '25 20:04 deslaughter

One other question, do you have the regression tests in reg_tests/r-test installed? If not, the simulation will close before reporting any issues about not finding the test case.

andrew-platt avatar Apr 25 '25 20:04 andrew-platt

Related #2652

andrew-platt avatar Apr 25 '25 20:04 andrew-platt

I'll have access again next week to see

arthursfs avatar Apr 25 '25 20:04 arthursfs

Which version of MATLAB are you using? I didn't see it listed in the thread, but i may have missed it. Check https://www.mathworks.com/support/requirements/previous-releases.html and see if it is compatible with OneAPI 2025.1 as listed in the links in the Compiler column of the table.

Hi, I am using Matlab 2024b, which is not listed. The link only states that the version 2024a compatible with oneAPI 2024.

One other question, do you have the regression tests in reg_tests/r-test installed? If not, the simulation will close before reporting any issues about not finding the test case.

The folder is empty, oddly. In the Github page, it has the content of the image:

Image

arthursfs avatar Apr 28 '25 07:04 arthursfs

@arthursfs reg_test/r-test points to a git submodule which is effectively a separate repository on GitHub. If you look at the top of the page from your screenshot, you'll see that it's showing the contents of the OpenFAST/r-test repository. To initialize the r-test submodule, open a command prompt inside the folder where you cloned OpenFAST and run git submodule update --init --recursive. Then, the contents of reg_test/r-test will match what's in your screenshot. Afterwards, please try running the Openloop example again.

deslaughter avatar Apr 28 '25 13:04 deslaughter

Hi, for some reason the command git submodule update --init --recursive only copied part of the content, so I manually transferred the ~800 mb from the main branch. It is still crashing...

arthursfs avatar Apr 28 '25 14:04 arthursfs

@arthursfs Is it producing an error or still crashing Simulink? Can you verify that the reg_tests/r-test/glue-codes/openfast/AOC_WSt/AOC_WSt.fst input file and reg_tests/r-test/glue-codes/openfast/AOC directory exist?

deslaughter avatar Apr 28 '25 14:04 deslaughter

Also, you'll need to make sure that MATLAB is in the glue-codes/simulink/examples directory when running Run_OpenLoop.m as it contains a relative path to the input files.

deslaughter avatar Apr 28 '25 14:04 deslaughter

@arthursfs Is it producing an error or still crashing Simulink? Can you verify that the reg_tests/r-test/glue-codes/openfast/AOC_WSt/AOC_WSt.fst input file and reg_tests/r-test/glue-codes/openfast/AOC directory exist?

They exist.

Also, you'll need to make sure that MATLAB is in the glue-codes/simulink/examples directory when running Run_OpenLoop.m as it contains a relative path to the input files.

The S-function dialog box only works if the directory is where the .DLL is. Just adding it to the path didn't work. I'll post tomorrow the message that appears if the path doesnt lead to the .DLL

arthursfs avatar Apr 28 '25 17:04 arthursfs