Skip to content

Commit

Permalink
vendor the dag library
Browse files Browse the repository at this point in the history
  • Loading branch information
everythingfunctional committed Jul 19, 2023
1 parent e362b0d commit 26aa7d7
Show file tree
Hide file tree
Showing 8 changed files with 756 additions and 1 deletion.
2 changes: 1 addition & 1 deletion fpm.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ maintainer = "[email protected]"
copyright = "2021 Sourcery Institute"

[dependencies]
dag = {git = "https://github.com/sourceryinstitute/dag", rev="e3f8ec61635842cc1e28d09bff34391c328fd75e" } #, tag = "3.0.0"}
dag = { path = "vendor/dag" }

[[example]]
name="build_feats"
Expand Down
60 changes: 60 additions & 0 deletions vendor/dag/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
Copyright (c) 2020, Sourcery Institute
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

------------------------------------------------------------------------------

Modern Fortran DAG Library
https://github.com/jacobwilliams/daglib

Copyright (c) 2018, Jacob Williams
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.

* The names of its contributors may not be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
BSD 3-Clause License
146 changes: 146 additions & 0 deletions vendor/dag/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
.___
__| _/____ ____
/ __ |\__ \ / ___\
/ /_/ | / __ \_/ /_/ >
\____ |(____ /\___ /
\/ \//_____/

Overview
========

DAG is a Fortran 2018 library for creating and manipulating directed acyclic graphs (DAGs).
DAG is based on a fork of [daglib by Jacob Williams], refactored to

* Adopt a functional programming pattern based on (mostly) pure functions.
* Add build system and test harness automated by [fpm],
* Add unit testing written with [veggies],
* Add continuous-integration testing and documentation deployment via [GitHub Actions],
* Add [documentation] generated by [FORD],
* Add runtime assertion-checking using [Assert], and
* Add [JSON] file input/output using [rojff].
* Ensure that dag objects always have a valid state that includes a topological
ordering stored without mutating vertices or vertex arrays.

Usage
-----
When compilers cooperate, we recommend using `associate` to assign names to
dag's user-defined structure constructor results. See the [example]
subdirectory for demonstrations of how we use `associate` instead of the
declare-and-define style that is much more common in Fortran
and other imperative programming languages. Associating a name instead of
declaring an object and then later defining it offers several potential
advantages:

* It prevents the accidental use of declared-but-undefined data.
* It provides immutable state, which in turn
- prevents the mistaken overwriting of data and
- enables some possible compiler optimizations.

_Caveat emptor_: your mileage may vary. Compiler support for `associate` is
evolving and compiler might or might not exploit optimizatio opportunities.
When weird things happen, resort to declaring and subsequently defining
objects by assigning a constructor function result to the declared object.

Prerequisites
-------------
The [fpm] package manager automatically downloads and builds all
dependencies. See [fpm.toml] for a complete list, including version numbers.

Downloading
-----------
Obtain dag by downloading the [latest release] or cloning the repository as
follows:

```
git clone [email protected]:sourceryinstitute/dag
```

Building and testing
--------------------
### Building and testing for serial execution
Build and test `dag` in a `bash`-like shell as follows:
```
fpm test
```
### Building and testing for parallel execution
With [gfortran] and [OpenCoarrays] installed, build and test `dag` in a
`bash`-like shell as follows:
```
fpm test --compiler caf --runner "cafrun -n 2"
```
replacing `2` in the last line with the desired number of images to execute in parallel
for each test.

Please report any test failures by submitting an [issue] on the DAG repository.

Examples
--------
The [example] subdirectory provides the following examples:

* [print-to-json.f90] - constructs and prints it a JSON representation the DAG.
Run this example and redirect the output to a file as follows:
```
fpm run --example print-to-json > dag.json
```
* [read-from-json.f90] - constructs a DAG by reading from a JSON file.
Run this example as follows:
```
fpm run --example read-from-json
```
which will read the file [./example/dag-dependencies.json]
* [dag-to-dot.f90] - constructs a DAG describing the module dependencies in
an early version of the Framework for Extensible Asynchronous
Task Scheduling ([FEATS]) and prints the DAG to a .dot file suitable for
conversion to a `.pdf` as follows:
```
fpm run --example dag-to-dot > feats-dag.dot
dot -Tpdf -o feats.pdf feats.dot
```
which should produce the following graph below:

![feats-dependencies](https://user-images.githubusercontent.com/13108868/133311851-721b7cda-1d10-4ee1-a51d-6169ca624839.png)

License
-------

This library is released under a [BSD-3 license].

Acknowledgments
----------------

| | |
|-|-|
| We gratefully acknowledge support from [NASA Langley Research Center] under contract number 80NSSC20P2246. | <img src="https://user-images.githubusercontent.com/13108868/112893191-304ce180-908f-11eb-8bea-e0cab5322aa8.png" alt="NASA logo" width="100">|

Donate
------
If you find this software useful, please consider donating code or
[currency](http://bit.ly/donate-to-sourcery-institute) to aid in development efforts.

[NASA Langley Research Center]: https://www.nasa.gov/langley
[latest release]: https://github.com/sourceryinstitute/dag/releases/latest

[daglib by Jacob Williams]: https://github.com/jacobwilliams/daglib
[GraphViz]: https://www.graphviz.org
[OpenCoarrays]: https://github.com/sourceryinstitute/opencoarrays
[CMake]: https://www.cmake.org
[gfortran]: https://gcc.gnu.org
[BSD-3 license]: https://github.com/sourceryinstitute/dag/blob/master/LICENSE
[fpm]: https://github.com/fortran-lang/fpm
[3276af]: https://github.com/everythingfunctional/fpm/commit/3276af2e000d1b2c90f151148cd01cce0d3e886d

[veggies]: https://gitlab.com/everythingfunctional/veggies
[GitHub Actions]: https://github.com/features/actions
[FORD]: https://github.com/Fortran-FOSS-Programmers/ford
[JSON]: https://www.json.org/json-en.html
[rojff]: https://gitlab.com/everythingfunctional/rojff
[./src/dag_test.f90]: ./src/dag_test.f90
[example]: ./example/
[FEATS]: https://github.com/sourceryinstitute/feats
[Assert]: https://github.com/sourceryinstitute/assert
[print-to-json.f90]: ./example/print-to-json.f90
[read-from-json.f90]:./example/read-from-json.f90
[dag-to-dot.f90]: ./example/dag-to-dot.f90
[documentation]: https://sourceryinstitute.github.io/dag/
[issue]: https://github.com/sourceryinstitute/dag/issues/new
[./example/dag-dependencies.json]: ./example/dag-dependencies.json
12 changes: 12 additions & 0 deletions vendor/dag/fpm.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name = "dag"
version = "3.0.0"
license = "BSD"
author = ["Damian Rouson", "Robert Singleterry", "Brad Richardson"]
maintainer = "[email protected]"
copyright = "2020-2021 Sourcery Institute"

[dependencies]
rojff = { git = "https://gitlab.com/everythingfunctional/rojff", tag = "v1.0.0" }
erloff = { git = "https://gitlab.com/everythingfunctional/erloff", tag = "v2.2.0" }
iso_varying_string = { git = "https://gitlab.com/everythingfunctional/iso_varying_string", tag = "v3.0.4" }
assert = { git = "https://github.com/sourceryinstitute/assert", tag = "1.4.0" }
94 changes: 94 additions & 0 deletions vendor/dag/src/dag_m.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
module dag_m
!! summary: A directed acyclic graph (DAG) abstraction.
!! author: Jacob Williams, Damian Rouson, Robert Singleterry, Brad Richardson
!! version: v1.0
!! date: 2020-Nov-30
!! license: Copyright (c) 2020, Sourcery Institute, BSD 3-clause license Copyright (c) 2018 Jacob Williams
use vertex_m, only : vertex_t
use rojff, only : json_object_t

implicit none

private

type,public :: dag_t
!! Encapsulate a graph as an array of vertices, each storing dependency information
private
type(vertex_t), allocatable :: vertices(:)
integer, allocatable :: order(:)
contains
procedure :: is_sorted_and_acyclic
procedure :: to_json
procedure :: num_vertices
procedure :: dependencies_for
procedure :: depends_on
procedure :: graphviz_digraph
end type

interface dag_t

module function construct_from_json(json_object) result(dag)
!! Construct a dag_t object from a JSON object (result contains a topologically sorted index array)
implicit none
type(json_object_t), intent(in) :: json_object
type(dag_t) dag
end function

pure module function construct_from_components(vertices) result(dag)
!! Construct a dag_t object from an array of (unsorted) vertex_t objects (result contains a topologically sorted index array)
implicit none
type(vertex_t), intent(in) :: vertices(:)
type(dag_t) dag
end function

end interface

interface

elemental module function is_sorted_and_acyclic(self)
!! Result is true if dag%order contains a topological sorting of vertex identifiers
implicit none
class(dag_t), intent(in) :: self
logical is_sorted_and_acyclic
end function

module function to_json(self) result(json_object)
!! Result is a JSON representation of the dag_t object
implicit none
class(dag_t), intent(in) :: self
type(json_object_t) json_object
end function

elemental module function num_vertices(self)
!! Result is the size of the vertex array
implicit none
class(dag_t), intent(in) :: self
integer num_vertices
end function

pure module function depends_on(self, vertex_num) result(dependencies)
!! Result is an array of the vertex numbers that depend on on vertex vertex_num
implicit none
class(dag_t), intent(in) :: self
integer, intent(in) :: vertex_num
integer, allocatable :: dependencies(:)
end function

pure module function dependencies_for(self, vertex_id) result(dependency_ids)
!! Result is an array of the ids on which vertex_id depends
implicit none
class(dag_t), intent(in) :: self
integer, intent(in) :: vertex_id
integer, allocatable :: dependency_ids(:)
end function

pure module function graphviz_digraph(self) result(digraph)
!! Result contains a Graphviz .dot file descriptoin of the dag_t object
implicit none
class(dag_t),intent(in) :: self
character(len=:), allocatable :: digraph
end function

end interface

end module dag_m
Loading

0 comments on commit 26aa7d7

Please sign in to comment.