Skip to content

Commit e722771

Browse files
committed
refac(mod_parallel): mv procedure def to submodule
1 parent a3530af commit e722771

File tree

2 files changed

+39
-23
lines changed

2 files changed

+39
-23
lines changed

src/mod_parallel.f90

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,16 @@ module mod_parallel
66
private
77
public :: tile_indices
88

9-
contains
10-
11-
pure function tile_indices(dims)
12-
!! Given input global array size, return start and end index
13-
!! of a parallel 1-d tile that correspond to this image.
14-
integer(ik), intent(in) :: dims
15-
integer(ik) :: tile_indices(2)
16-
integer(ik) :: offset, tile_size
17-
18-
tile_size = dims / num_images()
19-
20-
!! start and end indices assuming equal tile sizes
21-
tile_indices(1) = (this_image() - 1) * tile_size + 1
22-
tile_indices(2) = tile_indices(1) + tile_size - 1
23-
24-
!! if we have any remainder, distribute it to the tiles at the end
25-
offset = num_images() - mod(dims, num_images())
26-
if (this_image() > offset) then
27-
tile_indices(1) = tile_indices(1) + this_image() - offset - 1
28-
tile_indices(2) = tile_indices(2) + this_image() - offset
29-
end if
30-
31-
end function tile_indices
9+
interface
10+
11+
pure module function tile_indices(dims)
12+
!! Given input global array size, return start and end index
13+
!! of a parallel 1-d tile that correspond to this image.
14+
implicit none
15+
integer(ik), intent(in) :: dims
16+
integer(ik) :: tile_indices(2)
17+
end function tile_indices
18+
19+
end interface
3220

3321
end module mod_parallel

src/mod_parallel_submodule.f90

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
submodule(mod_parallel) mod_parallel_submodule
2+
3+
use mod_kinds, only: ik, rk
4+
implicit none
5+
6+
contains
7+
8+
pure module function tile_indices(dims)
9+
integer(ik), intent(in) :: dims
10+
integer(ik) :: tile_indices(2)
11+
integer(ik) :: offset, tile_size
12+
13+
tile_size = dims / num_images()
14+
15+
!! start and end indices assuming equal tile sizes
16+
tile_indices(1) = (this_image() - 1) * tile_size + 1
17+
tile_indices(2) = tile_indices(1) + tile_size - 1
18+
19+
!! if we have any remainder, distribute it to the tiles at the end
20+
offset = num_images() - mod(dims, num_images())
21+
if (this_image() > offset) then
22+
tile_indices(1) = tile_indices(1) + this_image() - offset - 1
23+
tile_indices(2) = tile_indices(2) + this_image() - offset
24+
end if
25+
26+
end function tile_indices
27+
28+
end submodule mod_parallel_submodule

0 commit comments

Comments
 (0)