|
| 1 | +program dag_to_dot |
| 2 | + !! Demonstrate the construction of a complex DAG, the generation of a Graphviz |
| 3 | + !! .dot file suitable for conversion to Portable Document Format (PDF). The |
| 4 | + !! DAG in this example represents the module dependencies in an early version |
| 5 | + !! of the Framework for Exensible Asynchronous Task Scheduling (FEATS). |
| 6 | + !! See https://github.com/sourceryinstitute/feats. |
| 7 | + !! |
| 8 | + !! Compile and run this program by executing the following command |
| 9 | + !! with your present working directory set to the top-level directory |
| 10 | + !! in the DAG source tree: |
| 11 | + !! |
| 12 | + !! fpm run --example dag-to-dot > feats.dot |
| 13 | + !! dot -Tpdf -o feats.pdf feats.dot |
| 14 | + !! |
| 15 | + !! where the latter command produces a PDF file if Graphviz has been installed. |
| 16 | + !! |
| 17 | + use dag_m, only : dag_t |
| 18 | + use vertex_m, only : vertex_t |
| 19 | + use iso_varying_string, only : var_str, varying_string |
| 20 | + implicit none |
| 21 | + |
| 22 | + character(len=*), parameter :: longest_name = "app_generator_m" |
| 23 | + character(len=len(longest_name)), parameter :: names(*) = & |
| 24 | + [character(len=len(longest_name)) :: & |
| 25 | + "assert_m", "dag_m", "payload_m", "compile_m", "data_loc_map_m", "task_m", "task_item_m", "app_m", "app_generator_m" & |
| 26 | + ,"image_m", "main", "task_item_s", "compile_s", "app_generator_s", "data_loc_map_s", "payload_s", "app_s", "mailbox_m" & |
| 27 | + ,"image_s", "final_task_m", "final_task_s" & |
| 28 | + ] |
| 29 | + associate( & |
| 30 | + assert_m => findloc(names, "assert_m", dim=1) & |
| 31 | + ,dag_m => findloc(names, "dag_m", dim=1) & |
| 32 | + ,payload_m => findloc(names, "payload_m", dim=1) & |
| 33 | + ,compile_m => findloc(names, "compile_m", dim=1) & |
| 34 | + ,data_loc_map_m => findloc(names, "data_loc_map_m", dim=1) & |
| 35 | + ,task_m => findloc(names, "task_m", dim=1) & |
| 36 | + ,task_item_m => findloc(names, "task_item_m", dim=1) & |
| 37 | + ,app_m => findloc(names, "app_m", dim=1) & |
| 38 | + ,app_generator_m => findloc(names, "app_generator_m", dim=1) & |
| 39 | + ,image_m => findloc(names, "image_m", dim=1) & |
| 40 | + ,main => findloc(names, "main", dim=1) & |
| 41 | + ,task_item_s => findloc(names, "task_item_s", dim=1) & |
| 42 | + ,compile_s => findloc(names, "compile_s", dim=1) & |
| 43 | + ,app_generator_s => findloc(names, "app_generator_s", dim=1) & |
| 44 | + ,data_loc_map_s => findloc(names, "data_loc_map_s", dim=1) & |
| 45 | + ,payload_s => findloc(names, "payload_s", dim=1) & |
| 46 | + ,app_s => findloc(names, "app_s", dim=1) & |
| 47 | + ,mailbox_m => findloc(names, "mailbox_m", dim=1) & |
| 48 | + ,image_s => findloc(names, "image_s", dim=1) & |
| 49 | + ,final_task_m => findloc(names, "final_task_m", dim=1) & |
| 50 | + ,final_task_s => findloc(names, "final_task_s", dim=1) & |
| 51 | + ) |
| 52 | + |
| 53 | + block |
| 54 | + character(len=*), parameter :: external_ = 'shape=square,fillcolor="green",style=filled' |
| 55 | + character(len=*), parameter :: root = 'shape=circle,fillcolor="white",style=filled' |
| 56 | + character(len=*), parameter :: branch = 'shape=square,fillcolor="SlateGray1",style=filled' |
| 57 | + character(len=len(branch)), parameter :: leaf = 'shape=circle,fillcolor="cornsilk",style=filled' |
| 58 | + type(dag_t) feats |
| 59 | + type(varying_string) name_string(size(names)) |
| 60 | + |
| 61 | + name_string = var_str(names) |
| 62 | + |
| 63 | + feats = & |
| 64 | + dag_t([ & |
| 65 | + vertex_t([integer::], name_string(assert_m), var_str(external_)) & |
| 66 | + ,vertex_t([integer:: ], name_string(dag_m), var_str(external_)) & |
| 67 | + ,vertex_t([integer::], name_string(payload_m), var_str(leaf) ) & |
| 68 | + ,vertex_t([integer:: ], name_string(compile_m), var_str(leaf) ) & |
| 69 | + ,vertex_t([integer::], name_string(data_loc_map_m), var_str(leaf) ) & |
| 70 | + ,vertex_t([payload_m], name_string(task_m), var_str(branch) ) & |
| 71 | + ,vertex_t([task_m], name_string(task_item_m), var_str(leaf) ) & |
| 72 | + ,vertex_t([dag_m, task_item_m], name_string(app_m), var_str(branch) ) & |
| 73 | + ,vertex_t([app_m, dag_m, task_item_m, compile_m], name_string(app_generator_m), var_str(branch) ) & |
| 74 | + ,vertex_t([app_m, data_loc_map_m], name_string(image_m), var_str(branch) ) & |
| 75 | + ,vertex_t([app_generator_m, image_m], name_string(main), var_str(root) ) & |
| 76 | + ,vertex_t([task_item_m], name_string(task_item_s), var_str(root) ) & |
| 77 | + ,vertex_t([compile_m], name_string(compile_s), var_str(branch) ) & |
| 78 | + ,vertex_t([app_generator_m], name_string(app_generator_s), var_str(root) ) & |
| 79 | + ,vertex_t([data_loc_map_m], name_string(data_loc_map_s), var_str(root) ) & |
| 80 | + ,vertex_t([payload_m], name_string(payload_s), var_str(root) ) & |
| 81 | + ,vertex_t([app_m, assert_m], name_string(app_s), var_str(root) ) & |
| 82 | + ,vertex_t([payload_m], name_string(mailbox_m), var_str(branch) ) & |
| 83 | + ,vertex_t([image_m, mailbox_m], name_string(image_s), var_str(root) ) & |
| 84 | + ,vertex_t([data_loc_map_m, payload_m, task_m], name_string(final_task_m), var_str(branch) ) & |
| 85 | + ,vertex_t([final_task_m], name_string(final_task_s), var_str(root) ) & |
| 86 | + ]) |
| 87 | + print *, feats%graphviz_digraph() |
| 88 | + end block |
| 89 | + end associate |
| 90 | + |
| 91 | +end program |
0 commit comments