Skip to content

Commit dc10a5b

Browse files
authored
Merge pull request #180 from BerkeleyLab/match-paper
Documentation: match laplacian function comments to AI4Dev paper
2 parents 2b1f3b2 + f39eda1 commit dc10a5b

2 files changed

Lines changed: 33 additions & 22 deletions

File tree

include/language-support.F90

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
! Copyright (c), The Regents of the University of California
22
! Terms of use are as specified in LICENSE.txt
33

4+
#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
5+
46
#ifndef HAVE_PROCEDURE_ACTUAL_FOR_POINTER_DUMMY
57
! Define whether the compiler supports associating a procedure pointer dummy argument with an
68
! actual argument that is a valid target for the pointer dummy in a procedure assignment, a
@@ -12,6 +14,15 @@
1214
# endif
1315
#endif
1416

17+
#ifndef HAVE_2018_LOCALITY_SPECIFIERS
18+
! Define whether the compiler supports locality specifiers in `do concurrent`
19+
# if defined(_CRAYFTN) || defined(__INTEL_COMPILER) || defined(NAGFOR) || defined(__flang__) || (GCC_VERSION > 150000)
20+
# define HAVE_2018_LOCALITY_SPECIFIERS 1
21+
# else
22+
# define HAVE_2018_LOCALITY_SPECIFIERS 0
23+
# endif
24+
#endif
25+
1526
#ifndef HAVE_CRITICAL
1627
! Define whether the compiler supports the `critical` and `end critical` statements
1728
# if defined(_CRAYFTN) || defined(__INTEL_COMPILER) || defined(NAGFOR) || defined(__GFORTRAN__)

src/matcha/subdomain_s.F90

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
submodule(subdomain_m) subdomain_s
77
use assert_m
88
use julienne_m, only : bin_t
9-
use intrinsic_array_m, only : intrinsic_array_t
109
implicit none
1110

1211
real, allocatable :: halo_x(:,:,:)[:]
@@ -37,7 +36,7 @@
3736
dy_ = dx_
3837
dz_ = dx_
3938

40-
call_assert_diagnose(num_subdomains <= nx-nx_boundaries, "subdomain_t%define: num_subdomains <= nx-nx_boundaries", intrinsic_array_t([nx, num_subdomains]))
39+
call_assert(num_subdomains <= nx-nx_boundaries)
4140

4241
me = this_image()
4342
num_subdomains = num_images()
@@ -82,34 +81,34 @@
8281
end procedure
8382

8483
module procedure laplacian
85-
integer i, j, k;
84+
integer i, j, k
8685
real, allocatable :: halo_west(:,:), halo_east(:,:)
8786

8887
call_assert(allocated(rhs%s_))
8988
call_assert(allocated(halo_x))
9089

9190
allocate(laplacian_rhs%s_(my_nx, ny, nz))
92-
halo_west = merge(halo_x(west,:,:), rhs%s_(1,:,:), me/=1)
91+
halo_west = merge(halo_x(west,:,:), rhs%s_(1,:,:), me/=1) ! conditionally use halo value
9392
i = my_internal_west
9493
call_assert_describe(i+1<=my_nx, "laplacian: westernmost subdomain too small")
95-
94+
! Compute Laplacians throughout the low-x boundary subdomain using non-allocatable associations:
9695
associate( laplacian_phi => laplacian_rhs%s_, inbox => halo_west, phi=>rhs%s_)
9796
#if HAVE_2018_LOCALITY_SPECIFIERS
9897
do concurrent(j=2:ny-1, k=2:nz-1) &
99-
default(none) shared(laplacian_phi, inbox, phi, dx_, dy_, dz_, i)
98+
default(none) shared(laplacian_phi, inbox, phi, dx_, dy_, dz_, i) !Fortran 2018 loacality specifiers
10099
#else
101-
do concurrent(j=2:ny-1, k=2:nz-1)
100+
do concurrent(j=2:ny-1, k=2:nz-1)
102101
#endif
103102
laplacian_phi(i,j,k) = (inbox(j,k ) - 2*phi(i,j,k) + phi(i+1,j ,k ))/dx_**2 + &
104103
(phi(i,j-1,k ) - 2*phi(i,j,k) + phi(i ,j+1,k ))/dy_**2 + &
105104
(phi(i,j ,k-1) - 2*phi(i,j,k) + phi(i ,j ,k+1))/dz_**2
106105
end do
107106
end associate
108-
109-
associate(laplacian_phi => laplacian_rhs%s_, phi=>rhs%s_)
107+
! Compute Laplacians throughout non-boundary subdomains with non-allocatable associations:
108+
associate(laplacian_phi => laplacian_rhs%s_, phi=>rhs%s_)
110109
#if HAVE_2018_LOCALITY_SPECIFIERS
111110
do concurrent(i=my_internal_west+1:my_internal_east-1, j=2:ny-1, k=2:nz-1) &
112-
default(none) shared(laplacian_phi, phi, dx_, dy_, dz_)
111+
default(none) shared(laplacian_phi, phi, dx_, dy_, dz_) ! Fortran 2018 locality specifiers
113112
#else
114113
do concurrent(i=my_internal_west+1:my_internal_east-1, j=2:ny-1, k=2:nz-1)
115114
#endif
@@ -119,29 +118,30 @@
119118
end do
120119
end associate
121120

122-
halo_east = merge(halo_x(east,:,:), rhs%s_(my_nx,:,:), me/=num_subdomains)
121+
halo_east = merge(halo_x(east,:,:), rhs%s_(my_nx,:,:), me/=num_subdomains) !conditionally use halo value
123122
i = my_internal_east
124123
call_assert_describe(i-1>0, "laplacian: easternmost subdomain too small")
125-
124+
! Compute Laplacians throughout the high-x boundary subdomain using non-allocatable associations:
126125
associate(laplacian_phi => laplacian_rhs%s_, inbox => halo_east, phi=>rhs%s_)
127126
#if HAVE_2018_LOCALITY_SPECIFIERS
128-
do concurrent(j=2:ny-1, k=2:nz-1) &
129-
default(none) shared(laplacian_phi, inbox, phi, dx_, dy_, dz_, i)
127+
do concurrent(j=2:ny-1, k=2:nz-1) & ! compute Laplacian in low-x boundary subdomain
128+
default(none) shared(laplacian_phi, inbox, phi, dx_, dy_, dz_, i) ! Fortran 2018 locality specifiers
130129
#else
131-
do concurrent(j=2:ny-1, k=2:nz-1)
130+
do concurrent(j=2:ny-1, k=2:nz-1) ! compute Laplacian in low-x boundary subdomain
132131
#endif
133132
laplacian_phi(i,j,k) = (phi(i-1,j ,k ) - 2*phi(i,j,k) + inbox( j ,k ))/dx_**2 + &
134133
(phi(i ,j-1,k ) - 2*phi(i,j,k) + phi(i ,j+1,k ))/dy_**2 + &
135134
(phi(i ,j ,k-1) - 2*phi(i,j,k) + phi(i ,j ,k+1))/dz_**2
136135
end do
137136
end associate
138137

139-
laplacian_rhs%s_(:, 1,:) = 0. ! y-direction low boundary
140-
laplacian_rhs%s_(:,ny,:) = 0. ! y-direction high boundary
141-
laplacian_rhs%s_(:,:, 1) = 0. ! z-direction low boundary
142-
laplacian_rhs%s_(:,:,nz) = 0. ! z-direction high boundary
143-
if (me==1) laplacian_rhs%s_(1,:,:) = 0. ! x-direction low boundary
144-
if (me==num_subdomains) laplacian_rhs%s_(my_nx,:,:) = 0. ! x-direction high boundary
138+
laplacian_rhs%s_(:, 1,:) = 0. ! low-y boundary
139+
laplacian_rhs%s_(:,ny,:) = 0. ! high-y boundary
140+
laplacian_rhs%s_(:,:, 1) = 0. ! low-z boundary
141+
laplacian_rhs%s_(:,:,nz) = 0. ! high-z boundary
142+
143+
if (me==1) laplacian_rhs%s_(1,:,:) = 0. ! low-x boundary
144+
if (me==num_subdomains) laplacian_rhs%s_(my_nx,:,:) = 0. ! high-x boundary
145145
end procedure
146146

147147
module procedure multiply
@@ -246,4 +246,4 @@ subroutine exchange_halo(s)
246246

247247
end procedure
248248

249-
end submodule subdomain_s
249+
end submodule subdomain_s

0 commit comments

Comments
 (0)