Skip to content
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
45 changes: 28 additions & 17 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ jobs:
container: snowstep/llvm:jammy

# https://hub.docker.com/r/phhargrove/llvm-flang/tags
- os: ubuntu-24.04-arm
compiler: flang
version: 23
container: phhargrove/llvm-flang:23.1.0-latest-arm64

- os: ubuntu-24.04
compiler: flang
version: 23
Expand Down Expand Up @@ -143,13 +148,8 @@ jobs:
# https://hub.docker.com/r/phhargrove/lfortran/tags
- os: ubuntu-24.04
compiler: lfortran
version: 0.54.0
container: phhargrove/lfortran:0.54.0-1

# - os: ubuntu-24.04
# compiler: lfortran
# version: 0.55.0
# container: phhargrove/lfortran:0.55.0-1
version: 0.55.0
container: phhargrove/lfortran:0.55.0-1
#
# - os: ubuntu-24.04
# compiler: lfortran
Expand Down Expand Up @@ -186,11 +186,6 @@ jobs:
version: 0.62.0
container: phhargrove/lfortran:0.62.0-1

- os: ubuntu-24.04
compiler: lfortran
version: 0.63.0
container: phhargrove/lfortran:0.63.0-1

# https://github.com/lfortran/lfortran/pkgs/container/lfortran
- os: ubuntu-22.04
compiler: lfortran
Expand All @@ -207,6 +202,11 @@ jobs:
version: 0.65.0
container: ghcr.io/lfortran/lfortran:v0.65.0

- os: ubuntu-22.04
compiler: lfortran
version: 0.66.0
container: ghcr.io/lfortran/lfortran:v0.66.0

- os: ubuntu-22.04
compiler: lfortran
version: latest
Expand Down Expand Up @@ -328,10 +328,11 @@ jobs:
if: ${{ runner.os == 'Linux' && runner.arch == 'ARM64' }}
run: |
export FPM_VERSION=0.13.0
mkdir -p fpm-temp/bin
cd fpm-temp
curl --retry 5 -LOsS https://github.com/fortran-lang/fpm/releases/download/v$FPM_VERSION/fpm-$FPM_VERSION.F90
mkdir fpm-temp
gfortran-14 -o fpm-temp/fpm fpm-$FPM_VERSION.F90
echo "PATH=${PWD}/fpm-temp:${PATH}" >> "$GITHUB_ENV"
gfortran-14 -o bin/fpm fpm-$FPM_VERSION.F90
echo "PATH=$PWD/bin:${PATH}" >> "$GITHUB_ENV"

- name: Version info
run: |
Expand Down Expand Up @@ -362,11 +363,21 @@ jobs:
( set +e ; eval fpm run --example invoke-via-macro ${FPM_FLAGS} --flag \"$FFLAGS\" $CHECK_ASSERT )

- name: Test Assertions w/ Parallel Callbacks
if: ${{ matrix.compiler != 'lfortran' || matrix.version != '0.54.0' }} # issue #68, fixed in 0.55
env:
FPM_FLAGS: ${{ env.FPM_FLAGS }} --flag -DASSERT_MULTI_IMAGE --flag -DASSERT_PARALLEL_CALLBACKS
FPM_FLAGS: ${{ env.FPM_FLAGS }} --flag -DTEST_PARALLEL_CALLBACKS
run: |
fpm run --example false-assertion ${FPM_FLAGS} --flag "$FFLAGS"
fpm run --example invoke-via-macro ${FPM_FLAGS} --flag "$FFLAGS"
( set +e ; eval fpm run --example false-assertion ${FPM_FLAGS} --flag \"$FFLAGS\" $CHECK_ASSERT )
( set +e ; eval fpm run --example invoke-via-macro ${FPM_FLAGS} --flag \"$FFLAGS\" $CHECK_ASSERT )

- name: Test Assertions w/ ASSERT_MULTI_IMAGE
if: matrix.compiler == 'gfortran'
env:
FPM_FLAGS: ${{ env.FPM_FLAGS }} --flag -fcoarray=single --flag -DASSERT_MULTI_IMAGE
run: |
fpm run --example false-assertion ${FPM_FLAGS} --flag "$FFLAGS"
fpm run --example invoke-via-macro ${FPM_FLAGS} --flag "$FFLAGS"
( set +e ; eval fpm run --example false-assertion ${FPM_FLAGS} --flag \"$FFLAGS\" $CHECK_ASSERT )
( set +e ; eval fpm run --example invoke-via-macro ${FPM_FLAGS} --flag \"$FFLAGS\" $CHECK_ASSERT )

53 changes: 26 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ preprocessor ASSERTIONS to non-zero, e.g.,
```
fpm build --flag "-DASSERTIONS"
```
The program [example/invoke-via-macro.F90] demonstrates the preferred way to invoke assertions via the three provided macros.
The program [example/invoke-via-macro.F90] demonstrates the preferred way to invoke assertions via the provided macros.
Invoking assertions this way ensures such calls will be completely removed whenever the `ASSERTIONS` macro is undefined (or defined to zero) during compilation.
Due to a limitation of `fpm`, this approach works best if the project using Assert is also a `fpm` project.
If instead `fpm install` is used, then either the user must copy `include/assert_macros.h` to the installation directory (default: `~/.local/include`) or
Expand Down Expand Up @@ -84,7 +84,7 @@ Building and Testing
- [GNU Compiler Collection (GCC) `gfortran`](#gnu-compiler-collection-gcc-gfortran))
- [Intel `ifx`](#intel-ifx))
- [LFortran `lfortran`](#lfortran-lfortran)
- [LLVM `flang-new`](#llvm-flang-new)
- [LLVM `flang`](#llvm-flang)
- [Numerical Algorithms Group (NAG) `nagfor`](#numerical-algorithms-group-nag-nagfor)

### General Build Knobs
Expand All @@ -98,16 +98,19 @@ using syntax like: `fpm --flag "-DASSERTIONS=1"`

* `ASSERT_MULTI_IMAGE`: Controls whether the library attempts to use multi-image
Fortran features (e.g. to report the image number of an assertion failure).
The default is compiler-specific. Multi-image support can be disabled using
`-DASSERT_MULTI_IMAGE=0`.
Default is disabled, multi-image support can be enabled using `-DASSERT_MULTI_IMAGE`.

* `ASSERT_PARALLEL_CALLBACKS`: Controls the use of a callback interface for
multi-process features. Contact us for more details.
### Cray Compiler Environment (CCE) `crayftn`

### Cray Compiler Environment (CCE) `ftn`
Because `fpm` uses the compiler name to determine the compiler identity and because
CCE provides one compiler wrapper, `ftn`, for invoking all compilers, you will
need to invoke `ftn` in a shell script named to identify CCE compiler. For example,
The simplest way to compile with CCE is to invoke the Cray compiler
directly:
```
fpm test --compiler crayftn --profile release
```

If instead you prefer to use the Cray PE compiler wrappers, note that `fpm` uses
the compiler name to determine the compiler identity, so you will
need to invoke `ftn` in a shell script named to identify the CCE compiler. For example,
place a script named `crayftn.sh` in your path with the following contents and with
executable privileges set appropriately:
```
Expand Down Expand Up @@ -136,11 +139,11 @@ The above commands build the Assert library (with the default of assertion enfor
#### Multi-image (parallel) execution
With `gfortran` 14 or later versions and OpenCoarrays installed, use
```
fpm test --compiler caf --profile release --runner "cafrun -n 2"
fpm test --compiler caf --profile release --runner "cafrun -n 2" --flag -DASSERT_MULTI_IMAGE
```
With `gfortran` 13 or earlier versions and OpenCoarrays installed,
```
fpm test --compiler caf --profile release --runner "cafrun -n 2" --flag "-ffree-line-length-0"
fpm test --compiler caf --profile release --runner "cafrun -n 2" --flag "-DASSERT_MULTI_IMAGE -ffree-line-length-0"
```

### Intel `ifx`
Expand All @@ -156,16 +159,16 @@ With Intel Fortran and Intel MPI installed,
fpm test --compiler ifx --profile release --flag "-coarray -DASSERT_MULTI_IMAGE"
```

### LLVM `flang-new`
### LLVM `flang`

#### Single-image (serial) execution
With `flang-new` version 19, use
With LLVM Flang version 19, use
```
fpm test --compiler flang-new --flag "-mmlir -allow-assumed-rank -O3"
```
With `flang-new` version 20 or later, use
With LLVM Flang version 20 or later, use
```
fpm test --compiler flang-new --flag "-O3"
fpm test --compiler flang --flag "-O3"
```

### LFortran `lfortran`
Expand All @@ -180,17 +183,13 @@ fpm test --compiler lfortran --profile release --flag --cpp
#### Single-image (serial) execution
With `nagfor` version 7.1 or later, use
```
fpm test --compiler nagfor --flag -fpp
fpm test --compiler nagfor -DASSERTIONS
```

#### Multi-image execution
With `nagfor` 7.1, use
```
fpm test --compiler nagfor --profile release --flag "-fpp -coarray=cosmp -f2018"
```
With `nagfor` 7.2 or later, use
With `nagfor` 7.1 or later, use
```
fpm test --compiler nagfor --flag -fpp
fpm test --compiler nagfor --flag -DASSERT_MULTI_IMAGE
```

Documentation
Expand Down Expand Up @@ -242,15 +241,15 @@ In the case of gfortran, this appears to have been resolved by default starting
#### Line breaks in macro invocations

The preprocessor is not currently specified by any Fortran standard, and
as of 2025 its operation differs in subtle ways between compilers.
as of 2026 its operation differs in subtle ways between compilers.
One way in which compilers differ is how macro invocations can safely be broken
across multiple lines.

For example, gfortran and flang-new both accept backslash `\` continuation
For example, GNU `gfortran` and LLVM `flang` both accept backslash `\` continuation
character for line-breaks in a macro invocation:

```fortran
! OK for flang-new and gfortran
! OK for flang and gfortran
call_assert_describe( computed_checksum == expected_checksum, \
"Checksum mismatch failure!" \
)
Expand All @@ -276,7 +275,7 @@ Fortran does not support comments with an end delimiter,
only to-end-of-line comments. As such, there is no portable way to safely insert a
Fortran comment into the middle of a macro invocation. For example, the
following seemingly reasonable code results in a syntax error
after macro expansion (on gfortran and flang-new):
after macro expansion (on gfortran and flang):

```fortran
! INCORRECT: cannot use Fortran comments inside macro invocation
Expand Down
9 changes: 4 additions & 5 deletions example/false-assertion.F90
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@ program false_assertion
use assert_m
implicit none

#if ASSERT_PARALLEL_CALLBACKS
#if TEST_PARALLEL_CALLBACKS
assert_this_image => assert_callback_this_image
assert_error_stop => assert_callback_error_stop
#endif

call assert(.false., "false-assertion: unconditionally failing test")

#if ASSERT_PARALLEL_CALLBACKS
#if TEST_PARALLEL_CALLBACKS
! By default, assert uses `THIS_IMAGE()` in multi-image mode while
! composing assertion output, and invokes `ERROR STOP` to print the
! assertion and terminate execution.
!
! The ASSERT_PARALLEL_CALLBACKS preprocessor flag enables the client to replace
! The parallel callbacks features enables the client to replace
! the default use of these two Fortran features with client-provided callbacks.
! To use this feature, the client must build the library with `-DASSERT_PARALLEL_CALLBACKS`,
! and then at startup set the `assert_this_image` and `assert_error_stop`
! To use this feature, the client must ! set the `assert_this_image` and `assert_error_stop`
! procedure pointers to reference the desired callbacks.
contains

Expand Down
13 changes: 2 additions & 11 deletions include/assert_features.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,9 @@
#define _ASSERT_FEATURES_H

! Whether or not the assert library may use multi-image features
! Default is compiler-dependent
! Disabled by default since many compilers require extra arguments to enable multi-image features
#ifndef ASSERT_MULTI_IMAGE
# if defined(__flang__) || defined(__INTEL_COMPILER) || defined(__LFORTRAN__)
# define ASSERT_MULTI_IMAGE 0
# else
# define ASSERT_MULTI_IMAGE 1
# endif
#endif

! Whether the library should use client callbacks for parallel features
#ifndef ASSERT_PARALLEL_CALLBACKS
#define ASSERT_PARALLEL_CALLBACKS 0
#define ASSERT_MULTI_IMAGE 0
#endif

#endif
Loading
Loading