Skip to content

Commit 0f87cd1

Browse files
authored
Merge pull request #183 from BerkeleyLab/vibes
Document prompt engineering steps
2 parents 77a25a1 + 7862963 commit 0f87cd1

4 files changed

Lines changed: 54 additions & 1 deletion

File tree

doc/ai4dev/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Set Up
2+
-----------
3+
With your present working directory set to `doc/ai4dev`, execute
4+
```bash
5+
cd ../../scripts/
6+
./create-single-source-file-programs.sh
7+
cd ../build/single-file-programs
8+
```
9+
10+
Vibe Coding
11+
-----------
12+
1. Compile and execute `diffusion-app.F90` to ensure that the program
13+
terminates normally. For example, with the `gfortran` compiler,
14+
run `gfortran -fcoarray=single -o diffusion-app diffusion-app.F90`
15+
followed by `./diffusion-app`.
16+
2. Edit `diffusion-app.F90` to remove the lines beginning and ending with
17+
`module procedure laplacian` and `end procedure laplacian`, respectively.
18+
3. Enter the file `doc/ai4dev/vibe-coding/README.md` as your prompt and
19+
attach the edited `diffusion-app.F90` file.
20+
4. Insert the resulting function into the `subdomain_s` submodule and
21+
try compiling and executing again to check the result.
22+
23+
Idiomtic Vibe Coding
24+
--------------------
25+
1. Compile and execute `test-suite.F90` to and check that the output
26+
reports that all tests pass. For example, with the `gfortran` compiler,
27+
run `gfortran -fcoarray=single -o test-suite test-suite.F90` followed
28+
by `./test-suite`.
29+
2. Edit `test-suite.F90` to remove the lines beginning and ending with
30+
`module procedure laplacian` and `end procedure laplacian`, respectively.
31+
3. Enter the file `doc/ai4dev/idiomaic-vibe-coding/README.md` as your prompt
32+
and attach the edited `tgest-sutie.F90` file.
33+
4. Insert the resulting function into the `subdomain_s` submodule and
34+
try compiling and executing again to check the result.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
You are a research software engineer who is familiar with Fortran 2018, experienced in parallel and object-oriented programming, and building a software library named "Matcha". All source code that you need is in the attached file. The main program runs a test suite that uses a module subdomain_test_m to report on several correctness checks on the subdomain_m module and subdomain_s submodule. The subdomain_m module also contains a module function interface body named "laplacian". Everything in the source code is complete except that there is no defintion for the "laplacian" function. Provide a defintion for the laplacian function definition using the following steps:
3+
4+
1. Write an empty module procecure named "laplacian" into which you will insert executable statements and comments that explain what your code is doing.
5+
2. Allocate the laplacian_rhs% component to a shape [my_nx, ny, nz]
6+
3. Use one or more "do concurrent" constructs, each with "default(none)" and any othe required locality specifiers, to compute a 2nd-order central difference approximation to the Laplacian of the "s_" array component of the "laplacian" function's "rhs" dummy argument.
7+
4. Store the Laplacian approximation in the s_ component of the laplacian_rhs function result.
8+
5. When an expresssion requires the value rhs%s_(1,:,:) and me==1, instead use halo_x(west,:,:) for the required value.
9+
5. When an expresssion requires the value rhs%s_(ubound(rhs%s_,1),:,:) and me==num_subdomains, instead use halo_x(east,:,:) for the required value.
10+
6. Set result component laplacian_rhs%s_ to zero for the subscript values (:, 1,:), (:,ny,:), (:,:, 1), (:,:,nz).
11+
7. Also set laplacian_rhs%s_ to zero for the subscript values (1,:,:) if me==1
12+
8. Also set laplacian_rhs%s_ to zero for the subscript values (my_nx,:,:) if me==num_subdomains.
13+
14+
When "laplacian" function is incorporated into the subdomain_m module, the attached file must compile and report that all tests passing when executed.

scripts/create-single-source-file-programs.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
export assert_dir="../build/dependencies/assert"
88
export julienne_dir="../build/dependencies/julienne"
99
export matcha_dir=".."
10+
export test_dir="../test"
1011
export destination_dir="../build/single-file-programs"
1112

1213
echo ""
@@ -80,3 +81,7 @@ cp "$julienne_dir/include/julienne-assert-macros.h" "$destination_dir"
8081

8182
echo "Concatenating Assert, Julienne, and Matcha src and app into $destination_dir/diffusion-app.F90"
8283
cat "$destination_dir"/assert.F90 "$destination_dir"/julienne.F90 "$destination_dir"/matcha.F90 "$matcha_dir/app/diffusion.f90" > $destination_dir/diffusion-app.F90
84+
85+
echo "Concatenating Assert, Julienne, and Matcha src and test into $destination_dir/test-suite.F90"
86+
test_modules=$(find "$test_dir" -name '*_m.?90')
87+
cat "$destination_dir"/assert.F90 "$destination_dir"/julienne.F90 "$destination_dir"/matcha.F90 $test_modules "$test_dir"/main.F90 > $destination_dir/test-suite.F90

src/matcha/subdomain_s.F90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@
142142

143143
if (me==1) laplacian_rhs%s_(1,:,:) = 0. ! low-x boundary
144144
if (me==num_subdomains) laplacian_rhs%s_(my_nx,:,:) = 0. ! high-x boundary
145-
end procedure
145+
end procedure laplacian
146146

147147
module procedure multiply
148148
call_assert(allocated(rhs%s_))

0 commit comments

Comments
 (0)