|
1 | 1 | submodule(data_partition_m) data_partition_s
|
2 | 2 | use assert_m, only : assert
|
| 3 | + use bin_m, only : bin_t |
3 | 4 | implicit none
|
4 | 5 |
|
5 | 6 | logical, parameter :: verbose=.false.
|
| 7 | + type(bin_t), allocatable :: bin(:) |
6 | 8 |
|
7 | 9 | contains
|
8 | 10 |
|
9 | 11 | 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() )] |
39 | 14 | end procedure
|
40 | 15 |
|
41 | 16 | 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() |
44 | 19 | end procedure
|
45 | 20 |
|
46 | 21 | 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() |
49 | 24 | end procedure
|
50 | 25 |
|
51 | 26 | module procedure gather_real32_1D_array
|
|
0 commit comments