@@ -38,7 +38,8 @@ pure module function topological_sort(dag) result(order)
3838 integer , allocatable :: discovered(:)
3939 integer v
4040
41- allocate (discovered(0 ), searched_and_ordered% o(0 ), searched_and_ordered% s(0 ))
41+ allocate (discovered(0 ))
42+ searched_and_ordered = searched_and_ordered_t(s = [integer :: ], o = [integer :: ])
4243
4344 do v = 1 , size (dag% vertices)
4445 if (.not. any (v == searched_and_ordered% s)) then
@@ -52,33 +53,28 @@ pure module function topological_sort(dag) result(order)
5253
5354 contains
5455
55- pure recursive function depth_first_search(v, d, o) result(result_ )
56+ pure recursive function depth_first_search(v, d, o) result(hybrid )
5657 integer , intent (in ) :: v
5758 integer , intent (in ), dimension (:) :: d, o
58- type (searched_and_ordered_t) result_
59+ type (searched_and_ordered_t) hybrid
5960
6061 call assert(.not. any (v == d), " depth_first_search: cycle detected" , intrinsic_array_t([v,d]))
6162
6263 block
63- integer , allocatable :: dependencies(:), d_local(:)
64+ integer , allocatable :: dependencies(:)
6465 integer w
65- type (searched_and_ordered_t) hybrid
6666
6767 hybrid = searched_and_ordered_t(s = [integer :: ], o = o)
6868 dependencies = dag% depends_on(v)
6969
70- allocate (d_local(0 ))
71-
72- do w = 1 , size (dependencies)
73- if (.not. any (dependencies(w) == hybrid% s)) then
74- hybrid = depth_first_search(dependencies(w), [d, v], hybrid% o)
75- d_local = [d_local, hybrid% s]
76- hybrid% s = d_local
77- end if
70+ do concurrent(w = 1 :size (dependencies))
71+ associate(w_dependencies = > dependencies(w))
72+ if (.not. any (w_dependencies == hybrid% s)) hybrid = depth_first_search(w_dependencies, [d, v], hybrid% o)
73+ end associate
7874 end do
7975
8076 if (.not. any (v == hybrid% o)) hybrid% o = [v, hybrid% o]
81- result_ = searched_and_ordered_t(s = [v, hybrid% s], o = hybrid% o)
77+ hybrid = searched_and_ordered_t(s = [v, hybrid% s], o = hybrid% o)
8278 end block
8379
8480 end function
0 commit comments