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

Make support for quadruple precision optional #565

Merged
merged 9 commits into from
Nov 15, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,18 @@ jobs:
matrix:
os: [ubuntu-latest, macos-latest]
gcc_v: [9, 10, 11] # Version of GFortran we want to use.
build: [cmake]
include:
- os: ubuntu-latest
gcc_v: 10
build: cmake-inline
- os: ubuntu-latest
gcc_v: 10
build: make
env:
FC: gfortran-${{ matrix.gcc_v }}
GCC_V: ${{ matrix.gcc_v }}
BUILD_DIR: ${{ matrix.build == 'cmake' && 'build' || '.' }}

steps:
- name: Checkout code
Expand Down Expand Up @@ -58,35 +67,32 @@ jobs:
brew link gcc@${GCC_V}

- name: Configure with CMake
if: ${{ contains(matrix.build, 'cmake') }}
run: >-
cmake -Wdev
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_MAXIMUM_RANK:String=4
-DCMAKE_INSTALL_PREFIX=$PWD/_dist
-S . -B build
-S . -B ${{ env.BUILD_DIR }}

- name: Build and compile
run: cmake --build build --parallel
if: ${{ contains(matrix.build, 'cmake') }}
run: cmake --build ${{ env.BUILD_DIR }} --parallel

- name: catch build fail
run: cmake --build build --verbose --parallel 1
if: failure()
run: cmake --build ${{ env.BUILD_DIR }} --verbose --parallel 1
if: ${{ failure() && contains(matrix.build, 'cmake') }}

- name: test
run: ctest --test-dir build --parallel --output-on-failure
if: ${{ contains(matrix.build, 'cmake') }}
run: ctest --test-dir ${{ env.BUILD_DIR }} --parallel --output-on-failure

- name: Install project
run: cmake --install build

- name: Test in-tree builds
if: contains( matrix.gcc_v, '10') # Only test one compiler on each platform
run: |
cmake -DCMAKE_MAXIMUM_RANK=4 .
cmake --build .
cmake --build . --target test
if: ${{ contains(matrix.build, 'cmake') }}
run: cmake --install ${{ env.BUILD_DIR }}

- name: Test manual makefiles
if: contains(matrix.os, 'ubuntu') && contains(matrix.gcc_v, '10')
if: ${{ matrix.build == 'make' }}
run: |
make -f Makefile.manual FYPPFLAGS="-DMAXRANK=4" -j
make -f Makefile.manual test
Expand Down
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ if(CMAKE_Fortran_COMPILER_ID STREQUAL GNU)
add_compile_options(-Wall)
add_compile_options(-Wextra)
add_compile_options(-Wimplicit-procedure)
add_compile_options(-Wconversion-extra)
# -pedantic-errors triggers a false positive for optional arguments of elemental functions,
# see test_optval and https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95446
if(CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 11.0)
Expand Down
6 changes: 5 additions & 1 deletion ci/fpm-deployment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ fypp="${FYPP:-$(which fypp)}"
fyflags="${FYFLAGS:--DMAXRANK=4}"

# Number of parallel jobs for preprocessing
njob="$(nproc)"
if [ $(uname) = "Darwin" ]; then
njob="$(sysctl -n hw.ncpu)"
else
njob="$(nproc)"
fi

# Additional files to include
include=(
Expand Down
1 change: 1 addition & 0 deletions ci/fpm.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ copyright = "2019-2021 stdlib contributors"

[dev-dependencies]
test-drive.git = "https://github.com/fortran-lang/test-drive"
test-drive.tag = "v0.4.0"
18 changes: 18 additions & 0 deletions config/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,24 @@ endif()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" PARENT_SCOPE)

# Check for available features
# Note: users can overwrite the automatic check by setting the value at configure time
include(CheckFortranSourceRuns)
if (NOT DEFINED WITH_QP)
check_fortran_source_runs(
"if (selected_real_kind(33) == -1) stop 1; end"
WITH_QP
)
set(WITH_QP ${WITH_QP} PARENT_SCOPE)
endif()
if (NOT DEFINED WITH_XDP)
check_fortran_source_runs(
"if (any(selected_real_kind(18) == [-1, selected_real_kind(33)])) stop 1; end"
WITH_XDP
)
set(WITH_XDP ${WITH_XDP} PARENT_SCOPE)
endif()

# Export a pkg-config file
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/template.pc"
Expand Down
2 changes: 1 addition & 1 deletion config/cmake/Findtest-drive.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ foreach(method ${${_pkg}_FIND_METHOD})
FetchContent_Declare(
"${_lib}"
GIT_REPOSITORY "${_url}"
GIT_TAG "HEAD"
GIT_TAG "v0.4.0"
)
FetchContent_MakeAvailable("${_lib}")

Expand Down
3 changes: 3 additions & 0 deletions config/template.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
@PACKAGE_INIT@

set("@PROJECT_NAME@_WITH_QP" @WITH_QP@)
set("@PROJECT_NAME@_WITH_XDP" @WITH_XDP@)

if(NOT TARGET "@PROJECT_NAME@::@PROJECT_NAME@")
include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")
endif()
17 changes: 14 additions & 3 deletions doc/specs/stdlib_kinds.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,28 @@ The `stdlib_kinds` module provides kind parameters for the Fortran intrinsic dat

### `sp`

Alias for intrinsic named constant `real32` imported from `iso_fortran_env`.
Single precision real kind parameter.
Provides real kind parameter for floating point numbers with a minimal precision of 6 significant digits.


### `dp`

Alias for intrinsic named constant `real64` imported from `iso_fortran_env`.
Double precision real kind parameter.
Provides real kind parameter for floating point numbers with a minimal precision of 15 significant digits.


### `xdp`

Extended double precision real kind parameter.
Provides real kind parameter for floating point numbers with a minimal precision of 18 significant digits.
If not available it has value `-1`.


### `qp`

Alias for intrinsic named constant `real128` imported from `iso_fortran_env`.
Quadruple precision real kind parameter.
Provides real kind parameter for floating point numbers with a minimal precision of 33 significant digits.
If not available it has value `-1`.


### `int8`
Expand Down
8 changes: 7 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ set(fppFiles
stdlib_bitsets_64.fypp
stdlib_bitsets_large.fypp
stdlib_io.fypp
stdlib_kinds.fypp
stdlib_linalg.fypp
stdlib_linalg_diag.fypp
stdlib_linalg_outer_product.fypp
Expand Down Expand Up @@ -50,11 +51,16 @@ else()
set(fyppFlags "-DVERSION90")
endif()

list(
APPEND fyppFlags
"-DWITH_QP=$<BOOL:${WITH_QP}>"
"-DWITH_XDP=$<BOOL:${WITH_XDP}>"
)

fypp_f90("${fyppFlags}" "${fppFiles}" outFiles)

set(SRC
stdlib_error.f90
stdlib_kinds.f90
stdlib_logger.f90
stdlib_system.F90
stdlib_specialfunctions.f90
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile.manual
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ SRCFYPP = \
stdlib_bitsets_large.fypp \
stdlib_bitsets.fypp \
stdlib_io.fypp \
stdlib_kinds.fypp \
stdlib_linalg.fypp \
stdlib_linalg_diag.fypp \
stdlib_linalg_outer_product.fypp \
Expand Down Expand Up @@ -41,7 +42,6 @@ SRC = f18estop.f90 \
stdlib_specialfunctions.f90 \
stdlib_specialfunctions_legendre.f90 \
stdlib_io.f90 \
stdlib_kinds.f90 \
stdlib_logger.f90 \
stdlib_quadrature_gauss.f90 \
stdlib_strings.f90 \
Expand Down
26 changes: 24 additions & 2 deletions src/common.fypp
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
#:mute

#! Support for quadruple precision floating point numbers
#:if not defined("WITH_QP")
#:set WITH_QP = False
#:endif

#! Support for extended double precision floating point numbers
#:if not defined("WITH_XDP")
#:set WITH_XDP = False
#:endif

#! Real kinds to be considered during templating
#:set REAL_KINDS = ["sp", "dp", "qp"]
#:set REAL_KINDS = ["sp", "dp"]
#:if WITH_XDP
#:set REAL_KINDS = REAL_KINDS + ["xdp"]
#:endif
#:if WITH_QP
#:set REAL_KINDS = REAL_KINDS + ["qp"]
#:endif

#! Real types to be considered during templating
#:set REAL_TYPES = ["real({})".format(k) for k in REAL_KINDS]
Expand All @@ -10,7 +26,13 @@
#:set REAL_KINDS_TYPES = list(zip(REAL_KINDS, REAL_TYPES))

#! Complex kinds to be considered during templating
#:set CMPLX_KINDS = ["sp", "dp", "qp"]
#:set CMPLX_KINDS = ["sp", "dp"]
#:if WITH_XDP
#:set CMPLX_KINDS = CMPLX_KINDS + ["xdp"]
#:endif
#:if WITH_QP
#:set CMPLX_KINDS = CMPLX_KINDS + ["qp"]
#:endif

#! Complex types to be considered during templating
#:set CMPLX_TYPES = ["complex({})".format(k) for k in CMPLX_KINDS]
Expand Down
4 changes: 3 additions & 1 deletion src/stdlib_io.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module stdlib_io
!! Provides a support for file handling
!! ([Specification](../page/specs/stdlib_io.html))

use stdlib_kinds, only: sp, dp, qp, &
use stdlib_kinds, only: sp, dp, xdp, qp, &
int8, int16, int32, int64
use stdlib_error, only: error_stop
use stdlib_optval, only: optval
Expand All @@ -24,9 +24,11 @@ module stdlib_io
FMT_INT = '(*(i0,1x))', &
FMT_REAL_SP = '(*(es15.8e2,1x))', &
FMT_REAL_DP = '(*(es24.16e3,1x))', &
FMT_REAL_XDP = '(*(es26.18e3,1x))', &
FMT_REAL_QP = '(*(es44.35e4,1x))', &
FMT_COMPLEX_SP = '(*(es15.8e2,1x,es15.8e2))', &
FMT_COMPLEX_DP = '(*(es24.16e3,1x,es24.16e3))', &
FMT_COMPLEX_XDP = '(*(es26.18e3,1x,es26.18e3))', &
FMT_COMPLEX_QP = '(*(es44.35e4,1x,es44.35e4))'

interface loadtxt
Expand Down
14 changes: 0 additions & 14 deletions src/stdlib_kinds.f90

This file was deleted.

27 changes: 27 additions & 0 deletions src/stdlib_kinds.fypp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#:include "common.fypp"
!> Version: experimental
!>
!> The specification of this module is available [here](../page/specs/stdlib_kinds.html).
module stdlib_kinds
use iso_fortran_env, only: int8, int16, int32, int64
use iso_c_binding, only: c_bool
implicit none
private
public :: sp, dp, xdp, qp, int8, int16, int32, int64, lk, c_bool

!> Single precision real numbers
integer, parameter :: sp = selected_real_kind(6)

!> Double precision real numbers
integer, parameter :: dp = selected_real_kind(15)

!> Extended double precision real numbers
integer, parameter :: xdp = #{if WITH_XDP}#selected_real_kind(18)#{else}#-1#{endif}#

!> Quadruple precision real numbers
integer, parameter :: qp = #{if WITH_QP}#selected_real_kind(33)#{else}#-1#{endif}#

!> Default logical kind parameter
integer, parameter :: lk = kind(.true.)

end module stdlib_kinds
2 changes: 1 addition & 1 deletion src/stdlib_linalg.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module stdlib_linalg
!!Provides a support for various linear algebra procedures
!! ([Specification](../page/specs/stdlib_linalg.html))
use stdlib_kinds, only: sp, dp, qp, &
use stdlib_kinds, only: sp, dp, xdp, qp, &
int8, int16, int32, int64
use stdlib_optval, only: optval
implicit none
Expand Down
9 changes: 7 additions & 2 deletions src/stdlib_math.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
#:set RC_KINDS_TYPES = REAL_KINDS_TYPES + CMPLX_KINDS_TYPES

module stdlib_math
use stdlib_kinds, only: int8, int16, int32, int64, sp, dp, qp
use stdlib_kinds, only: int8, int16, int32, int64, sp, dp, xdp, qp
use stdlib_optval, only: optval

implicit none
private
public :: clip, gcd, linspace, logspace
public :: EULERS_NUMBER_SP, EULERS_NUMBER_DP, EULERS_NUMBER_QP
public :: EULERS_NUMBER_SP, EULERS_NUMBER_DP
#:if WITH_QP
public :: EULERS_NUMBER_QP
#:endif
public :: DEFAULT_LINSPACE_LENGTH, DEFAULT_LOGSPACE_BASE, DEFAULT_LOGSPACE_LENGTH
public :: arange

Expand All @@ -20,7 +23,9 @@ module stdlib_math
! Useful constants for lnspace
real(sp), parameter :: EULERS_NUMBER_SP = exp(1.0_sp)
real(dp), parameter :: EULERS_NUMBER_DP = exp(1.0_dp)
#:if WITH_QP
real(qp), parameter :: EULERS_NUMBER_QP = exp(1.0_qp)
#:endif

interface clip
#:for k1, t1 in IR_KINDS_TYPES
Expand Down
2 changes: 1 addition & 1 deletion src/stdlib_optval.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module stdlib_optval
!!
!! It is an error to call `optval` with a single actual argument.
!!
use stdlib_kinds, only: sp, dp, qp, int8, int16, int32, int64
use stdlib_kinds, only: sp, dp, xdp, qp, int8, int16, int32, int64
implicit none


Expand Down
2 changes: 1 addition & 1 deletion src/stdlib_quadrature.fypp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#:include "common.fypp"
module stdlib_quadrature
!! ([Specification](../page/specs/stdlib_quadrature.html#description))
use stdlib_kinds, only: sp, dp, qp
use stdlib_kinds, only: sp, dp, xdp, qp

implicit none

Expand Down
1 change: 1 addition & 0 deletions src/stdlib_sorting.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ module stdlib_sorting
int64, &
sp, &
dp, &
xdp, &
qp

use stdlib_optval, only: optval
Expand Down
2 changes: 1 addition & 1 deletion src/stdlib_specialfunctions.f90
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module stdlib_specialfunctions
use stdlib_kinds, only: sp, dp, qp
use stdlib_kinds, only: sp, dp, xdp, qp

implicit none

Expand Down
2 changes: 1 addition & 1 deletion src/stdlib_stats.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module stdlib_stats
!! Provides support for various statistical methods. This includes currently
!! descriptive statistics
!! ([Specification](../page/specs/stdlib_stats.html))
use stdlib_kinds, only: sp, dp, qp, &
use stdlib_kinds, only: sp, dp, xdp, qp, &
int8, int16, int32, int64
implicit none
private
Expand Down
Loading