Skip to content

Commit 02b2d2f

Browse files
author
Damian Rouson
committed
doc: update top-level & examples-dir README files
1 parent 40a0551 commit 02b2d2f

File tree

2 files changed

+91
-25
lines changed

2 files changed

+91
-25
lines changed

README.md

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,47 +32,36 @@ Use Cases
3232
2. Postconditions (assurances): expressions that must evaluate to `.false.`
3333
3. Invariants: universal pre- and postconditions that must always be true when all procedures in a class or package start or finish executing.
3434

35-
### Examples
36-
See the [./example](./example) subdirectory.
3735

3836
Downloading, Building, and Running Examples
3937
-------------------------------------------
40-
Prerequisites:
38+
39+
### Prerequisites
4140
1. A Fortran 2018 compiler (recent Cray, Intel, GNU, and NAG compiler versions suffice).
4241
2. The [Fortran Package Manager](https://github.com/fortran-lang/fpm).
4342
3. _Optional_: [OpenCoarrays] for parallel execution with the GNU Fortran compiler.
4443

45-
### Single-image execution
44+
### Downloading and Building
45+
46+
#### Building for single-image (serial) execution
4647
```
4748
git clone [email protected]:sourceryinstitute/assert
4849
cd assert
49-
fpm run --example simple_assertions
50-
fpm run --example derived_type_diagnostic
51-
```
52-
where the `fpm run` automatically invokes `fpm build` if necessary, .e.g., the `fpm` source has
53-
changed since the most recent build. If `assert` is working correctly, the first `fpm run` above
54-
will error-terminate with the character stop code
55-
```
56-
Assertion "x > 0" failed on image 1 with diagnostic data "-1.00000000"
57-
```
58-
and the second `fpm run` above will error-terminate with the character stop code
59-
```
60-
Assertion "stuff_t%z(): self%defined()" failed on image 1 with diagnostic data "(none provided)"
50+
fpm build
6151
```
6252

63-
### Multi-image execution with `gfortran` and OpenCoarrays
53+
#### Building for multi-image (parallel) execution
54+
With `gfortran` and OpenCoarrays installed,
6455
```
65-
git clone [email protected]/sourceryinstitute/assert
56+
git clone [email protected]:sourceryinstitute/assert
6657
cd assert
67-
fpm run --compiler caf --runner "cafrun -n 2" --example simple_assertions
68-
fpm run --compiler caf --runner "cafrun -n 2" --example derived_type_diagnostic
58+
fpm build --compiler caf
6959
```
70-
Replace either instance of `2` above with the desired number of images to run for parallel execution.
71-
If `assert` is working correctly, both of the latter `fpm run` commands will error-terminate with one
72-
or more images providing stop codes analogous to those quoted in the [Single-image execution] section.
60+
61+
### Running the examples
62+
See the [./example](./example) subdirectory.
7363

7464
[Hyperlinks]:#
7565
[OpenCoarrays]: https://github.com/sourceryinstitute/opencoarrays
7666
[Enforcing programming contracts]: #enforcing-programming-contracts
7767
[Single-image execution]: #single-image-execution
78-

example/README.md

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,78 @@
1-
![Classes involved in [derived_type_diagnostic.f90](./derived_type_diagnostic.f90)](https://user-images.githubusercontent.com/13108868/130385757-6b79e5f1-5dec-440c-98f5-0f659c538754.png)
1+
-------------------------------------------
2+
3+
This directory contains two example programs.
4+
5+
Simple examples
6+
---------------
7+
8+
The [simple_assertions.f90] example demonstrates a precondition and a
9+
postcondition, each with an assertion that checks the truth of a logical
10+
expression based on scalar, real values.
11+
12+
Derived type diagnostic data
13+
----------------------------
14+
15+
See [derived_type_diagnostic.f90]. For reasons related to runtime performance,
16+
it is desirable to ensure that any computation required to extract diagnostic
17+
data from an object only take place if the assertion fails. This is one of the
18+
main motivations for allowing objects to be passed to the `diagnostic_data`
19+
argument of `assert`. The generic programming facilities planned for
20+
"Fortran 202y" (two standards after Fortran 2018) will ultimately provide the
21+
best way to facilitate the extraction of diagnostic data from objects by
22+
empowering developers to express requirements on types such as that the types
23+
must support a specific procedure binding that can be used to extract output
24+
in character form, the form that `assert` uses for its error stop code. For
25+
now, we impose such a requirement through an `as_character` deferred binding
26+
on the provided `characterizable_t` abstract type.
27+
28+
Because might be problematic to require that a user type to extend the
29+
`characterizable_t` abstract type, the [derived_type_diagnostic.f90] example
30+
shows a workaround based on the class hierarchy described in the figure
31+
below. The pattern expressed in the workaround aggregates the example user
32+
type, `stuff_t` as a component inside the encapsulating `characterizable_stuff_t`
33+
type. The latter type extends `characterizable_t` and implements this parent
34+
type's deferred binding.
35+
36+
![Classes involved in Derived-Type Diagnostic Example](https://user-images.githubusercontent.com/13108868/130385757-6b79e5f1-5dec-440c-98f5-0f659c538754.png)
37+
38+
Running the examples
39+
--------------------
40+
41+
### Single-image execution
42+
```
43+
fpm run --example simple_assertions
44+
fpm run --example derived_type_diagnostic
45+
```
46+
where the `fpm run` automatically invokes `fpm build` if necessary, .e.g., the `fpm` source has
47+
changed since the most recent build. If `assert` is working correctly, the first `fpm run` above
48+
will error-terminate with the character stop code
49+
```
50+
Assertion "reciprocal: abs(error) < tolerance" failed on image 1 with diagnostic data "-1.00000000"
51+
```
52+
and the second `fpm run` above will error-terminate with the character stop code
53+
```
54+
Assertion "stuff_t%z(): self%defined()" failed on image 1 with diagnostic data "(none provided)"
55+
```
56+
57+
### Multi-image execution with `gfortran` and OpenCoarrays
58+
```
59+
git clone [email protected]/sourceryinstitute/assert
60+
cd assert
61+
fpm run --compiler caf --runner "cafrun -n 2" --example simple_assertions
62+
fpm run --compiler caf --runner "cafrun -n 2" --example derived_type_diagnostic
63+
```
64+
Replace either instance of `2` above with the desired number of images to run for parallel execution.
65+
If `assert` is working correctly, both of the latter `fpm run` commands will error-terminate with one
66+
or more images providing stop codes analogous to those quoted in the [Single-image execution] section.
67+
68+
## Derived-type diagnostic data output
69+
To demonstrate the derived-type diagnostic data output capability, try replacing the
70+
`i%defined()` assertion in the [derived_type_diagnostic.f90](./derived_type_diagnostic.f90)
71+
with `.false.`.
72+
73+
[Hyperlinks]:#
74+
[OpenCoarrays]: https://github.com/sourceryinstitute/opencoarrays
75+
[Enforcing programming contracts]: #enforcing-programming-contracts
76+
[Single-image execution]: #single-image-execution
77+
[derived_type_diagnostic.f90]: ./derived_type_diagnostic.f90
78+
[simple_assertions.f90]: ./simple_assertions.f90

0 commit comments

Comments
 (0)