Github action files and Fortran

Relatively new to github actions I see them being used in the Fortran community but see no repositories or lists pointing to standard components. There is a distributable file for fpm, but not many examples. I am just beginning to put together a list myself and am wondering what the state of the art is and if fortran-lang should host a repository of them.

I find it very appealing that I can copy my .github directory to another github site hosting an fpm package and it immediately builds on Ubunto with ifort/gfortran, MacOS and Windows with gfortran, and rebuilds documenation with ford(1) and all I have to change is the title in the ford.md file.

Are there already existing YML files to install and run doxygen, other compilers, other compilers and containers? Do others find a list of files or pointers to examples would be useful?

I’m currently working on a setup action for Fortran compilers, I got GFortran working with plenty of versions on Ubuntu, MacOS and Windows this way, but haven’t come around to get Intel oneAPI or NVHPC in yet. At least for Linux and MacOS I have working snippets to efficiently install and use Intel oneAPI in a workflow.

Help is definitely welcome, once it becomes a real thing we can move it to the Fortran-lang organization.

8 Likes

NVHPC download is huuuge. I think the best way to implement this for NVHPC is using Gitlab CI/CD and Docker containers. Note that NVIDIA provides official Docker containers here: NVIDIA NGC

2 Likes

Hi -

This Github repo runs CI with gfortran-9 and -10 using Github’s VMs and using ifort and nvfortran using containers (which you are welcome to use too). I moved to containers after finding that downloading and installing the Intel or Fortran compilers on the Github VMs was unhappily slow.

  • Robert
3 Likes

Welcome to the Discourse, @RobertPincus!

Hello, @certik Ondřej! Is it possible to use LFortran under GitHub Actions? Making it work for Linux will be great. Thank you.

1 Like

Easiest would be to install LFortran form the conda-forge channel (feedstock). For GitHub actions there is a workflow to use micromamba for setting up an environment:

2 Likes

Yes, just install it using Conda.

1 Like

An example Github action with LFortran for Windows: brolib/fpm.yml at master · brocolis/brolib · GitHub

2 Likes

Nice! Is it just a binary that you created? We can integrate it with our LFortran CI to create such binaries and host them on our website.

I’m using gfortran on Ubuntu + MacOS and ifort and ifx on Ubuntu:

I agree with @RobertPincus that the installation of the Intel toolchain is very slow, it is in the order of 15 min as far as I remember. Theoretically, one can cache an installation, but I did not figure out how to do that for system packages In the example I’m doing that to avoid compilation of PETSc.

1 Like

@MarDie The slowest part of the oneAPI installation comes from these lines:

124          sudo apt-get install \
125          intel-basekit \
126          intel-oneapi-compiler-dpcpp-cpp-and-cpp-classic intel-oneapi-compiler-fortran \
127          intel-oneapi-openmp intel-oneapi-mkl-devel

Basically, after adding Intel’s package signing key and updating the apt cache, it downloads the .deb packages from Intel’s official oneAPI repo for Ubuntu, then installs them. The packages themselves are huge (on the order of several GiB), so if this has to be done for every single CI workflow, it’s a waste of both time and bandwidth (doing the same thing repeatedly!)

GitHub documentation for build/dependency caches can be accessed here.

Another possible solution is using official oneAPI Docker images that Intel publishes regularly to DockerHub after each compiler release. The documentation for how to use Docker containers in GitHub Action runners can be accessed here. I believe GitLab also supports such a workflow scheme.

For my project, it seems sufficient to install only intel-oneapi-common-vars and intel-oneapi-compiler-fortran. It downloads ~600 MB data and takes ~2 min. Note, however, that I use only the bare ifort and ifx without any other components of oneAPI, which may not be the case for your GitHub Actions.

Here is the script I use to install ifort and ifx on GitHub-hosted ubuntu-latest runners. You need to make sure that your actions can locate ifort / ifx by putting them on your path or making a symlink in, e.g., /usr/bin.

Click to see the script
#!/bin/bash                                                                                          

# do the job in /tmp                                                                                                     
cd /tmp || exit 1        

# use wget to fetch the Intel repository public key
wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB                    
                                                                                                     
# add to your apt sources keyring so that archives signed with this key will be trusted.             
sudo apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB                                                   
                                                                                                     
# optionally, remove the public key                                                                  
rm GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB                                                                 
                                                                                                     
# the installation                                                                                   
echo "deb https://apt.repos.intel.com/oneapi all main" | sudo tee /etc/apt/sources.list.d/oneAPI.list
sudo add-apt-repository "deb https://apt.repos.intel.com/oneapi all main"                            
sudo apt-get update                                                                                  
#sudo apt install intel-basekit intel-hpckit  # Instead of this line, the following line seems to suffice
sudo apt-get install -y intel-oneapi-common-vars intel-oneapi-compiler-fortran    

# source `setvars.sh`
 if [[ -f /opt/intel/oneapi/setvars.sh ]] ; then                                                      
    source /opt/intel/oneapi/setvars.sh > /dev/null ; env | grep intel | sed "s/:\/User.*$//" \      
         | sed 's/^/export /' > "/tmp/setenv.sh"                                                      
    source "/tmp/setenv.sh"     
    # The above lines source `setvars.sh` and save the relevant settings in `/tmp/setenv.sh`. 
    # It may be OK to do only `source /opt/intel/oneapi/setvars.sh`, but my actions need 
    # `/tmp/setenv.sh` out of this script.                                                    
else                                                                                                 
    exit 2                                                                                                                                                                                                         
fi  
2 Likes