Skip to content

Commit 3778e6a

Browse files
feat: example application running
1 parent 380b774 commit 3778e6a

File tree

6 files changed

+139
-27
lines changed

6 files changed

+139
-27
lines changed
Lines changed: 111 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,124 @@
11
module application_generator_m
22
use application_m, only: application_t
3+
use dag_m, only : dag_t
4+
use iso_varying_string, only: varying_string, operator(//), put_line, var_str
5+
use payload_m, only: payload_t
6+
use strff, only: to_string
7+
use task_payload_map_m, only: task_payload_map_t
8+
use task_m, only: task_t
9+
use task_item_m, only: task_item_t
10+
use vertex_m, only : vertex_t
11+
312
implicit none
413
private
514
public :: generate_application
615

16+
type, extends(task_t) :: compile_task_t
17+
type(varying_string) :: to_compile
18+
contains
19+
procedure :: execute => compile_task_execute
20+
end type
721
contains
822
function generate_application() result(application)
923
type(application_t) :: application
1024

11-
associate(unused => application)
25+
character(len=*), parameter :: longest_name = "app_generator_m"
26+
character(len=len(longest_name)), parameter :: names(*) = &
27+
[ character(len=len(longest_name)) :: "assert_m" &
28+
, "dag_m" &
29+
, "payload_m" &
30+
, "compile_m" &
31+
, "data_loc_map_m" &
32+
, "task_m" &
33+
, "task_item_m" &
34+
, "app_m" &
35+
, "app_generator_m" &
36+
, "image_m" &
37+
, "main" &
38+
, "task_item_s" &
39+
, "compile_s" &
40+
, "app_generator_s" &
41+
, "data_loc_map_s" &
42+
, "payload_s" &
43+
, "app_s" &
44+
, "mailbox_m" &
45+
, "image_s" &
46+
, "final_task_m" &
47+
, "final_task_s" &
48+
]
49+
associate( &
50+
assert_m => findloc(names, "assert_m", dim=1) &
51+
, dag_m => findloc(names, "dag_m", dim=1) &
52+
, payload_m => findloc(names, "payload_m", dim=1) &
53+
, compile_m => findloc(names, "compile_m", dim=1) &
54+
, data_loc_map_m => findloc(names, "data_loc_map_m", dim=1) &
55+
, task_m => findloc(names, "task_m", dim=1) &
56+
, task_item_m => findloc(names, "task_item_m", dim=1) &
57+
, app_m => findloc(names, "app_m", dim=1) &
58+
, app_generator_m => findloc(names, "app_generator_m", dim=1) &
59+
, image_m => findloc(names, "image_m", dim=1) &
60+
, main => findloc(names, "main", dim=1) &
61+
, task_item_s => findloc(names, "task_item_s", dim=1) &
62+
, compile_s => findloc(names, "compile_s", dim=1) &
63+
, app_generator_s => findloc(names, "app_generator_s", dim=1) &
64+
, data_loc_map_s => findloc(names, "data_loc_map_s", dim=1) &
65+
, payload_s => findloc(names, "payload_s", dim=1) &
66+
, app_s => findloc(names, "app_s", dim=1) &
67+
, mailbox_m => findloc(names, "mailbox_m", dim=1) &
68+
, image_s => findloc(names, "image_s", dim=1) &
69+
, final_task_m => findloc(names, "final_task_m", dim=1) &
70+
, final_task_s => findloc(names, "final_task_s", dim=1) &
71+
)
72+
73+
block
74+
character(len=*), parameter :: external_ = 'shape=square,fillcolor="green",style=filled'
75+
character(len=*), parameter :: root = 'shape=circle,fillcolor="white",style=filled'
76+
character(len=*), parameter :: branch = 'shape=square,fillcolor="SlateGray1",style=filled'
77+
character(len=len(branch)), parameter :: leaf = 'shape=circle,fillcolor="cornsilk",style=filled'
78+
type(dag_t) feats
79+
integer i
80+
type(varying_string) name_string(size(names))
81+
type(task_item_t), allocatable :: tasks(:)
82+
83+
name_string = var_str(names)
84+
85+
feats = &
86+
dag_t([ &
87+
vertex_t([integer::], name_string(assert_m), var_str(external_)) &
88+
, vertex_t([integer:: ], name_string(dag_m), var_str(external_)) &
89+
, vertex_t([integer::], name_string(payload_m), var_str(leaf) ) &
90+
, vertex_t([integer:: ], name_string(compile_m), var_str(leaf) ) &
91+
, vertex_t([integer::], name_string(data_loc_map_m), var_str(leaf) ) &
92+
, vertex_t([payload_m], name_string(task_m), var_str(branch) ) &
93+
, vertex_t([task_m], name_string(task_item_m), var_str(leaf) ) &
94+
, vertex_t([dag_m, task_item_m], name_string(app_m), var_str(branch) ) &
95+
, vertex_t([app_m, dag_m, task_item_m, compile_m], name_string(app_generator_m), var_str(branch) ) &
96+
, vertex_t([app_m, data_loc_map_m], name_string(image_m), var_str(branch) ) &
97+
, vertex_t([app_generator_m, image_m], name_string(main), var_str(root) ) &
98+
, vertex_t([task_item_m], name_string(task_item_s), var_str(root) ) &
99+
, vertex_t([compile_m], name_string(compile_s), var_str(branch) ) &
100+
, vertex_t([app_generator_m], name_string(app_generator_s), var_str(root) ) &
101+
, vertex_t([data_loc_map_m], name_string(data_loc_map_s), var_str(root) ) &
102+
, vertex_t([payload_m], name_string(payload_s), var_str(root) ) &
103+
, vertex_t([app_m, assert_m], name_string(app_s), var_str(root) ) &
104+
, vertex_t([payload_m], name_string(mailbox_m), var_str(branch) ) &
105+
, vertex_t([image_m, mailbox_m], name_string(image_s), var_str(root) ) &
106+
, vertex_t([data_loc_map_m, payload_m, task_m], name_string(final_task_m), var_str(branch) ) &
107+
, vertex_t([final_task_m], name_string(final_task_s), var_str(root) ) &
108+
])
109+
tasks = [(task_item_t(compile_task_t(name_string(i))), i = 1, size(names))]
110+
application = application_t(feats, tasks)
111+
end block
12112
end associate
13113
end function
114+
115+
function compile_task_execute(self, task_number, upstream_task_results) result(output)
116+
class(compile_task_t), intent(in) :: self
117+
integer, intent(in) :: task_number
118+
type(task_payload_map_t), intent(in) :: upstream_task_results
119+
type(payload_t) :: output
120+
121+
call put_line("Executing task number: " // to_string(task_number))
122+
call put_line("Compiling: " // self%to_compile)
123+
end function
14124
end module

example/main.f90

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
program main
22
!! Framework for Extensible Asynchronous Task Scheduling
3+
use application_m, only: application_t
34
use application_generator_m, only : generate_application
45
use image_m, only: image_t
6+
use task_payload_map_m, only: task_payload_map_t
57
implicit none
68

9+
type(application_t) :: application
710
type(image_t) :: image
11+
type(task_payload_map_t) :: results
812

9-
associate(application => generate_application())
10-
associate(results => image%run(application))
11-
! can access results if needed
12-
end associate
13-
end associate
13+
application = generate_application()
14+
results = image%run(application)
1415
end program

src/final_task_m.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module function execute(self, task_number, upstream_task_results) result(output)
2121
implicit none
2222
class(final_task_t), intent(in) :: self
2323
integer, intent(in) :: task_number
24-
class(task_payload_map_t), intent(in) :: upstream_task_results
24+
type(task_payload_map_t), intent(in) :: upstream_task_results
2525
type(payload_t) :: output
2626
end function
2727

src/image_s.f90

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131

3232
module procedure run
3333
logical :: tasks_left
34+
type(task_item_t), allocatable :: tasks(:)
35+
type(dag_t) :: dag
3436

3537
task_identifier = no_task_assigned
3638
associate(n_tasks => size(application%tasks()), n_imgs => num_images())
@@ -48,17 +50,16 @@
4850

4951
tasks_left = .true.
5052

51-
associate( &
52-
tasks => [application%tasks(), task_item_t(final_task_t())], &
53-
dag => application%dag())
54-
do while (tasks_left)
55-
if (this_image() == scheduler_image) then
56-
tasks_left = assign_task(dag)
57-
else
58-
tasks_left = do_work(tasks, dag)
59-
end if
60-
end do
61-
end associate
53+
tasks = [application%tasks(), task_item_t(final_task_t())]
54+
dag = application%dag()
55+
do while (tasks_left)
56+
if (this_image() == scheduler_image) then
57+
tasks_left = assign_task(dag)
58+
else
59+
tasks_left = do_work(tasks, dag)
60+
end if
61+
end do
62+
results = task_payload_map_t([integer::], [integer::])
6263
end procedure
6364

6465
function do_work(tasks, dag) result(tasks_left)
@@ -138,13 +139,13 @@ function assign_task(dag) result(tasks_left)
138139
! check which task the image just finished, that's task A
139140
! for each task B upstream of A, walk through that task's downstream dependencies
140141
! if they're all completed, the output data from B can be freed.
141-
upstream_tasks = dag%dependencies_for(task_identifier[next_image])
142-
upstream_task_images = task_assignment_history(upstream_tasks)
143-
do i = 1, size(upstream_tasks)
144-
if (all(task_done(dag%depends_on(upstream_tasks(i))))) then
145-
mailbox_entry_can_be_freed(upstream_tasks(i))[upstream_task_images(i)] = .true.
146-
end if
147-
end do
142+
! upstream_tasks = dag%dependencies_for(task_identifier[next_image])
143+
! upstream_task_images = task_assignment_history(upstream_tasks)
144+
! do i = 1, size(upstream_tasks)
145+
! if (all(task_done(dag%depends_on(upstream_tasks(i))))) then
146+
! mailbox_entry_can_be_freed(upstream_tasks(i))[upstream_task_images(i)] = .true.
147+
! end if
148+
! end do
148149

149150

150151
! tell the image that it can proceed with the next task

src/task_item_m.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module function execute(self, task_number, upstream_task_results) result(output)
3434
implicit none
3535
class(task_item_t), intent(in) :: self
3636
integer, intent(in) :: task_number
37-
class(task_payload_map_t), intent(in) :: upstream_task_results
37+
type(task_payload_map_t), intent(in) :: upstream_task_results
3838
type(payload_t) :: output
3939
end function
4040

src/task_m.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function execute_i(self, task_number, upstream_task_results) result(output)
2424
implicit none
2525
class(task_t), intent(in) :: self
2626
integer, intent(in) :: task_number
27-
class(task_payload_map_t), intent(in) :: upstream_task_results
27+
type(task_payload_map_t), intent(in) :: upstream_task_results
2828
type(payload_t) :: output
2929
end function
3030

0 commit comments

Comments
 (0)