Skip to content

Commit

Permalink
Merge pull request #13 from FluidNumerics/bugfix/issue-12
Browse files Browse the repository at this point in the history
[WIP] Bugfix/issue 12
  • Loading branch information
fluidnumerics-joe authored Dec 6, 2023
2 parents 72e4ab5 + b5a2937 commit 079accc
Show file tree
Hide file tree
Showing 45 changed files with 657 additions and 236 deletions.
148 changes: 132 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ on:
- 'AUTHORS.md'
- 'LICENSE.md'
- 'README.md'
env:
# Modify this variable to change the ifort compiler version - do NOT hardcode the version
# anywhere else!
INTEL_ONEAPI_VERSION: 2023.2.1

jobs:
test:
timeout-minutes: 5
if: "!contains(github.event.head_commit.message, 'skip ci')"
name: ${{ matrix.os_name }} - ${{ matrix.compiler }} - ${{ matrix.build_type }} - ${{ github.event_name }}
name: ${{ matrix.os_name }} - ${{ matrix.fcompiler }} - ${{ matrix.build_type }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand All @@ -27,58 +32,169 @@ jobs:
# Linux
- os: ubuntu-22.04
os_name: linux
compiler: gfortran-9
fcompiler: gfortran-9
ccompiler: gcc-9
shell: bash
build_type: coverage

- os: ubuntu-22.04
os_name: linux
fcompiler: gfortran-9
ccompiler: gcc-9
shell: bash
build_type: debug

- os: ubuntu-22.04
os_name: linux
fcompiler: gfortran-10
ccompiler: gcc-10
shell: bash
build_type: debug

- os: ubuntu-22.04
os_name: linux
fcompiler: gfortran-11
ccompiler: gcc-11
shell: bash
build_type: debug

- os: ubuntu-22.04
os_name: linux
fcompiler: gfortran-12
ccompiler: gcc-12
shell: bash
build_type: debug

- os: ubuntu-22.04
os_name: linux
compiler: gfortran-10
fcompiler: ifx
ccompiler: icx-cc
shell: bash
build_type: debug

- os: ubuntu-22.04
os_name: linux
compiler: gfortran-11
fcompiler: ifort
ccompiler: icx-cc
shell: bash
build_type: debug

- os: ubuntu-22.04
os_name: linux
fcompiler: gfortran-9
ccompiler: gcc-9
shell: bash
build_type: fpm

- os: ubuntu-22.04
os_name: linux
compiler: gfortran-10
fcompiler: gfortran-10
ccompiler: gcc-10
shell: bash
build_type: fpm

- os: ubuntu-22.04
os_name: linux
fcompiler: gfortran-11
ccompiler: gcc-11
shell: bash
build_type: fpm

- os: ubuntu-22.04
os_name: linux
fcompiler: gfortran-12
ccompiler: gcc-12
shell: bash
build_type: fpm

# - os: ubuntu-22.04
# os_name: linux
# fcompiler: ifx
# ccompiler: icx-cc
# shell: bash
# build_type: fpm

- os: ubuntu-22.04
os_name: linux
fcompiler: ifort
ccompiler: icx-cc
shell: bash
build_type: fpm


# Windows
- os: windows-latest
os_name: windows
fcompiler: gfortran
ccompiler: gcc
shell: 'msys2 {0}'
test_type: debug

defaults:
run:
shell: ${{ matrix.shell }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
# - name: Add msbuild to PATH
# if: ${{ matrix.os_name == 'windows-latest' }}
# uses: microsoft/setup-msbuild@v1.0.2

- uses: msys2/setup-msys2@v2
if: ${{ matrix.os == 'windows-latest' }}
with:
update: true
install: git base-devel mingw-w64-x86_64-toolchain
install: git base-devel mingw-w64-x86_64-toolchain cmake

# - uses: actions/cache@v3
# id: cache
# with:
# path: /opt/intel/oneapi
# key: ${{ matrix.os }}-${{ matrix.fcompiler }}-${{ env.INTEL_ONEAPI_VERSION }}

- name: Install Intel oneAPI Fortran compiler
if: ${{ startsWith(matrix.fcompiler,'if') }}
run: |
# download the key to system keyring
wget -O- https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB \
| gpg --dearmor | sudo tee /usr/share/keyrings/oneapi-archive-keyring.gpg > /dev/null
# add signed entry to apt sources and configure the APT client to use Intel repository:
echo "deb [signed-by=/usr/share/keyrings/oneapi-archive-keyring.gpg] https://apt.repos.intel.com/oneapi all main" | sudo tee /etc/apt/sources.list.d/oneAPI.list
# update package index and install Fortran compiler
sudo apt update -y
sudo apt-get -y install intel-oneapi-compiler-fortran-$INTEL_ONEAPI_VERSION intel-oneapi-dpcpp-cpp-$INTEL_ONEAPI_VERSION
# set environment variables and make them persistent across steps
. /opt/intel/oneapi/setvars.sh
env | grep oneapi >> $GITHUB_ENV
- name: Use existing Intel oneAPI Fortran compiler
if: ${{ startsWith(matrix.fcompiler,'if') }}
run: |
# set environment variables and make them persistent across steps
. /opt/intel/oneapi/setvars.sh
env | grep oneapi >> $GITHUB_ENV
- name: Show version information
run: |
${{ matrix.compiler }} --version
${{ matrix.fcompiler }} --version
${{ matrix.ccompiler }} --version
- name: Build with Cmake
if: ${{ matrix.build_type != 'fpm' }}
run: |
mkdir build
cd build
FC=${{ matrix.compiler }} cmake -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} ../
FC=${{ matrix.fcompiler }} CC=${{ matrix.ccompiler }} cmake -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} ../
make VERBOSE=1
- name: fpm tests
if: ${{ matrix.build_type == 'fpm' }}
run: |
wget https://github.com/fortran-lang/fpm/releases/download/v0.9.0/fpm-0.9.0-linux-x86_64
chmod +x ./fpm-0.9.0-linux-x86_64 && mv ./fpm-0.9.0-linux-x86_64 fpm
./fpm install
./fpm test
./fpm run --example "*"
./fpm install --compiler ${{ matrix.fcompiler }} --c-compiler ${{ matrix.ccompiler }}
./fpm test --compiler ${{ matrix.fcompiler }} --c-compiler ${{ matrix.ccompiler }}
./fpm run --compiler ${{ matrix.fcompiler }} --c-compiler ${{ matrix.ccompiler }} --example "*"
- name: Initialize coverage counters
if: ${{ matrix.build_type == 'coverage' }}
Expand Down Expand Up @@ -114,7 +230,7 @@ jobs:
flags: ctests

- name: Run memory checks with Valgrind (only Linux)
if: ${{ matrix.os_name == 'linux' && matrix.test_type == 'valgrind' }}
if: ${{ matrix.os_name == 'linux' && matrix.test_type == 'debug' }}
run: |
sudo apt-get install -y valgrind
valgrind --error-exitcode=1 -s ./test/testsuite -A
valgrind --error-exitcode=1 -s ./build/test/testsuite -A
17 changes: 16 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,30 @@ ENDIF(NOT CMAKE_Fortran_COMPILER_SUPPORTS_F90)

# Default Fortran compiler flags
# Fortran compiler flags

if( "${CMAKE_Fortran_COMPILER_ID}" STREQUAL "GNU" )
set( CMAKE_Fortran_FLAGS "-cpp -ffree-line-length-512" )
set( CMAKE_Fortran_FLAGS_DEBUG "-g -O0 -C -Wall -fbounds-check -fbacktrace -ffpe-trap=invalid,zero,overflow" )
set( CMAKE_Fortran_FLAGS_COVERAGE "${CMAKE_Fortran_FLAGS_DEBUG} --coverage")
set( CMAKE_Fortran_FLAGS_PROFILE "-pg -O3")
set( CMAKE_Fortran_FLAGS_RELEASE "-O3" )

set( CMAKE_C_FLAGS_COVERAGE "-g -O0 --coverage")

elseif( "${CMAKE_Fortran_COMPILER_ID}" STREQUAL "Intel" )
set( CMAKE_Fortran_FLAGS "-fpp" )
set( CMAKE_Fortran_FLAGS_DEBUG "-O0 -g -debug all -check all -traceback" )
set( CMAKE_Fortran_FLAGS_COVERAGE "${CMAKE_Fortran_FLAGS_DEBUG} -prof-gen=srcpos")
set( CMAKE_Fortran_FLAGS_PROFILE "-O3")
set( CMAKE_Fortran_FLAGS_RELEASE "-O3" )
set( CMAKE_C_FLAGS_COVERAGE "-g -O0")

elseif( "${CMAKE_Fortran_COMPILER_ID}" STREQUAL "IntelLLVM" )
set( CMAKE_Fortran_FLAGS "-fpp" )
set( CMAKE_Fortran_FLAGS_DEBUG "-debug all" )
set( CMAKE_Fortran_FLAGS_COVERAGE "${CMAKE_Fortran_FLAGS_DEBUG}") # Code coverage not available with ifx
set( CMAKE_Fortran_FLAGS_PROFILE "-O3")
set( CMAKE_Fortran_FLAGS_RELEASE "-O3" )
set( CMAKE_C_FLAGS_COVERAGE "-g -O0")
endif()

ADD_SUBDIRECTORY(${CMAKE_SOURCE_DIR}/src)
Expand Down
53 changes: 49 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@ Copyright 2020 Fluid Numerics LLC
[![Build Status](https://github.com/fluidnumerics/feq-parse/actions/workflows/ci.yml/badge.svg)](https://github.com/FluidNumerics/feq-parse/actions)
[![codecov](https://codecov.io/gh/FluidNumerics/feq-parse/graph/badge.svg?token=IBNDDI4MHB)](https://codecov.io/gh/FluidNumerics/feq-parse)

`feqparse` is an equation parser Fortran class that is used to interpret and evaluate functions provided as strings.
`feq-parse` is an equation parser Fortran class that is used to interpret and evaluate functions provided as strings.

[Learn how to contribute to this repository](./CONTRIBUTING.md)

## Installation
`feq-parse` can be installed using either CMake, [Fortran Package Manager (fpm)](https://github.com/fortran-lang/fpm), or with [Spack](https://spack.io).

### Prerequisites
All you need is a Fortran compiler that is compliant with the Fortran 2008 standard and supports C interoperability. You can see which compilers are regularly tested on the [Github actions page](https://github.com/FluidNumerics/feq-parse/actions/workflows/ci.yml)

If you are installing with CMake, you will need to have CMake version 3.0.2 or greated


### CMake
For a quick installation to `/usr/local/feqparse`,
```
cd build/
Expand Down Expand Up @@ -61,13 +69,50 @@ Or, to use a specific version:
feq-parse = { git="https://github.com/FluidNumerics/feq-parse.git", tag = "v1.1.0" }
```

### Spack
The maintainers of this repository also keep the `feq-parse` spack package up to date with the latest releases. This means you can easily install `feq-parse` from source with the [spack package manager](https://spack.io).

To get started with Spack, if you haven't already
```
git clone https://github.com/spack/spack ~/spack
source ~/spack/share/spack/setup-env.sh
spack compiler find
```

To install the latest version of `feq-parse` with spack,
```
spack install feq-parse
```

To install a specific version of feq-parse with spack, e.g.
```
spack install feq-parse@1.1.0
```

Refer to the [spack documentation](https://spack.readthedocs.io/en/latest/) for further guidance on using Spack.

## Usage

!!! note
All functions in the equation string must start with a `\`
> [!NOTE]
> All functions in the equation string must start with a `\`
### Run examples with fpm
> [!NOTE]
> Examples are now included in the `example/` subdirectory
### Demo Program
Included examples
* `scalar_with_scalar_eval.f90` - Creates an equation parser, and evaluates an equation with scalar input and scalar output.
* `array_with_array_eval.f90` - Creates an equation parser, and evaluates an equation with rank 1 array input and rank 1 output.
* `array_with_scalar_eval.f90` - Creates an equation parser, and evaluates an equation with scalar array input and scalar output within a do loop to fill an array of values. This example is to demonstrate the performance difference with using the array evaluation.
* `gaussian_scalar_multivar.f90` - Creates an equation parser, and evaluates an equation with scalar input and scalar output but with multiple independent variables (much like the example shown below).
* `scalar_function_product.f90` - Creates an equation parser, and evaluates an equation with scalar array input and scalar output, and demonstrates multiplication of two functions.

To run the included examples with the fortran package manager,
```
fpm run --example "*"
```

### Simple example with Makefile
*Example Makefile*
```
FC = gfortran
Expand Down
Empty file removed build/.gitkeep
Empty file.
31 changes: 31 additions & 0 deletions example/gaussian_scalar_multivar.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
program gaussian_scalar_multivar

use FEQParse

implicit none
type(EquationParser) :: f
character(LEN=1),dimension(2) :: independentVars
character(LEN=30) :: eqChar
real :: x(2)

! Specify the independent variables
independentVars = (/'x', 'a'/)

! Specify an equation string that we want to evaluate
eqChar = 'f = \exp( -(x^2) ) - a'
! eqChar = 'f = \exp( -(x^2) - a )'
! eqChar = 'f = (x - a)^2 )'

! Create the EquationParser object
f = EquationParser(eqChar,independentVars)

! Evaluate the equation
x(1) = 1.0
x(2) = 1.0
print*, f % evaluate(x)
print*, exp(-1.0) -1.0

! Clean up memory
call f % Destruct()

end program gaussian_scalar_multivar
5 changes: 5 additions & 0 deletions fpm.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,8 @@ main = "scalar_with_scalar_eval.f90"
name = "scalar_function_product"
source-dir = "example"
main = "scalar_function_product.f90"

[[example]]
name = "gaussian_scalar_multivar"
source-dir = "example"
main = "gaussian_scalar_multivar.f90"
Loading

0 comments on commit 079accc

Please sign in to comment.