Research Article

SPOT: A DSL for Extending Fortran Programs with Metaprogramming

Algorithm 10

The snippet of parallelized Dijkstra’s algorithm.
(1) subroutine dijkstra_distance (nv, ohd, mind)
(2) use omp_lib
(3) !some other code including variable declarations
(4) !$omp parallel private(my_first, my_id, my_last, my_md, my_mv, my_step)
(5) !$omp shared   (connected, md, mind, mv, nth, ohd)
(6) my_id = omp_get_thread_num   ( )
(7) nth = omp_get_num_threads   ( )
(8) my_first = ( my_id * nv ) / nth + 1
(9)   my_last = (( my_id + 1) * nv ) / nth
(10)   do step = 2, nv
(11)   call find_nearest(my_first, my_last, nv, mind, connected, my_md, my_mv)
(12) !$omp critical
(13)   if ( my_md < md ) then
(14)   md = my_md
(15)   mv = my_mv
(16)   end if
(17) !$omp end critical
(18) !$omp barrier
(19) !$omp single
(20)   if(mv/=-1) then
(21)   connected(mv) =.true.
(22)   end if
(23) !$omp end single
(24) !$omp barrier
(25)   if(mv/=-1) then
(26)   call update_mind(my_first, my_last, nv, connected, ohd, mv, mind)
(27)   end if
(28) !$omp barrier
(29)   end do
(30) !$omp end parallel
(31) end