1+ # Usage: code-scribe update ERF_NOAHMP.cpp \
2+ # -p prompts/noahmpio_update.toml -m <openai|argo|..>
3+
14[[chat .user ]]
2- content = """
5+ content = '''
36You are a code-update assistant for extending the ERF-NoahMP C++ driver interface.
47
58Only edit the appended files. Focus on the coupling logic inside
@@ -12,23 +15,23 @@ patterns used for existing variables such as `U_PHY`, `V_PHY`, `T_PHY`, `QV_CURR
1215
13161. Context
1417
15- - The ERF-NoahMP coupling exchanges field data via `noahmpio_vect`, a per-tile
16- vector of `NoahmpIO_type` objects. Each object corresponds to a domain tile
17- in `cons_in`.
18+ - The ERF-NoahMP coupling exchanges field data via `noahmpio_vect`, a per-tile
19+ vector of `NoahmpIO_type` objects. Each object corresponds to a domain tile
20+ in `cons_in`.
1821
19- - Each time step, `Advance_With_State()` performs the following sequence:
20- (1) Extract 3D Array4<Real> views from ERF state variables.
21- (2) Allocate temporary host-accessible FArrayBox buffers (The_Pinned_Arena()).
22- (3) Launch ParallelFor GPU kernels to copy ERF data into pinned buffers.
23- (4) Synchronize GPU streams, then perform CPU loops (LoopOnCpu) to copy
24- those buffers into corresponding NoahMP fields (noahmpio->VAR(i,k,j)).
25- (5) Call the NoahMP driver (DriverMain()).
26- (6) Copy computed fluxes and surface variables back from NoahMP to ERF arrays.
22+ - Each time step, `Advance_With_State()` performs the following sequence:
23+ (1) Extract 3D Array4<Real> views from ERF state variables.
24+ (2) Allocate temporary host-accessible FArrayBox buffers (The_Pinned_Arena()).
25+ (3) Launch ParallelFor GPU kernels to copy ERF data into pinned buffers.
26+ (4) Synchronize GPU streams, then perform CPU loops (LoopOnCpu) to copy
27+ those buffers into corresponding NoahMP fields (noahmpio->VAR(i,k,j)).
28+ (5) Call the NoahMP driver (DriverMain()).
29+ (6) Copy computed fluxes and surface variables back from NoahMP to ERF arrays.
2730
28- - Newly added variables follow the same pattern:
29- - GPU->Host copy -> LoopOnCpu -> assign to noahmpio->NEWVAR
30- - DriverMain() executes the Fortran driver
31- - Host->GPU copy -> ParallelFor -> assign to ERF Array4<Real> fields
31+ - Newly added variables follow the same pattern:
32+ - GPU->Host copy -> LoopOnCpu -> assign to noahmpio->NEWVAR
33+ - DriverMain() executes the Fortran driver
34+ - Host->GPU copy -> ParallelFor -> assign to ERF Array4<Real> fields
3235
33362. Task Details
3437
@@ -37,53 +40,53 @@ variables RAINLSM and any other surface fields needed for the ERF side.
3740
3841Changes Required
3942
40- - Host buffers
43+ - Host buffers
4144Add new temporary FArrayBox allocations for each new variable:
42- FArrayBox tmp_rainlsm(bx, 1, The_Pinned_Arena());
45+ FArrayBox tmp_rainlsm(bx, 1, The_Pinned_Arena());
4346
4447and retrieve their array handles:
45- auto const& tmp_rainlsm_arr = tmp_rainlsm.array();
48+ auto const& tmp_rainlsm_arr = tmp_rainlsm.array();
4649
47- - Device->Host copy (ParallelFor)
50+ - Device->Host copy (ParallelFor)
4851If the new field originates on the ERF side (e.g., forcing input), copy it from
4952ERF arrays into the pinned buffer in the existing ParallelFor block.
5053
5154If it is computed by NoahMP, skip this step and handle it in the post-DriverMain()
5255copy-back section.
5356
54- - Host->NoahMP copy (LoopOnCpu)
57+ - Host->NoahMP copy (LoopOnCpu)
5558After GPU synchronization (Gpu::streamSynchronize()), extend the LoopOnCpu
5659block that writes to noahmpio fields:
57- noahmpio->RAINLSM(i,j) = tmp_rainlsm_arr(i,j,0);
60+ noahmpio->RAINLSM(i,j) = tmp_rainlsm_arr(i,j,0);
5861
59- - Post-DriverMain copy (LoopOnCpu)
62+ - Post-DriverMain copy (LoopOnCpu)
6063Add the reverse direction: copying noahmpio->RAINLSM values back into the
6164temporary FArrayBox before GPU upload:
62- h_rainlsm_arr(i,j,0) = noahmpio->RAINLSM(i,j);
65+ h_rainlsm_arr(i,j,0) = noahmpio->RAINLSM(i,j);
6366
64- - Host->Device copy-back (ParallelFor)
67+ - Host->Device copy-back (ParallelFor)
6568Finally, assign results into the correct ERF field:
66- RAINLSM(i,j,0) = tmp_rainlsm_arr(i,j,0);
69+ RAINLSM(i,j,0) = tmp_rainlsm_arr(i,j,0);
6770
6871Follow the same block and comment style used for variables like TSK, EMISS,
6972and HFX.
7073
71743. Validation
7275
73- - Verify that array ranks match (2D for surface variables, 3D for atmospheric variables).
74- - Ensure the order of CPU/GPU synchronization and host copies is preserved.
75- - Confirm that noahmpio_vect indexing (idb) and bounds (bx.smallEnd, domain.smallEnd)
76- remain untouched.
77- - Maintain one-to-one consistency between ERF arrays and NoahMP I/O variables.
76+ - Verify that array ranks match (2D for surface variables, 3D for atmospheric variables).
77+ - Ensure the order of CPU/GPU synchronization and host copies is preserved.
78+ - Confirm that noahmpio_vect indexing (idb) and bounds (bx.smallEnd, domain.smallEnd)
79+ remain untouched.
80+ - Maintain one-to-one consistency between ERF arrays and NoahMP I/O variables.
7881
79824. Actual Task
8083
8184Modify and link the following variable declared in NoahmpIOVarType.F90 and
8285allocated in NoahmpIOVarInitMod.F90:
8386
84- - RAINLSM, 2D array of type real(kind=kind_noahmp), with bounds (XSTART:XEND, YSTART:YEND)
87+ - RAINLSM, 2D array of type real(kind=kind_noahmp), with bounds (XSTART:XEND, YSTART:YEND)
8588
8689Ensure the field is fully integrated into the ERF-NoahMP coupling sequence
8790inside Advance_With_State() following the memory flow used for TSK.
8891
89- """
92+ '''
0 commit comments