Skip to content

Commit 060e982

Browse files
committed
Apply codee-format
1 parent edb050f commit 060e982

File tree

8 files changed

+234
-222
lines changed

8 files changed

+234
-222
lines changed

examples/Fortran/example.f90

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ program main
1919
do
2020
if (.not.lb%get_range(bot, top)) exit
2121
do j = bot, top
22-
block
23-
real(8), allocatable :: a(:,:), b(:,:), c(:,:)
24-
i = 3 * (100 - j) + 200
25-
allocate(a(i,i),b(i,i),c(i,i))
26-
call random_number(a)
27-
call random_number(b)
28-
c = matmul(a,b)
29-
write(7,'(I6,ES15.8)') j, sum(c)
30-
deallocate(a,b,c)
31-
end block
22+
block
23+
real(8), allocatable :: a(:, :), b(:, :), c(:, :)
24+
i = 3 * (100 - j) + 200
25+
allocate(a(i, i), b(i, i), c(i, i))
26+
call random_number(a)
27+
call random_number(b)
28+
c = matmul(a, b)
29+
write(7, '(I6,ES15.8)') j, sum(c)
30+
deallocate(a, b, c)
31+
end block
3232
end do
3333
end do
3434
print '(A)', "Done!"

src/Fortran/abstract_load_balancer.f90

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@ module SLB4MPI_abstract_load_balancer_m
1515

1616
type, abstract :: load_balancer_t
1717
integer(MPI_INTEGER_KIND) :: communicator !< MPI communicator
18-
integer(MPI_INTEGER_KIND) :: rank !< Rank of the process
19-
integer(MPI_INTEGER_KIND) :: root = 0 !< Rank of the root process
20-
integer(MPI_INTEGER_KIND) :: nranks !< Number of processes (group size)
21-
integer(8) :: lower_bound !< Lower bound of range
22-
integer(8) :: upper_bound !< Upper bound of range
23-
integer(8) :: min_chunk_size !< Minimal chunk size for job
24-
integer(8) :: max_chunk_size !< Maximal chunk size for job
25-
contains
18+
integer(MPI_INTEGER_KIND) :: rank !< Rank of the process
19+
integer(MPI_INTEGER_KIND) :: root = 0 !< Rank of the root process
20+
integer(MPI_INTEGER_KIND) :: nranks !< Number of processes (group size)
21+
integer(8) :: lower_bound !< Lower bound of range
22+
integer(8) :: upper_bound !< Upper bound of range
23+
integer(8) :: min_chunk_size !< Minimal chunk size for job
24+
integer(8) :: max_chunk_size !< Maximal chunk size for job
25+
contains
2626
procedure(initialize), deferred, public :: initialize
27-
procedure(get_range), deferred, public :: get_range
28-
procedure(clean), deferred, public :: clean
27+
procedure(get_range), deferred, public :: get_range
28+
procedure(clean), deferred, public :: clean
2929

3030
procedure :: default_initialize
31-
end type
31+
end type load_balancer_t
3232

3333
abstract interface
3434

@@ -44,10 +44,10 @@ module SLB4MPI_abstract_load_balancer_m
4444
!>
4545
subroutine initialize(lb, communicator, lower_bound, upper_bound, min_chunk_size, max_chunk_size)
4646
import load_balancer_t, MPI_INTEGER_KIND
47-
class(load_balancer_t), intent(inout) :: lb
48-
integer(MPI_INTEGER_KIND), intent(in) :: communicator
49-
integer(8), intent(in) :: lower_bound, upper_bound
50-
integer(8), optional, intent(in) :: min_chunk_size, max_chunk_size
47+
class(load_balancer_t), intent(inout) :: lb
48+
integer(MPI_INTEGER_KIND), intent(in) :: communicator
49+
integer(8), intent(in) :: lower_bound, upper_bound
50+
integer(8), optional, intent(in) :: min_chunk_size, max_chunk_size
5151
end subroutine initialize
5252

5353
!>
@@ -64,7 +64,7 @@ end subroutine initialize
6464
logical function get_range(lb, lower_bound, upper_bound)
6565
import load_balancer_t
6666
class(load_balancer_t), intent(inout) :: lb
67-
integer(8), intent(out) :: lower_bound, upper_bound
67+
integer(8), intent(out) :: lower_bound, upper_bound
6868
end function get_range
6969

7070
!>
@@ -94,10 +94,10 @@ end subroutine clean
9494
!> @param[in] max_chunk_size - maximal size of chank that can be associated with job, default: upper_bound - lower_bound + 1
9595
!>
9696
subroutine default_initialize(lb, communicator, lower_bound, upper_bound, min_chunk_size, max_chunk_size)
97-
class(load_balancer_t), intent(inout) :: lb
98-
integer(MPI_INTEGER_KIND), intent(in) :: communicator
99-
integer(8), intent(in) :: lower_bound, upper_bound
100-
integer(8), optional, intent(in) :: min_chunk_size, max_chunk_size
97+
class(load_balancer_t), intent(inout) :: lb
98+
integer(MPI_INTEGER_KIND), intent(in) :: communicator
99+
integer(8), intent(in) :: lower_bound, upper_bound
100+
integer(8), optional, intent(in) :: min_chunk_size, max_chunk_size
101101

102102
integer(MPI_INTEGER_KIND) :: ierr
103103

src/Fortran/dynamic_load_balancer.f90

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ module SLB4MPI_dynamic_load_balancer_m
88

99
type, extends(load_balancer_t) :: dynamic_load_balancer_t
1010
#ifdef SLB4MPI_WITH_MPI
11-
integer(MPI_INTEGER_KIND) :: window !< sync window
11+
integer(MPI_INTEGER_KIND) :: window !< sync window
1212
#else
1313
integer(MPI_INTEGER_KIND) :: counter !< evaluation index
1414
#endif
15-
contains
15+
contains
1616
procedure :: initialize
1717
procedure :: get_range
1818
procedure :: clean
19-
end type
19+
end type dynamic_load_balancer_t
2020

2121
interface
2222

@@ -38,9 +38,9 @@ module SLB4MPI_dynamic_load_balancer_m
3838
subroutine initialize(lb, communicator, lower_bound, upper_bound, min_chunk_size, max_chunk_size)
3939
use, intrinsic :: iso_c_binding, only: c_ptr, c_f_pointer
4040
class(dynamic_load_balancer_t), intent(inout) :: lb
41-
integer(MPI_INTEGER_KIND), intent(in) :: communicator
42-
integer(8), intent(in) :: lower_bound, upper_bound
43-
integer(8), optional, intent(in) :: min_chunk_size, max_chunk_size
41+
integer(MPI_INTEGER_KIND), intent(in) :: communicator
42+
integer(8), intent(in) :: lower_bound, upper_bound
43+
integer(8), optional, intent(in) :: min_chunk_size, max_chunk_size
4444

4545
integer(MPI_ADDRESS_KIND) :: size
4646
integer(MPI_INTEGER_KIND) :: disp_unit, ierr

src/Fortran/guided_load_balancer.f90

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ module SLB4MPI_guided_load_balancer_m
88

99
type, extends(load_balancer_t) :: guided_load_balancer_t
1010
#ifdef SLB4MPI_WITH_MPI
11-
integer(MPI_INTEGER_KIND) :: window !< sync window
11+
integer(MPI_INTEGER_KIND) :: window !< sync window
1212
#else
1313
integer(MPI_INTEGER_KIND) :: counter !< evaluation index
1414
#endif
15-
contains
15+
contains
1616
procedure :: initialize
1717
procedure :: get_range
1818
procedure :: clean
19-
end type
19+
end type guided_load_balancer_t
2020

2121
interface
2222

@@ -38,9 +38,9 @@ module SLB4MPI_guided_load_balancer_m
3838
subroutine initialize(lb, communicator, lower_bound, upper_bound, min_chunk_size, max_chunk_size)
3939
use, intrinsic :: iso_c_binding, only: c_ptr, c_f_pointer
4040
class(guided_load_balancer_t), intent(inout) :: lb
41-
integer(MPI_INTEGER_KIND), intent(in) :: communicator
42-
integer(8), intent(in) :: lower_bound, upper_bound
43-
integer(8), optional, intent(in) :: min_chunk_size, max_chunk_size
41+
integer(MPI_INTEGER_KIND), intent(in) :: communicator
42+
integer(8), intent(in) :: lower_bound, upper_bound
43+
integer(8), optional, intent(in) :: min_chunk_size, max_chunk_size
4444

4545
integer(MPI_ADDRESS_KIND) :: size
4646
integer(MPI_INTEGER_KIND) :: disp_unit, ierr
@@ -89,7 +89,8 @@ logical function get_range(lb, lower_bound, upper_bound) result(to_compute)
8989

9090
#ifdef SLB4MPI_WITH_MPI
9191
call MPI_Win_lock(MPI_LOCK_EXCLUSIVE, lb%root, 0_MPI_INTEGER_KIND, lb%window, ierr)
92-
call MPI_Get(root_counter, 1_MPI_INTEGER_KIND, MPI_INTEGER8, lb%root, 0_MPI_ADDRESS_KIND, 1_MPI_INTEGER_KIND, MPI_INTEGER8, lb%window, ierr)
92+
call MPI_Get(root_counter, 1_MPI_INTEGER_KIND, MPI_INTEGER8, lb%root, 0_MPI_ADDRESS_KIND, 1_MPI_INTEGER_KIND, MPI_INTEGER8, &
93+
lb%window, ierr)
9394
call MPI_Win_flush(lb%root, lb%window, ierr)
9495
associated_tasks = min(max((lb%upper_bound - root_counter) / lb%nranks, lb%min_chunk_size), lb%max_chunk_size)
9596
call MPI_Fetch_and_op(associated_tasks, lower_bound, MPI_INTEGER8, lb%root, 0_MPI_ADDRESS_KIND, MPI_SUM, lb%window, ierr)

src/Fortran/local_static_load_balancer.f90

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ module SLB4MPI_local_static_load_balancer_m
66
type, extends(load_balancer_t) :: local_static_load_balancer_t
77
private
88
integer(8) :: counter
9-
contains
9+
contains
1010
procedure :: initialize
1111
procedure :: get_range
1212
procedure :: clean
13-
end type
13+
end type local_static_load_balancer_t
1414

1515
interface
1616

@@ -31,9 +31,9 @@ module SLB4MPI_local_static_load_balancer_m
3131
!>
3232
subroutine initialize(lb, communicator, lower_bound, upper_bound, min_chunk_size, max_chunk_size)
3333
class(local_static_load_balancer_t), intent(inout) :: lb
34-
integer(MPI_INTEGER_KIND), intent(in) :: communicator
35-
integer(8), intent(in) :: lower_bound, upper_bound
36-
integer(8), optional, intent(in) :: min_chunk_size, max_chunk_size
34+
integer(MPI_INTEGER_KIND), intent(in) :: communicator
35+
integer(8), intent(in) :: lower_bound, upper_bound
36+
integer(8), optional, intent(in) :: min_chunk_size, max_chunk_size
3737
!
3838
integer(8) :: n_tasks, extra_tasks
3939

@@ -42,16 +42,16 @@ subroutine initialize(lb, communicator, lower_bound, upper_bound, min_chunk_size
4242
n_tasks = (upper_bound - lower_bound + 1) / lb%nranks
4343
extra_tasks = mod(upper_bound - lower_bound + 1, lb%nranks)
4444
if (n_tasks < min_chunk_size) then
45-
n_tasks = min_chunk_size
46-
extra_tasks = 0
45+
n_tasks = min_chunk_size
46+
extra_tasks = 0
4747
end if
4848

4949
if (lb%rank < extra_tasks) then
50-
lb%lower_bound = lb%rank * (n_tasks + 1) + lower_bound
51-
lb%upper_bound = (lb%rank + 1) * (n_tasks + 1) + lower_bound - 1
50+
lb%lower_bound = lb%rank * (n_tasks + 1) + lower_bound
51+
lb%upper_bound = (lb%rank + 1) * (n_tasks + 1) + lower_bound - 1
5252
else
53-
lb%lower_bound = lb%rank * n_tasks + extra_tasks + lower_bound
54-
lb%upper_bound = (lb%rank + 1) * n_tasks + extra_tasks + lower_bound - 1
53+
lb%lower_bound = lb%rank * n_tasks + extra_tasks + lower_bound
54+
lb%upper_bound = (lb%rank + 1) * n_tasks + extra_tasks + lower_bound - 1
5555
end if
5656

5757
lb%lower_bound = min(lb%lower_bound, upper_bound + 1)
@@ -74,7 +74,7 @@ end subroutine initialize
7474
!>
7575
logical function get_range(lb, lower_bound, upper_bound) result(to_compute)
7676
class(local_static_load_balancer_t), intent(inout) :: lb
77-
integer(8), intent(out) :: lower_bound, upper_bound
77+
integer(8), intent(out) :: lower_bound, upper_bound
7878

7979
to_compute = .true.
8080

src/Fortran/runtime_load_balancer.f90

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ module SLB4MPI_runtime_load_balancer_m
1818

1919
type, extends(load_balancer_t) :: runtime_load_balancer_t
2020
class(load_balancer_t), allocatable :: balancer !< actual load balancer
21-
contains
21+
contains
2222
procedure :: initialize
2323
procedure :: get_range
2424
procedure :: clean
25-
end type
25+
end type runtime_load_balancer_t
2626

2727
interface
2828

@@ -45,42 +45,42 @@ module SLB4MPI_runtime_load_balancer_m
4545
subroutine initialize(lb, communicator, lower_bound, upper_bound, min_chunk_size, max_chunk_size)
4646
use, intrinsic :: iso_c_binding, only: c_ptr, c_f_pointer
4747
class(runtime_load_balancer_t), intent(inout) :: lb
48-
integer(MPI_INTEGER_KIND), intent(in) :: communicator
49-
integer(8), intent(in) :: lower_bound, upper_bound
50-
integer(8), optional, intent(in) :: min_chunk_size, max_chunk_size
48+
integer(MPI_INTEGER_KIND), intent(in) :: communicator
49+
integer(8), intent(in) :: lower_bound, upper_bound
50+
integer(8), optional, intent(in) :: min_chunk_size, max_chunk_size
5151

5252
if (load_balancer_type == ENV_LOAD_BALANCER) then
53-
block
54-
use, intrinsic :: iso_fortran_env, only: error_unit
55-
character(len=80) :: envval
56-
logical :: ok
57-
call get_environment_variable("SLB4MPI_LOAD_BALANCER", envval)
58-
call SLB4MPI_set_schedule(trim(envval), ok)
59-
if (len_trim(envval) /= 0 .and. (.not.ok .or. trim(envval) == 'env')) then
60-
write(error_unit, '(A)') "SLB4MPI_LOAD_BALANCER environmental variable is not set properly!"
61-
write(error_unit, '(A)') "Actual value is '" // trim(envval) // "'"
62-
write(error_unit, '(A)') "Possible values are: static, local_static, dynamic, guided, work_stealing"
63-
write(error_unit, '(A)') "static load balancer will be used!"
64-
call SLB4MPI_set_schedule("static")
65-
else if (len_trim(envval) == 0) then
66-
call SLB4MPI_set_schedule("static")
67-
end if
68-
end block
53+
block
54+
use, intrinsic :: iso_fortran_env, only: error_unit
55+
character(len=80) :: envval
56+
logical :: ok
57+
call get_environment_variable("SLB4MPI_LOAD_BALANCER", envval)
58+
call SLB4MPI_set_schedule(trim(envval), ok)
59+
if (len_trim(envval) /= 0 .and. (.not.ok .or. trim(envval) == 'env')) then
60+
write(error_unit, '(A)') "SLB4MPI_LOAD_BALANCER environmental variable is not set properly!"
61+
write(error_unit, '(A)') "Actual value is '" // trim(envval) // "'"
62+
write(error_unit, '(A)') "Possible values are: static, local_static, dynamic, guided, work_stealing"
63+
write(error_unit, '(A)') "static load balancer will be used!"
64+
call SLB4MPI_set_schedule("static")
65+
else if (len_trim(envval) == 0) then
66+
call SLB4MPI_set_schedule("static")
67+
end if
68+
end block
6969
end if
7070

7171
select case (load_balancer_type)
72-
case(STATIC_LOAD_BALANCER)
73-
allocate(static_load_balancer_t :: lb%balancer)
74-
case(LOCAL_STATIC_LOAD_BALANCER)
75-
allocate(local_static_load_balancer_t :: lb%balancer)
76-
case(DYNAMIC_LOAD_BALANCER)
77-
allocate(dynamic_load_balancer_t :: lb%balancer)
78-
case(GUIDED_LOAD_BALANCER)
79-
allocate(guided_load_balancer_t :: lb%balancer)
80-
case(WORK_STEALING_LOAD_BALANCER)
81-
allocate(work_stealing_load_balancer_t :: lb%balancer)
82-
case default
83-
error stop "Unknown load balancer"
72+
case (STATIC_LOAD_BALANCER)
73+
allocate(static_load_balancer_t :: lb%balancer)
74+
case (LOCAL_STATIC_LOAD_BALANCER)
75+
allocate(local_static_load_balancer_t :: lb%balancer)
76+
case (DYNAMIC_LOAD_BALANCER)
77+
allocate(dynamic_load_balancer_t :: lb%balancer)
78+
case (GUIDED_LOAD_BALANCER)
79+
allocate(guided_load_balancer_t :: lb%balancer)
80+
case (WORK_STEALING_LOAD_BALANCER)
81+
allocate(work_stealing_load_balancer_t :: lb%balancer)
82+
case default
83+
error stop "Unknown load balancer"
8484
end select
8585

8686
call lb%balancer%initialize(communicator, lower_bound, upper_bound, min_chunk_size, max_chunk_size)
@@ -125,21 +125,21 @@ subroutine SLB4MPI_set_schedule(lbtype, ok)
125125
logical, optional, intent(out) :: ok
126126
logical :: ok_
127127
ok_ = .true.
128-
select case(lbtype)
129-
case ("env")
130-
load_balancer_type = ENV_LOAD_BALANCER
131-
case ("static")
132-
load_balancer_type = STATIC_LOAD_BALANCER
133-
case ("local_static")
134-
load_balancer_type = LOCAL_STATIC_LOAD_BALANCER
135-
case ("dynamic")
136-
load_balancer_type = DYNAMIC_LOAD_BALANCER
137-
case ("guided")
138-
load_balancer_type = GUIDED_LOAD_BALANCER
139-
case ("work_stealing")
140-
load_balancer_type = WORK_STEALING_LOAD_BALANCER
141-
case default
142-
ok_ = .false.
128+
select case (lbtype)
129+
case ("env")
130+
load_balancer_type = ENV_LOAD_BALANCER
131+
case ("static")
132+
load_balancer_type = STATIC_LOAD_BALANCER
133+
case ("local_static")
134+
load_balancer_type = LOCAL_STATIC_LOAD_BALANCER
135+
case ("dynamic")
136+
load_balancer_type = DYNAMIC_LOAD_BALANCER
137+
case ("guided")
138+
load_balancer_type = GUIDED_LOAD_BALANCER
139+
case ("work_stealing")
140+
load_balancer_type = WORK_STEALING_LOAD_BALANCER
141+
case default
142+
ok_ = .false.
143143
end select
144144
if (present(ok)) ok = ok_
145145
end subroutine SLB4MPI_set_schedule

src/Fortran/static_load_balancer.f90

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ module SLB4MPI_static_load_balancer_m
66
type, extends(load_balancer_t) :: static_load_balancer_t
77
private
88
integer(8) :: counter
9-
contains
9+
contains
1010
procedure :: initialize
1111
procedure :: get_range
1212
procedure :: clean
13-
end type
13+
end type static_load_balancer_t
1414

1515
interface
1616

@@ -31,9 +31,9 @@ module SLB4MPI_static_load_balancer_m
3131
!>
3232
subroutine initialize(lb, communicator, lower_bound, upper_bound, min_chunk_size, max_chunk_size)
3333
class(static_load_balancer_t), intent(inout) :: lb
34-
integer(MPI_INTEGER_KIND), intent(in) :: communicator
35-
integer(8), intent(in) :: lower_bound, upper_bound
36-
integer(8), optional, intent(in) :: min_chunk_size, max_chunk_size
34+
integer(MPI_INTEGER_KIND), intent(in) :: communicator
35+
integer(8), intent(in) :: lower_bound, upper_bound
36+
integer(8), optional, intent(in) :: min_chunk_size, max_chunk_size
3737

3838
call lb%default_initialize(communicator, lower_bound, upper_bound, min_chunk_size, max_chunk_size)
3939

@@ -54,7 +54,7 @@ end subroutine initialize
5454
!>
5555
logical function get_range(lb, lower_bound, upper_bound) result(to_compute)
5656
class(static_load_balancer_t), intent(inout) :: lb
57-
integer(8), intent(out) :: lower_bound, upper_bound
57+
integer(8), intent(out) :: lower_bound, upper_bound
5858

5959
to_compute = .true.
6060

0 commit comments

Comments
 (0)