Skip to content

Commit

Permalink
Remove dependence on iso_varying_string
Browse files Browse the repository at this point in the history
  • Loading branch information
everythingfunctional committed Jul 21, 2023
1 parent 6d71a93 commit 7dc0866
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 130 deletions.
103 changes: 38 additions & 65 deletions example/build_feats/feats_application_generator_m.f90
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module feats_application_generator_m
use application_m, only: application_t
use dag_m, only : dag_t
use iso_varying_string, only: varying_string, operator(//), trim, put_line, var_str
use payload_m, only: payload_t, empty_payload
use task_m, only: task_t
use task_item_m, only: task_item_t
Expand All @@ -12,84 +11,59 @@ module feats_application_generator_m
public :: generate_application

type, extends(task_t) :: compile_task_t
type(varying_string) :: to_compile
character(len=:), allocatable :: to_compile
contains
procedure :: execute => compile_task_execute
end type
contains
function generate_application() result(application)
type(application_t) :: application
character(len=*), parameter :: longest_name = "feats_result_map_m"
character(len=len(longest_name)), parameter :: names(*) = &
[ character(len=len(longest_name)) :: "assert_m" &
, "dag_m" &
, "application_m" &
, "application_s" &
, "feats_result_map_m" &
, "final_task_m" &
, "final_task_s" &
, "image_m" &
, "image_s" &
, "mailbox_m" &
, "payload_m" &
, "payload_s" &
, "task_item_m" &
, "task_item_s" &
, "task_m" &
, "task_s" &
]
associate( &
assert_m => findloc(names, "assert_m", dim=1) &
, dag_m => findloc(names, "dag_m", dim=1) &
, application_m => findloc(names, "application_m", dim=1) &
, application_s => findloc(names, "application_s", dim=1) &
, feats_result_map_m => findloc(names, "feats_result_map_m", dim=1) &
, final_task_m => findloc(names, "final_task_m", dim=1) &
, final_task_s => findloc(names, "final_task_s", dim=1) &
, image_m => findloc(names, "image_m", dim=1) &
, image_s => findloc(names, "image_s", dim=1) &
, mailbox_m => findloc(names, "mailbox_m", dim=1) &
, payload_m => findloc(names, "payload_m", dim=1) &
, payload_s => findloc(names, "payload_s", dim=1) &
, task_item_m => findloc(names, "task_item_m", dim=1) &
, task_item_s => findloc(names, "task_item_s", dim=1) &
, task_m => findloc(names, "task_m", dim=1) &
, task_s => findloc(names, "task_s", dim=1) &
)
block
character(len=*), parameter :: external_ = 'shape=square,fillcolor="green",style=filled'
character(len=*), parameter :: root = 'shape=circle,fillcolor="white",style=filled'
character(len=*), parameter :: branch = 'shape=square,fillcolor="SlateGray1",style=filled'
character(len=len(branch)), parameter :: leaf = 'shape=circle,fillcolor="cornsilk",style=filled'
type(dag_t) feats
integer i
type(varying_string) name_string(size(names))
type(task_item_t), allocatable :: tasks(:)

name_string = trim(var_str(names))

feats = dag_t(&
[ vertex_t([integer::], name_string(assert_m), var_str(external_)) &
, vertex_t([integer::], name_string(dag_m), var_str(external_)) &
, vertex_t([dag_m, task_item_m], name_string(application_m), var_str(branch)) &
, vertex_t([assert_m, application_m], name_string(application_s), var_str(root)) &
, vertex_t([integer::], name_string(feats_result_map_m), var_str(leaf)) &
, vertex_t([payload_m, task_m], name_string(final_task_m), var_str(branch)) &
, vertex_t([final_task_m], name_string(final_task_s), var_str(root)) &
, vertex_t([application_m, feats_result_map_m, payload_m], name_string(image_m), var_str(branch)) &
, vertex_t([dag_m, final_task_m, image_m, mailbox_m, task_item_m], name_string(image_s), var_str(root)) &
, vertex_t([payload_m], name_string(mailbox_m), var_str(branch)) &
, vertex_t([integer::], name_string(payload_m), var_str(leaf)) &
, vertex_t([payload_m], name_string(payload_s), var_str(root)) &
, vertex_t([payload_m, task_m], name_string(task_item_m), var_str(branch)) &
, vertex_t([task_item_m], name_string(task_item_s), var_str(root)) &
, vertex_t([payload_m], name_string(task_m), var_str(branch)) &
, vertex_t([task_m], name_string(task_s), var_str(root)) &
[ vertex_t([integer::], "assert_m", external_) & ! 1
, vertex_t([integer::], "dag_m", external_) & ! 2
, vertex_t([2, 13], "application_m", branch) & ! 3
, vertex_t([1, 3], "application_s", root) & ! 4
, vertex_t([integer::], "feats_result_map_m", leaf) & ! 5
, vertex_t([11, 15], "final_task_m", branch) & ! 6
, vertex_t([6], "final_task_s", root) & ! 7
, vertex_t([3, 5, 11], "image_m", branch) & ! 8
, vertex_t([2, 6, 8, 10, 13], "image_s", root) & ! 9
, vertex_t([11], "mailbox_m", branch) & ! 10
, vertex_t([integer::], "payload_m", leaf) & ! 11
, vertex_t([11], "payload_s", root) & ! 12
, vertex_t([11, 15], "task_item_m", branch) & ! 13
, vertex_t([13], "task_item_s", root) & ! 14
, vertex_t([11], "task_m", branch) & ! 15
, vertex_t([15], "task_s", root) & ! 16
])
tasks = [(task_item_t(compile_task_t(name_string(i))), i = 1, size(names))]
tasks = &
[ task_item_t(compile_task_t("assert_m")) &
, task_item_t(compile_task_t("dag_m")) &
, task_item_t(compile_task_t("application_m")) &
, task_item_t(compile_task_t("application_s")) &
, task_item_t(compile_task_t("feats_result_map_m")) &
, task_item_t(compile_task_t("final_task_m")) &
, task_item_t(compile_task_t("final_task_s")) &
, task_item_t(compile_task_t("image_m")) &
, task_item_t(compile_task_t("image_s")) &
, task_item_t(compile_task_t("mailbox_m")) &
, task_item_t(compile_task_t("payload_m")) &
, task_item_t(compile_task_t("payload_s")) &
, task_item_t(compile_task_t("task_item_m")) &
, task_item_t(compile_task_t("task_item_s")) &
, task_item_t(compile_task_t("task_m")) &
, task_item_t(compile_task_t("task_s")) &
]
application = application_t(feats, tasks)
end block
end associate
end function

function compile_task_execute(self, arguments) result(output)
Expand All @@ -101,12 +75,11 @@ function compile_task_execute(self, arguments) result(output)
character(len=10) :: image_string

write(image_string, "(I0)") this_image()
call put_line( &
"Compiling: " // self%to_compile &
// " on image number: " // trim(image_string))
print *, "Compiling: " // self%to_compile &
// " on image number: " // trim(image_string)
call random_number(rand)
call sleep(int(rand * 10))
call put_line("Finished Compiling: " // self%to_compile)
print *, "Finished Compiling: " // self%to_compile

output = empty_payload()
end function
Expand Down
19 changes: 9 additions & 10 deletions example/lu_decomp/lu_decom_app_m.f90
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module lu_decomp_app_m
use application_m, only: application_t
use dag_m, only: dag_t
use iso_varying_string, only: varying_string, trim, var_str
use iso_fortran_env, only: wp => real64
use payload_m, only: payload_t
use task_m, only: task_t
Expand Down Expand Up @@ -98,49 +97,49 @@ function generate_application() result(application)
previous_task = 0

tasks = [task_item_t(initial_t(matrix))]
vertices = [vertex_t([integer::], var_str("initial"))]
vertices = [vertex_t([integer::], "initial")]
previous_task = previous_task + 1
latest_matrix = previous_task

tasks = [tasks, task_item_t(print_matrix_t())]
vertices = [vertices, vertex_t([latest_matrix], var_str("print"))]
vertices = [vertices, vertex_t([latest_matrix], "print")]
previous_task = previous_task + 1

allocate(for_back_substitution(0))
do step = 1, matrix_size-1
for_reconstruction = [latest_matrix]
do row = step+1, matrix_size
tasks = [tasks, task_item_t(calc_factor_t(row=row, step=step))]
vertices = [vertices, vertex_t([latest_matrix], var_str("factor"))]
vertices = [vertices, vertex_t([latest_matrix], "factor")]
previous_task = previous_task + 1
for_back_substitution = [for_back_substitution, previous_task]

tasks = [tasks, task_item_t(row_multiply_t(step=step))]
vertices = [vertices, vertex_t([latest_matrix, previous_task], var_str("row_multiply"))]
vertices = [vertices, vertex_t([latest_matrix, previous_task], "row_multiply")]
previous_task = previous_task + 1

tasks = [tasks, task_item_t(row_subtract_t(row=row))]
vertices = [vertices, vertex_t([latest_matrix, previous_task], var_str("row_subtract"))]
vertices = [vertices, vertex_t([latest_matrix, previous_task], "row_subtract")]
previous_task = previous_task + 1
for_reconstruction = [for_reconstruction, previous_task]
end do
tasks = [tasks, task_item_t(reconstruct_t(step=step))]
vertices = [vertices, vertex_t(for_reconstruction, var_str("reconstruct"))]
vertices = [vertices, vertex_t(for_reconstruction, "reconstruct")]
previous_task = previous_task + 1
latest_matrix = previous_task

tasks = [tasks, task_item_t(print_matrix_t())]
vertices = [vertices, vertex_t([latest_matrix], var_str("print"))]
vertices = [vertices, vertex_t([latest_matrix], "print")]
previous_task = previous_task + 1
end do
tasks = [tasks, task_item_t(back_substitute_t(n_rows=matrix_size))]
vertices = [vertices, vertex_t(for_back_substitution, var_str("back_substitute"))]
vertices = [vertices, vertex_t(for_back_substitution, "back_substitute")]
previous_task = previous_task + 1
deallocate(for_back_substitution)
latest_matrix = previous_task

tasks = [tasks, task_item_t(print_matrix_t())]
vertices = [vertices, vertex_t([latest_matrix], var_str("print"))]
vertices = [vertices, vertex_t([latest_matrix], "print")]
previous_task = previous_task + 1

dag = dag_t(vertices)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module quadratic_solver_application_generator_m
use application_m, only: application_t
use dag_m, only: dag_t
use iso_varying_string, only: varying_string, trim, var_str
use legacy_m, only: square, four_a_c
use payload_m, only: payload_t
use task_m, only: task_t
Expand Down Expand Up @@ -70,55 +69,25 @@ module quadratic_solver_application_generator_m
contains
function generate_application() result(application)
type(application_t) :: application

character(len=*), parameter :: longest_name = "minus_b_pm_square_root"
character(len=len(longest_name)), parameter :: names(*) = &
[ character(len=len(longest_name)) :: "a" &
, "b" &
, "c" &
, "b_squared" &
, "four_ac" &
, "square_root" &
, "minus_b_pm_square_root" &
, "two_a" &
, "division" &
, "print" &
]
associate( &
a => findloc(names, "a", dim=1) &
, b => findloc(names, "b", dim=1) &
, c => findloc(names, "c", dim=1) &
, b_squared => findloc(names, "b_squared", dim=1) &
, four_ac => findloc(names, "four_ac", dim=1) &
, square_root => findloc(names, "square_root", dim=1) &
, minus_b_pm_square_root => findloc(names, "minus_b_pm_square_root", dim=1) &
, two_a => findloc(names, "two_a", dim=1) &
, division => findloc(names, "division", dim=1) &
, print => findloc(names, "print", dim=1) &
)
block
character(len=*), parameter :: root = 'shape=circle,fillcolor="white",style=filled'
character(len=*), parameter :: branch = 'shape=square,fillcolor="SlateGray1",style=filled'
character(len=len(branch)), parameter :: leaf = 'shape=circle,fillcolor="cornsilk",style=filled'
type(dag_t) solver
integer i
type(varying_string) name_string(size(names))
type(task_item_t), allocatable :: tasks(:)

name_string = trim(var_str(names))

solver = &
dag_t([ &
vertex_t([integer::], name_string(a), var_str(leaf)) &
, vertex_t([integer::], name_string(b), var_str(leaf)) &
, vertex_t([integer::], name_string(c), var_str(leaf)) &
, vertex_t([b], name_string(b_squared), var_str(branch)) &
, vertex_t([a, c], name_string(four_ac), var_str(branch)) &
, vertex_t([b_squared, four_ac], name_string(square_root), var_str(branch)) &
, vertex_t([b, square_root], name_string(minus_b_pm_square_root), var_str(branch)) &
, vertex_t([a], name_string(two_a), var_str(branch)) &
, vertex_t([two_a, minus_b_pm_square_root], name_string(division), var_str(branch)) &
, vertex_t([division], name_string(print), var_str(root)) &
vertex_t([integer::], "a", leaf) &
, vertex_t([integer::], "b", leaf) &
, vertex_t([integer::], "c", leaf) &
, vertex_t([2], "b_squared", branch) &
, vertex_t([1, 3], "four_ac", branch) &
, vertex_t([4, 5], "square_root", branch) &
, vertex_t([2, 6], "minus_b_pm_square_root", branch) &
, vertex_t([1], "two_a", branch) &
, vertex_t([8, 7], "division", branch) &
, vertex_t([9], "print", root) &
])
block
real :: a, b, c
Expand All @@ -144,7 +113,6 @@ function generate_application() result(application)
application = application_t(solver, tasks)
end block
end block
end associate
end function

function a_execute(self, arguments) result(output)
Expand Down
3 changes: 0 additions & 3 deletions vendor/dag/fpm.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,3 @@ license = "BSD"
author = ["Damian Rouson", "Robert Singleterry", "Brad Richardson"]
maintainer = "[email protected]"
copyright = "2020-2021 Sourcery Institute"

[dependencies]
iso_varying_string = { git = "https://gitlab.com/everythingfunctional/iso_varying_string", tag = "v3.0.4" }
18 changes: 8 additions & 10 deletions vendor/dag/src/vertex_m.f90
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ module vertex_m
!! version: v1.0
!! date: 2020-Nov-30
!! license: Copyright (c) 2020-2021, Sourcery Institute, BSD 3-clause license Copyright (c) 2018 Jacob Williams
use iso_varying_string, only : varying_string, assignment(=)

implicit none

private
Expand All @@ -15,8 +13,8 @@ module vertex_m
!! Encapsulate a node in a graph comprised of vertices connected by dependencies (edges)
private
integer, allocatable :: edges_(:)
type(varying_string) :: label_
type(varying_string) :: attributes_
character(len=:), allocatable :: label_
character(len=:), allocatable :: attributes_
contains
procedure :: edges
procedure :: label
Expand All @@ -31,8 +29,8 @@ module vertex_m
pure function construct_from_components(edges, label, attributes) result(vertex)
!! Component-wise constructor of a vertex_t object
integer, intent(in) :: edges(:) !! vertices on which this vertex depends
type(varying_string), intent(in) :: label !! vertex description (e.g., name)
type(varying_string), intent(in), optional :: attributes !! Graphvizl .dot symbol description
character(len=*), intent(in) :: label !! vertex description (e.g., name)
character(len=*), intent(in), optional :: attributes !! Graphvizl .dot symbol description
type(vertex_t) vertex

character(len=*), parameter :: &
Expand Down Expand Up @@ -66,18 +64,18 @@ pure function edges(self) result(my_edges)
my_edges = self%edges_
end function

elemental function label(self) result(my_label)
pure function label(self) result(my_label)
!! Vertex label getter
class(vertex_t), intent(in) :: self
type(varying_string) my_label
character(len=:), allocatable :: my_label

my_label = self%label_
end function

elemental function attributes(self) result(my_attributes)
pure function attributes(self) result(my_attributes)
!! Vertex attributes getter
class(vertex_t), intent(in) :: self
type(varying_string) my_attributes
character(len=:), allocatable :: my_attributes

my_attributes = self%attributes_
end function
Expand Down

0 comments on commit 7dc0866

Please sign in to comment.