Skip to content

Commit d5d0faa

Browse files
authored
Merge pull request #191 from BerkeleyLab/merge-upstream-main
chore: merge main into vibe-coding branch
2 parents a606798 + 603a6b2 commit d5d0faa

6 files changed

Lines changed: 50 additions & 49 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ Change '2' above to the number of images that you would like to launch in parall
3737
#### Multi-image (parallel) execution
3838
The unit test suite uses small grids to minimize runtime, which limits the scalability of the test suite only.
3939
Hence, the test suite is _not_ designed for execution in a large number of images.
40-
All tests pass when running the test suite in 1-4 images:
40+
41+
All tests pass when running the test suite in 1-4 images:
4142
```
4243
export FOR_COARRAY_NUM_IMAGES=4
4344
fpm test --compiler ifx --profile release --flag "-heap-arrays -coarray"

doc/ai4dev/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Vibe Coding
2020
```
2121
4. Use the contents of [vibe-coding/README.md](./vibe-coding/README.md) as your
2222
prompt to a large language model (LLM).
23-
5. Use an editor to edit the test-suite.F90 lines beginning and ending with
23+
5. Use an editor to edit the test-suite.F90 lines beginning and ending with
2424
`module procedure laplacian` and `end procedure laplacian`, respectively,
2525
replacing those lines with the LLM's response.
2626
6. Compile test-suite.F90 as in step 2 again.
@@ -36,7 +36,7 @@ Vibe Coding
3636
but tests failed replace "compiling" with "running" and replace "errors"
3737
with "test failures".
3838
* Append LLM-generated code from the previous iteration.
39-
39+
4040
Idiomatic Vibe Coding
4141
---------------------
4242
Follow the [vibe coding](#vibe-coding) steps except as described below:

doc/ai4dev/idiomatic-vibe-coding/idiomatic-vibe-response.f90

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,87 +2,87 @@ pure module function laplacian(rhs) result(laplacian_rhs)
22
implicit none
33
class(subdomain_t), intent(in) :: rhs
44
type(subdomain_t) :: laplacian_rhs
5-
5+
66
! Local variables for array bounds and grid spacing
77
integer :: my_nx, ny, nz, me, num_subdomains
88
real :: dx_val, dy_val, dz_val, dx2_inv, dy2_inv, dz2_inv
9-
9+
1010
! Get array dimensions and parallel image information
1111
my_nx = size(rhs%s_, 1)
12-
ny = size(rhs%s_, 2)
12+
ny = size(rhs%s_, 2)
1313
nz = size(rhs%s_, 3)
1414
me = this_image()
1515
num_subdomains = num_images()
16-
16+
1717
! Get grid spacing values
1818
dx_val = rhs%dx()
19-
dy_val = rhs%dy()
19+
dy_val = rhs%dy()
2020
dz_val = rhs%dz()
21-
21+
2222
! Compute inverse squared grid spacings for efficiency
2323
dx2_inv = 1.0 / (dx_val * dx_val)
2424
dy2_inv = 1.0 / (dy_val * dy_val)
2525
dz2_inv = 1.0 / (dz_val * dz_val)
2626

2727
! Allocate result array with same shape as input
2828
allocate(laplacian_rhs%s_(my_nx, ny, nz))
29-
29+
3030
! Initialize result to zero
3131
laplacian_rhs%s_ = 0.0
32-
32+
3333
! Compute 2nd-order central difference Laplacian in interior points
34-
! Laplacian = d²/dx² + d²/dy² + d²/dz²
34+
! Laplacian = d2/dx2 + d2/dy2 + d2/dz2
3535
do concurrent (i = 2:my_nx-1, j = 2:ny-1, k = 2:nz-1) default(none) &
3636
shared(laplacian_rhs, rhs, dx2_inv, dy2_inv, dz2_inv, my_nx, ny, nz, me, num_subdomains)
37-
38-
! Second derivative in x-direction: (f(i+1) - 2*f(i) + f(i-1))/dx²
39-
! Second derivative in y-direction: (f(j+1) - 2*f(j) + f(j-1))/dy²
40-
! Second derivative in z-direction: (f(k+1) - 2*f(k) + f(k-1))/dz²
37+
38+
! Second derivative in x-direction: (f(i+1) - 2*f(i) + f(i-1))/dx2
39+
! Second derivative in y-direction: (f(j+1) - 2*f(j) + f(j-1))/dy2
40+
! Second derivative in z-direction: (f(k+1) - 2*f(k) + f(k-1))/dz2
4141
laplacian_rhs%s_(i,j,k) = &
4242
dx2_inv * (rhs%s_(i+1,j,k) - 2.0*rhs%s_(i,j,k) + rhs%s_(i-1,j,k)) + &
4343
dy2_inv * (rhs%s_(i,j+1,k) - 2.0*rhs%s_(i,j,k) + rhs%s_(i,j-1,k)) + &
4444
dz2_inv * (rhs%s_(i,j,k+1) - 2.0*rhs%s_(i,j,k) + rhs%s_(i,j,k-1))
4545
end do
46-
46+
4747
! Handle boundary conditions at subdomain interfaces for x-direction
4848
! Left boundary (i=1) - only compute if not the first subdomain
4949
if (me > 1) then
5050
do concurrent (j = 2:ny-1, k = 2:nz-1) default(none) &
5151
shared(laplacian_rhs, rhs, dx2_inv, dy2_inv, dz2_inv, ny, nz, halo_x)
52-
52+
5353
laplacian_rhs%s_(1,j,k) = &
5454
dx2_inv * (rhs%s_(2,j,k) - 2.0*rhs%s_(1,j,k) + halo_x(west,j,k)) + &
5555
dy2_inv * (rhs%s_(1,j+1,k) - 2.0*rhs%s_(1,j,k) + rhs%s_(1,j-1,k)) + &
5656
dz2_inv * (rhs%s_(1,j,k+1) - 2.0*rhs%s_(1,j,k) + rhs%s_(1,j,k-1))
5757
end do
5858
end if
59-
60-
! Right boundary (i=my_nx) - only compute if not the last subdomain
59+
60+
! Right boundary (i=my_nx) - only compute if not the last subdomain
6161
if (me < num_subdomains) then
6262
do concurrent (j = 2:ny-1, k = 2:nz-1) default(none) &
6363
shared(laplacian_rhs, rhs, dx2_inv, dy2_inv, dz2_inv, my_nx, ny, nz, halo_x, num_subdomains)
64-
64+
6565
laplacian_rhs%s_(my_nx,j,k) = &
6666
dx2_inv * (halo_x(east,j,k) - 2.0*rhs%s_(my_nx,j,k) + rhs%s_(my_nx-1,j,k)) + &
6767
dy2_inv * (rhs%s_(my_nx,j+1,k) - 2.0*rhs%s_(my_nx,j,k) + rhs%s_(my_nx,j-1,k)) + &
6868
dz2_inv * (rhs%s_(my_nx,j,k+1) - 2.0*rhs%s_(my_nx,j,k) + rhs%s_(my_nx,j,k-1))
6969
end do
7070
end if
71-
71+
7272
! Set boundary values to zero as specified
7373
! Y boundaries
7474
laplacian_rhs%s_(:, 1, :) = 0.0
7575
laplacian_rhs%s_(:, ny, :) = 0.0
76-
77-
! Z boundaries
76+
77+
! Z boundaries
7878
laplacian_rhs%s_(:, :, 1) = 0.0
7979
laplacian_rhs%s_(:, :, nz) = 0.0
80-
80+
8181
! X boundaries for first and last subdomains
8282
if (me == 1) then
8383
laplacian_rhs%s_(1, :, :) = 0.0
8484
end if
85-
85+
8686
if (me == num_subdomains) then
8787
laplacian_rhs%s_(my_nx, :, :) = 0.0
8888
end if
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
module procedure laplacian
22
! Separate module procedure for pure function laplacian
33
! Computes 2nd-order central-difference Laplacian operator
4-
4+
55
integer :: i, j, k
66
real, allocatable :: s_west(:,:), s_east(:,:)
7-
7+
88
! Allocate result array
99
allocate(laplacian_rhs%s_(my_nx, ny, nz))
10-
10+
1111
! Initialize result to zero
1212
laplacian_rhs%s_ = 0.0
13-
13+
1414
! Prepare halo data for boundary conditions
1515
allocate(s_west(ny, nz), s_east(ny, nz))
1616
s_west = merge(halo_x(west,:,:), 0.0, me == 1)
1717
s_east = merge(halo_x(east,:,:), 0.0, me == num_subdomains)
18-
18+
1919
! Compute Laplacian using do concurrent with proper boundary handling
2020
do concurrent (i = 1:my_nx, j = 1:ny, k = 1:nz) &
2121
default(none) shared(laplacian_rhs, rhs, s_west, s_east) &
2222
local(i, j, k)
23-
23+
2424
! Apply boundary conditions - result vanishes at boundaries
2525
laplacian_rhs%s_(i,j,k) = merge(0.0, &
2626
! X-direction second derivative
@@ -29,7 +29,7 @@
2929
merge(rhs%s_(i-1,j,k), 0.0, i > 1 .or. me > 1) + &
3030
merge(rhs%s_(i+1,j,k), 0.0, i < my_nx .or. me < num_subdomains) - &
3131
2.0 * rhs%s_(i,j,k) + &
32-
! Y-direction second derivative
32+
! Y-direction second derivative
3333
merge(rhs%s_(i,j-1,k) + rhs%s_(i,j+1,k) - 2.0 * rhs%s_(i,j,k), 0.0, &
3434
j > 1 .and. j < ny) + &
3535
! Z-direction second derivative
@@ -38,7 +38,7 @@
3838
! Boundary condition mask
3939
j == 1 .or. j == ny .or. k == 1 .or. k == nz .or. &
4040
(i == 1 .and. me == 1) .or. (i == my_nx .and. me == num_subdomains))
41-
41+
4242
end do
43-
43+
4444
end procedure laplacian

example/time-paradigm.F90

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ program time_paradigm_m
77
!! Time various alternative programming paradigms
88
use subdomain_m, only : subdomain_t
99
use assert_m
10-
use julienne_m, only : string_t, file_t, command_line_t, bin_t, csv
10+
use julienne_m, only : string_t, file_t, command_line_t, bin_t, csv
1111
use iso_fortran_env, only : int64
1212
implicit none
1313

@@ -32,23 +32,23 @@ program time_paradigm_m
3232
if (len(steps_string)/=0) read(steps_string,*) steps
3333
if (len(resolution_string)/=0) read(resolution_string,*) resolution
3434

35-
if (me==1) then
35+
if (me==1) then
3636
print *,"Number of steps to execute: ",steps
3737
print *,"Number of grid points in each coordinate direction: ",resolution
3838
print *,"Starting functional solver."
3939
end if
4040
associate(t_functional => functional_programming_time())
4141
if (me==1) print *,"Starting procedural solver."
4242
associate(t_procedural => functional_programming_time())
43-
if (me==1) then
43+
if (me==1) then
4444
print *,"Functional program time: ", t_functional
4545
print *,"Procedural program time: ", t_procedural
4646
print *,"Procedural speedup: ", (t_functional - t_procedural)/t_functional
4747
end if
4848
end associate
4949
end associate
5050
end associate
51-
51+
5252
contains
5353

5454
function functional_programming_time() result(system_time)

src/matcha/distribution_s.F90

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
implicit none
99

1010
contains
11-
11+
1212
pure function monotonically_increasing(f) result(monotonic)
1313
double precision, intent(in) :: f(:)
1414
logical monotonic
@@ -21,8 +21,8 @@ pure function monotonically_increasing(f) result(monotonic)
2121

2222
call_assert(all(sample_distribution(:,2)>=0.D0))
2323

24-
associate(nintervals => size(sample_distribution,1))
25-
distribution%vel_ = [(sample_distribution(i,1), i =1, nintervals)] ! Assign speeds to each distribution bin
24+
associate(nintervals => size(sample_distribution,1))
25+
distribution%vel_ = [(sample_distribution(i,1), i =1, nintervals)] ! Assign speeds to each distribution bin
2626
distribution%cumulative_distribution_ = [0.D0, [(sum(sample_distribution(1:i,2)), i=1, nintervals)]]
2727
end associate
2828

@@ -33,14 +33,14 @@ pure function monotonically_increasing(f) result(monotonic)
3333
module procedure cumulative_distribution
3434
call_assert(allocated(self%cumulative_distribution_))
3535
my_cumulative_distribution = self%cumulative_distribution_
36-
end procedure
37-
36+
end procedure
37+
3838
module procedure velocities
39-
39+
4040
double precision, allocatable :: sampled_speeds(:,:), dir(:,:,:)
4141
integer cell, step, k
42-
43-
call_assert(allocated(self%cumulative_distribution_))
42+
43+
call_assert(allocated(self%cumulative_distribution_))
4444
call_assert(allocated(self%vel_))
4545

4646
! Sample from the distribution
@@ -50,7 +50,7 @@ pure function monotonically_increasing(f) result(monotonic)
5050
k = findloc(speeds(cell,step) >= self%cumulative_distribution(), value=.false., dim=1)-1
5151
sampled_speeds(cell,step) = self%vel_(k)
5252
end do
53-
53+
5454
! Create unit vectors
5555
dir = directions(:,1:nsteps,:)
5656

@@ -63,7 +63,7 @@ pure function monotonically_increasing(f) result(monotonic)
6363
end associate
6464

6565
allocate(my_velocities, mold=dir)
66-
66+
6767
do concurrent(step=1:nsteps)
6868
my_velocities(:,step,1) = sampled_speeds(:,step)*dir(:,step,1)
6969
my_velocities(:,step,2) = sampled_speeds(:,step)*dir(:,step,2)

0 commit comments

Comments
 (0)