You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+33-8Lines changed: 33 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -30,7 +30,7 @@ When the `ASSERTIONS` preprocessor macro is not defined to any value,
30
30
the default is that assertions are *disabled* and will not check the condition.
31
31
32
32
To enable assertion enforcement (e.g., for a debug build), define the
33
-
preprocessor ASSERTIONS to non-zero, eg:
33
+
preprocessor ASSERTIONS to non-zero, e.g.,
34
34
```
35
35
fpm build --flag "-DASSERTIONS"
36
36
```
@@ -45,8 +45,22 @@ Use Cases
45
45
---------
46
46
Two common use cases include
47
47
48
-
1.[Enforcing programming contracts] throughout a project via runtime checks.
49
-
2. Producing output in `pure` procedures for debugging purposes.
48
+
1.[Supporting output in pure procedures] for debugging purposes.
49
+
2.[Enforcing programming contracts] throughout a project via runtime checks.
50
+
51
+
### Supporting output in pure procedures
52
+
Writing pure procedures communicates useful information to a compiler or a developer.
53
+
Specifically, the pure attribute conveys compliance with several constraints that clarify data dependencies and preclude most side effects.
54
+
For a compiler, these constraints support optimizations, including automatic parallelization on a central processing unit (CPU) or offloading to a graphics processing unit (GPU).
55
+
For a developer, the constraints support refactoring tasks such as code movement.
56
+
57
+
The Fortran standard prohibits input or output in pure procedures, which precludes a common debugging mechanism.
58
+
A developer seeking output inside a procedure presumably has an expectation regarding what ranges of output values represent correct program execution.
59
+
A developer can state such expectations in an assertion such as `call_assert(i>0 .and. j<0)`.
60
+
Enforce the assertion by defining the `ASSERTIONS` macro when compiling.
61
+
If the expectation is not met, the program error terminates and prints a stop code showing the assertion's file and line location and a description.
62
+
By default, the description is the literal text of what was asserted: `i>0 .and. j<0` in the aforementioned example.
63
+
Alternatively, the user can provide a custom description.
50
64
51
65
### Enforcing programming contracts
52
66
Programming can be thought of as requirements for correct execution of a procedure and assurances for the result of correct execution.
@@ -193,17 +207,17 @@ limit. This can result in compile-time errors like the following from gfortran:
193
207
Error: Line truncated at (1) [-Werror=line-truncation]
194
208
```
195
209
196
-
Some compilers offer a command-line argument that can be used to workaround this legacy limit, eg:
210
+
Some compilers offer a command-line argument that can be used to workaround this legacy limit, e.g.,
* The [Julienne](https://go.lbl.gov/julienne) correctness-checking framework wraps Assert and defines idioms that automatically generate diagnostic messages containing program data.
296
+
* The [Caffeine](https://go.lbl.gov/caffeine) multi-image Fortran compiler runtime library uses Assert for internal sanity checks and interface validation.
297
+
* The [Fiats](https://go.lbl.gov/fiats) deep learning library uses Assert and Julienne.
298
+
* The [Matcha](https://go.lbl.gov/matcha) T-cell motility simulator also uses Assert and Julienne.
299
+
276
300
Legal Information
277
301
-----------------
278
302
See the [LICENSE](LICENSE) file for copyright and licensing information.
@@ -283,7 +307,8 @@ See the [LICENSE](LICENSE) file for copyright and licensing information.
0 commit comments