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

Fix fpm tests program and add fpm tests to ci #6

Merged
merged 4 commits into from Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 16 additions & 1 deletion .github/workflows/ci.yml
Expand Up @@ -40,6 +40,11 @@ jobs:
compiler: gfortran-11
shell: bash
build_type: debug
- os: ubuntu-22.04
os_name: linux
compiler: gfortran-10
shell: bash
build_type: fpm
defaults:
run:
shell: ${{ matrix.shell }}
Expand All @@ -59,12 +64,21 @@ jobs:
run: |
${{ matrix.compiler }} --version

- name: Build
- name: Build with Cmake
if: ${{ matrix.build_type != 'fpm' }}
run: |
cd build
FC=${{ matrix.compiler }} 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 run --example "*"

- name: Initialize coverage counters
if: ${{ matrix.build_type == 'coverage' }}
run: |
Expand All @@ -74,6 +88,7 @@ jobs:
--zerocounters

- name: Run ctests
if: ${{ matrix.build_type != 'fpm' }}
run: |
cd build/test
ctest || ctest --rerun-failed --output-on-failure
Expand Down
5 changes: 5 additions & 0 deletions README.md
Expand Up @@ -43,6 +43,11 @@ fpm build --profile release
fpm test --profile release
```

You can also run the examples included in the `example/` subdirectory :
```
fpm run --example "*"
```

To use `feq-parse` within your fpm project, add the following to your `fpm.toml` file:
```toml
[dependencies]
Expand Down
36 changes: 36 additions & 0 deletions example/array_with_array_eval.f90
@@ -0,0 +1,36 @@
program array_with_array_eval

use FEQParse

implicit none
integer,parameter :: N = 10000000
type(EquationParser) :: f
character(LEN=1),dimension(1) :: independentVars
character(LEN=30) :: eqChar
real :: x(1:N,1)
real :: feval(1:N)
integer :: i
real :: t1,t2

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

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

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

! Evaluate the equation
call cpu_time(t1)
do i = 1,N
x(i,1) = -1.0_real32 + (2.0_real32)/real(N,real32)*real(i - 1,real32)
end do
feval = f % evaluate(x)
call cpu_time(t2)
print *, "runtime :", (t2 - t1)," s"

! Clean up memory
call f % Destruct()

end program array_with_array_eval
36 changes: 36 additions & 0 deletions example/array_with_scalar_eval.f90
@@ -0,0 +1,36 @@
program array_with_scalar_eval

use FEQParse

implicit none
integer,parameter :: N = 100000
type(EquationParser) :: f
character(LEN=1),dimension(1) :: independentVars
character(LEN=30) :: eqChar
real :: x(1)
real :: feval(1:N)
integer :: i
real :: t1,t2

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

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

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

! Evaluate the equation
call cpu_time(t1)
do i = 1,N
x(1) = -1.0_real32 + (2.0_real32)/real(N,real32)*real(i - 1,real32)
feval(i) = f % evaluate(x)
end do
call cpu_time(t2)
print *, "runtime :", (t2 - t1)," s"

! Clean up memory
call f % Destruct()

end program array_with_scalar_eval
27 changes: 27 additions & 0 deletions example/scalar_with_scalar_eval.f90
@@ -0,0 +1,27 @@
program scalar_with_scalar_eval

use FEQParse

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

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

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

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

! Evaluate the equation
x(1) = 0.0
print*, f % evaluate(x)

! Clean up memory
call f % Destruct()

end program scalar_with_scalar_eval
17 changes: 16 additions & 1 deletion fpm.toml
Expand Up @@ -15,4 +15,19 @@ auto-tests = true
source-dir = "src"

[install]
library = true
library = true

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

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

[[example]]
name = "scalar_with_scalar_eval"
source-dir = "example"
main = "scalar_with_scalar_eval.f90"
4 changes: 2 additions & 2 deletions test/test.f90
Expand Up @@ -10,7 +10,7 @@ program test

contains


include "abs_r1fp32.f90"
include "abs_r1fp64.f90"
include "abs_sfp32.f90"
include "abs_sfp64.f90"
Expand Down Expand Up @@ -73,4 +73,4 @@ program test



end program testinclude "abs_r1fp32.f90"
end program test