Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does mex work on Windows? #29

Closed
zaikunzhang opened this issue Feb 18, 2022 · 4 comments
Closed

Does mex work on Windows? #29

zaikunzhang opened this issue Feb 18, 2022 · 4 comments

Comments

@zaikunzhang
Copy link

Hello!

First of all, thank you very much for making MATLAB available with GitHub Actions. This is life-changing. I have been using it in several research projects.

It is great that v1.1.0 now supports Windows and macOS. I have some actions involving mex (e.g., this one). Both the Linux and macOS versions work perfectly, but the Windows version complain that

 Supported compiler not detected. You can install the freely available MinGW-w64 C/C++ compiler; visit
  https://www.mathworks.com/matlabcentral/fileexchange/52848-matlab-support-for-mingw-w64-c-c-compiler. For more options, visit https://www.mathworks.com/support/compilers.

Did I miss something? How should I configure a GiHub-hosted runner so that mex works?

Thank you very much!

Best regards,
Zaikun

@zaikunzhang
Copy link
Author

zaikunzhang commented Feb 19, 2022

Hello!

Very strangely and fortunately, mex works for C on Windows starting from the second run of my GitHub Action, even though it failed due to the unavailability of a supported compiler during the first run.

However, now I have been trying to make it work for Fortran but failed on both Windows and macOS. How should I configure Windows and macOS runners so that they can mexify Fortran?

Thank you very much again for this great facility!

Best regards,
Zaikun

@zaikunzhang
Copy link
Author

Update:

I tested MEX using another action: https://github.com/equipez/test_gactions/actions/workflows/test_matlab_mex.yml

The same as the other action, MEX works for C on Windows starting from the second run of the action, but fails in the first run. This is very strange.

MEX does not work for Fortran on Windows or macOS for the moment, as we can see here: https://github.com/equipez/test_gactions/actions/runs/1870818916

Thank you very much again!

@mcafaro
Copy link
Member

mcafaro commented Feb 23, 2022

Hi @zaikunzhang,

The MEX command requires the runner have a supported compiler per https://www.mathworks.com/support/requirements/supported-compilers.html.

windows-latest does not include a supported C compiler for MATLAB R2021b. It includes Visual Studio Enterprise 2022 per https://github.com/actions/virtual-environments/blob/main/images/win/Windows2022-Readme.md. MATLAB R2021b requires Visual Studio 2019 or 2017. windows-2019 includes Visual Studio Enterprise 2019.

Neither Windows nor macOS GitHub-hosted runners include a supported Fortran compiler. You would need to install a supported Fortran compiler manually during your build process before calling MEX.

Below is an example config compiling C and Fortran MEX files across all platforms. Note "Intel oneAPI Toolkits" is installed on Windows and macOS to get a supported Fortran compiler. windows-2019 is used to get a supported C compiler.

name: CI
on: [push]
jobs:
  build:
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest, windows-2019]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v2
      
      - name: Install Intel oneAPI Toolkits (macOS)
        run: |
          wget https://registrationcenter-download.intel.com/akdlm/irc_nas/18341/m_HPCKit_p_2022.1.0.86_offline.dmg
          hdiutil attach m_HPCKit_p_2022.1.0.86_offline.dmg
          cd /Volumes/m_HPCKit_p_2022.1.0.86_offline/bootstrapper.app/Contents/MacOS/
          sudo ./install.sh --silent --eula accept --components intel.oneapi.mac.ifort-compiler
          echo "ONEAPI_ROOT=/opt/intel/oneapi" >> $GITHUB_ENV
        if: startsWith(matrix.os, 'macos')
        
      - name: Install Intel oneAPI Toolkits (Windows)
        run: |
          curl.exe --output webimage.exe --url https://registrationcenter-download.intel.com/akdlm/irc_nas/18529/w_HPCKit_p_2022.1.2.116_offline.exe
          start /b /wait webimage.exe -s -x -f webimage_extracted --log extract.log
          del webimage.exe
          webimage_extracted\bootstrapper.exe -s --action install --components=intel.oneapi.win.ifort-compiler --eula=accept -p=NEED_VS2017_INTEGRATION=0 -p=NEED_VS2019_INTEGRATION=0 --log-dir=.
          echo ONEAPI_ROOT=C:\Program Files (x86)\Intel\oneAPI >> %GITHUB_ENV%
        shell: cmd
        if: startsWith(matrix.os, 'windows')
        
      - name: Setup MATLAB
        uses: matlab-actions/setup-matlab@v1
        
      - name: Run MATLAB Command
        uses: matlab-actions/run-command@v1
        with:
          command: |
            mex('-setup', '-v', 'C');
            mex('-v', fullfile(matlabroot,'extern','examples','refbook','timestwo.c'));
            timestwo(1);
            delete('timestwo.mex*');
            
            mex('-setup', '-v', 'FORTRAN');
            mex('-v', fullfile(matlabroot,'extern','examples','refbook','timestwo.F'));
            timestwo(1);
            delete('timestwo.mex*');

@zaikunzhang
Copy link
Author

zaikunzhang commented Feb 23, 2022

Hello @mcafaro ! This is great! Thank you very much for providing the yml.

On the other hand, it turns out that MEX is much slower on macOS than on Linux. I have set up an action to test it and opened an issue according to the results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants