Skip to content

Commit 0e5632f

Browse files
committed
refac(data_partition_t): simply by using bin_t
1 parent abc5361 commit 0e5632f

File tree

2 files changed

+8
-35
lines changed

2 files changed

+8
-35
lines changed

src/sourcery/data_partition_m.f90

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ module data_partition_m
1818
generic :: gather => gather_real32_2D_array, gather_real64_2D_array, gather_real32_1D_array, gather_real64_1D_array
1919
end type
2020

21-
integer, allocatable :: first_datum(:), last_datum(:)
22-
2321
interface
2422

2523
module subroutine define_partitions(cardinality)

src/sourcery/data_partition_s.f90

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,26 @@
11
submodule(data_partition_m) data_partition_s
22
use assert_m, only : assert
3+
use bin_m, only : bin_t
34
implicit none
45

56
logical, parameter :: verbose=.false.
7+
type(bin_t), allocatable :: bin(:)
68

79
contains
810

911
module procedure define_partitions
10-
11-
if (allocated(first_datum)) deallocate(first_datum)
12-
if (allocated(last_datum)) deallocate(last_datum)
13-
14-
associate( ni => num_images() )
15-
16-
call assert( ni<=cardinality, "sufficient data for distribution across images", cardinality)
17-
18-
allocate(first_datum(ni), last_datum(ni))
19-
20-
block
21-
integer i, image
22-
do image=1,ni
23-
associate( remainder => mod(cardinality, ni), quotient => cardinality/ni )
24-
first_datum(image) = sum([(quotient+overflow(i, remainder), i=1, image-1)]) + 1
25-
last_datum(image) = first_datum(image) + quotient + overflow(image, remainder) - 1
26-
end associate
27-
end do
28-
end block
29-
end associate
30-
31-
contains
32-
33-
pure function overflow(im, excess) result(extra_datum)
34-
integer, intent(in) :: im, excess
35-
integer extra_datum
36-
extra_datum= merge(1,0,im<=excess)
37-
end function
38-
12+
integer image
13+
bin = [( bin_t(num_items=cardinality, num_bins=num_images(), bin_number=image), image=1,num_images() )]
3914
end procedure
4015

4116
module procedure first
42-
call assert( allocated(first_datum), "allocated(first_datum)")
43-
first_index= first_datum( image_number )
17+
call assert( allocated(bin), "data_partition_s(first): allocated(bin)")
18+
first_index = bin(image_number)%first(image_number)
4419
end procedure
4520

4621
module procedure last
47-
call assert( allocated(last_datum), "allocated(last_datum)")
48-
last_index = last_datum( image_number )
22+
call assert( allocated(bin), "data_partition_s(last): allocated(bin)")
23+
last_index = bin(image_number)%last(image_number)
4924
end procedure
5025

5126
module procedure gather_real32_1D_array

0 commit comments

Comments
 (0)