Skip to content

Commit

Permalink
Merge pull request #6 from jchristopherson/FPM
Browse files Browse the repository at this point in the history
FPM
  • Loading branch information
jchristopherson authored Nov 22, 2023
2 parents 89210fb + f437837 commit 72a027d
Show file tree
Hide file tree
Showing 24 changed files with 266 additions and 18 deletions.
129 changes: 129 additions & 0 deletions .github/workflows/fpm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
name: fpm

on: [push, pull_request]

jobs:
gcc-build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-11]
gcc_v: [10] # Version of GFortran we want to use.
include:
- os: ubuntu-latest
os-arch: linux-x86_64

- os: macos-11
os-arch: macos-x86_64

env:
FC: gfortran
GCC_V: ${{ matrix.gcc_v }}

steps:
- name: Checkout code
uses: actions/checkout@v1

- name: Install GFortran macOS
if: contains(matrix.os, 'macos')
run: |
ln -s /usr/local/bin/gfortran-${GCC_V} /usr/local/bin/gfortran
which gfortran-${GCC_V}
which gfortran
- name: Install GFortran Linux
if: contains(matrix.os, 'ubuntu')
run: |
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-${GCC_V} 100 \
--slave /usr/bin/gfortran gfortran /usr/bin/gfortran-${GCC_V} \
--slave /usr/bin/gcov gcov /usr/bin/gcov-${GCC_V}
- name: Install fpm
uses: fortran-lang/setup-fpm@v3
with:
fpm-version: 'v0.8.2'

- name: Build the library
run: |
gfortran --version
fpm build
- name: Run tests
run: |
gfortran --version
fpm test
msys2-build:
runs-on: windows-latest
defaults:
run:
shell: msys2 {0}

steps:
- uses: actions/checkout@v2
- uses: msys2/setup-msys2@v2
with:
msystem: MINGW64
update: true
path-type: inherit
install: |
mingw-w64-x86_64-gcc-fortran
mingw-w64-x86_64-fpm
mingw-w64-x86_64-openblas
mingw-w64-x86_64-lapack
- name: fpm build
run: |
gfortran --version
fpm --version
fpm build
- name: fpm test
run: |
fpm test
intel-build:
runs-on: ubuntu-latest
strategy:
fail-fast: false

env:
FPM_FC: ifort
FC: ifort

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Add Intel repository (Linux)
run: |
wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB
sudo apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB
rm GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB
echo "deb https://apt.repos.intel.com/oneapi all main" | sudo tee /etc/apt/sources.list.d/oneAPI.list
sudo apt-get update
- name: Install Intel oneAPI compiler (Linux)
run: |
sudo apt-get install intel-oneapi-compiler-fortran
- name: Setup Intel oneAPI environment
run: |
source /opt/intel/oneapi/setvars.sh
printenv >> $GITHUB_ENV
- name: Install fpm
uses: fortran-lang/setup-fpm@v3
with:
fpm-version: 'v0.8.2'

- name: fpm build
run: |
ifort --version
fpm --version
fpm build --profile debug --flag "-warn nointerfaces"
- name: fpm test
run: |
fpm test --profile debug --flag "-warn nointerfaces"
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ include("${PROJECT_SOURCE_DIR}/cmake/helper.cmake")
add_subdirectory(configure)

# Deal with the dependencies
find_package(BLAS)
find_package(LAPACK)
add_subdirectory(dependencies)

# Source
Expand All @@ -25,6 +27,11 @@ add_fortran_library(
${PROJECT_VERSION_MAJOR}
${NONLIN_SOURCES}
)
target_link_libraries(
${PROJECT_NAME}
${BLAS_LIBRARIES}
${LAPACK_LIBRARIES}
)
link_library(${PROJECT_NAME} ${ferror_LIBRARY} ${ferror_INCLUDE_DIR})
link_library(${PROJECT_NAME} ${linalg_LIBRARY} ${linalg_INCLUDE_DIR})

Expand Down
24 changes: 20 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,30 @@ A library that provides routines to compute the solutions to systems of nonlinea

## Status
[![CMake](https://github.com/jchristopherson/nonlin/actions/workflows/cmake.yml/badge.svg)](https://github.com/jchristopherson/nonlin/actions/workflows/cmake.yml)
[![Actions Status](https://github.com/jchristopherson/nonlin/workflows/fpm/badge.svg)](https://github.com/jchristopherson/nonlin/actions)

## Documentation
Documentation can be found [here](https://jchristopherson.github.io/nonlin/)

## Building NONLIN
[CMake](https://cmake.org/)This library can be built using CMake. For instructions see [Running CMake](https://cmake.org/runningcmake/).

[FPM](https://github.com/fortran-lang/fpm) can also be used to build this library using the provided fpm.toml.
```txt
fpm build
```
The NONLIN library can be used within your FPM project by adding the following to your fpm.toml file.
```toml
[dependencies]
nonlin = { git = "https://github.com/jchristopherson/nonlin" }
```
## External Libraries
Here is a list of external code libraries utilized by this library.
- [BLAS](http://www.netlib.org/blas/)
- [LAPACK](http://www.netlib.org/lapack/)
- [FERROR](https://github.com/jchristopherson/ferror)
- [LINALG](https://github.com/jchristopherson/linalg)

## Example 1
This example solves a set of two equations of two unknowns using a Quasi-Newton type solver. In this example, the solver is left to compute the derivatives numerically.

Expand Down Expand Up @@ -253,7 +273,3 @@ Iterations: 52
Function Evaluations: 101
```
Notice, the convergence tolerance was set to its default value (1e-12).

## TO DO
Additional items to accomplish:
- Constrained optimization routines.
7 changes: 7 additions & 0 deletions dependencies/BLAS/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# If found, use the installed version; else, import the library
if (${BLAS_FOUND})
# Inform the user of what's going on
message(STATUS "BLAS library found.")
else()
message(STATUS "BLAS library not found. The reference BLAS will be used.")
endif()
6 changes: 6 additions & 0 deletions dependencies/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
include("${PROJECT_SOURCE_DIR}/cmake/helper.cmake")
include(FetchContent)

# Get BLAS
add_subdirectory(BLAS)

# Get LAPACK
add_subdirectory(LAPACK)

# Get FERROR
add_subdirectory(ferror)
set(ferror_LIBRARY ${ferror_LIBRARY} PARENT_SCOPE)
Expand Down
27 changes: 27 additions & 0 deletions dependencies/LAPACK/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# If found, use the installed version; else, import the library
if (${LAPACK_FOUND})
# Inform the user of what's going on
message(STATUS "LAPACK library found.")
else()
# Inform the user of what's going on
message(STATUS "LAPACK not found. Downloading the reference LAPACK.")

# Fetch the proper content
FetchContent_Declare(
LAPACK
GIT_REPOSITORY "https://github.com/Reference-LAPACK/lapack"
)

FetchContent_MakeAvailable(LAPACK)

if (WIN32)
if (${BUILD_SHARED_LIBS})
add_custom_command(
TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:lapack>
$<TARGET_FILE_DIR:${PROJECT_NAME}
)
endif()
endif()
endif()
2 changes: 1 addition & 1 deletion docs/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = nonlin
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 1.5.0
PROJECT_NUMBER = 1.5.1

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
32 changes: 32 additions & 0 deletions fpm.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name = "nonlin"
version = "1.5.1"
license = "GPL-3.0"
author = "Jason Christopherson"
maintainer = "Jason Christopherson"
copyright = "Copyright 2017-2023, Jason Christopherson"
description = "A library that provides routines to compute the solutions to systems of nonlinear equations."
homepage = "https://github.com/jchristopherson/nonlin"

[library]
source-dir = "src"

[dependencies]
ferror = { git = "https://github.com/jchristopherson/ferror" }
linalg = { git = "https://github.com/jchristopherson/linalg" }

[dev-dependencies]
fortran_test_helper = { git = "https://github.com/jchristopherson/fortran_test_helper" }

[install]
library = true

[build]
link = ["blas", "lapack"]
auto-executables = false
auto-examples = false
auto-tests = false

[[test]]
name = "nonlin_test"
source-dir = "tests"
main = "nonlin_test.f90"
1 change: 1 addition & 0 deletions src/nonlin_equation_optimizer.f90
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
! nonlin_equation_optimizer.f90

submodule (nonlin_core) nonlin_equation_optimizer
implicit none
contains
! ------------------------------------------------------------------------------
pure module function oe_get_max_eval(this) result(n)
Expand Down
1 change: 1 addition & 0 deletions src/nonlin_equation_solver.f90
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
! nonlin_equation_solver.f90

submodule (nonlin_core) nonlin_equation_solver
implicit none
contains
! ------------------------------------------------------------------------------
pure module function es_get_max_eval(this) result(n)
Expand Down
1 change: 1 addition & 0 deletions src/nonlin_equation_solver_1var.f90
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
! nonlin_equation_solver_1var.f90

submodule (nonlin_core) nonlin_equation_solver_1var
implicit none
contains
! ------------------------------------------------------------------------------
pure module function es1_get_max_eval(this) result(n)
Expand Down
1 change: 1 addition & 0 deletions src/nonlin_fcn1var_helper.f90
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
! nonlin_fcn1var_helper.f90

submodule (nonlin_core) nonlin_fcn1var_helper
implicit none
contains
! ------------------------------------------------------------------------------
module function f1h_fcn(this, x) result(f)
Expand Down
1 change: 1 addition & 0 deletions src/nonlin_fcnnvar_helper.f90
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
! nonlin_fcnnvar_helper.f90

submodule (nonlin_core) nonlin_fcnnvar_helper
implicit none
contains
! ------------------------------------------------------------------------------
module function fnh_fcn(this, x) result(f)
Expand Down
13 changes: 13 additions & 0 deletions src/nonlin_optimize_bfgs.f90
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
! nonlin_optimize_bfgs.f90

submodule (nonlin_optimize) nonlin_optimize_bfgs
use lapack
implicit none

interface
subroutine DSYMV(uplo, n, alpha, a, lda, x, incx, beta, y, incy)
use iso_fortran_env, only : int32, real64
character, intent(in) :: uplo
integer(int32), intent(in) :: n, lda, incx, incy
real(real64), intent(in) :: alpha, beta, a(lda,*), x(*)
real(real64), intent(inout) :: y(*)
end subroutine
end interface

contains
module subroutine bfgs_solve(this, fcn, x, fout, ib, err)
! Arguments
Expand Down
1 change: 1 addition & 0 deletions src/nonlin_optimize_line_search.f90
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
! nonlin_optimize_line_search.f90

submodule (nonlin_optimize) nonlin_optimize_line_search
implicit none
contains
! ------------------------------------------------------------------------------
module subroutine lso_get_line_search(this, ls)
Expand Down
1 change: 1 addition & 0 deletions src/nonlin_optimize_nelder_mead.f90
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
! nonlin_optimize_nelder_mead.f90

submodule (nonlin_optimize) nonlin_optimize_nelder_mead
implicit none
contains
! ------------------------------------------------------------------------------
module subroutine nm_solve(this, fcn, x, fout, ib, err)
Expand Down
1 change: 1 addition & 0 deletions src/nonlin_solve_brent.f90
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
! nonlin_solve_brent.f90

submodule (nonlin_solve) nonlin_solve_brent
implicit none
contains
! ------------------------------------------------------------------------------
module subroutine brent_solve(this, fcn, x, lim, f, ib, err)
Expand Down
1 change: 1 addition & 0 deletions src/nonlin_solve_line_search.f90
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
! nonlin_solve_line_search.f90

submodule (nonlin_solve) nonlin_solve_line_search
implicit none
contains
! ------------------------------------------------------------------------------
module subroutine lss_get_line_search(this, ls)
Expand Down
1 change: 1 addition & 0 deletions src/nonlin_solve_newton.f90
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
! nonlin_solve_newton.f90

submodule (nonlin_solve) nonlin_solve_newton
implicit none
contains
! ------------------------------------------------------------------------------
module subroutine ns_solve(this, fcn, x, fvec, ib, err)
Expand Down
1 change: 1 addition & 0 deletions src/nonlin_solve_newton1var.f90
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
! nonlin_solve_newton1var.f90

submodule (nonlin_solve) nonlin_solve_newton1var
implicit none
contains
! ------------------------------------------------------------------------------
module subroutine newt1var_solve(this, fcn, x, lim, f, ib, err)
Expand Down
Loading

0 comments on commit 72a027d

Please sign in to comment.