E3SM-Project / E3SM-Project/E3SM
EAMxx: potential bug report for zero-value files when `write_tables = true` in `p3_init_impl.hpp`
- Dominant language
- Fortran
- Stars
- 440
- Forks
- 481
- Avg merge
- 4d 7h
- Merged PRs (30d)
- 33
Description
Hi team,
I believe I've encountered a potential issue when using the `P3F::p3_init` method with the `write_tables = true`.
When initializing with:
```
P3F::p3_init(/* write_tables = */ true, is_root);
```
the resulting output files (all .dat for p3 except `p3_lookup_table_1.dat-v4.1.1`) appear to contain all zero values.
---
### My Analysis and Suggested Fix
It seems the issue may stem from where the data copy from device to host occurs within the `void io_impl(...)` method. For file writing to accurately capture the table data computed on the device, a deep copy to the host memory must happen after the tables are populated on the device but before the `action` function is called.
It generates correct output files after I modifies the code like this in `p3_init_impl.hpp`
```
template
void io_impl(const bool masterproc, const char* dir, MuRT& mu_r_table_vals, VNT& vn_table_vals, VMT& vm_table_vals, RevapT& revap_table_vals)
...
if constexpr (!IsRead) {
Kokkos::deep_copy(mu_r_table_vals_h, mu_r_table_vals);
Kokkos::deep_copy(revap_table_vals_h, revap_table_vals);
Kokkos::deep_copy(vn_table_vals_h, vn_table_vals);
Kokkos::deep_copy(vm_table_vals_h, vm_table_vals);
}
// Read files
action(mu_r_file, mu_r_table_vals_h.data(), mu_r_table_vals.size());
action(revap_file, revap_table_vals_h.data(), revap_table_vals.size());
action(vn_file, vn_table_vals_h.data(), vn_table_vals.size());
action(vm_file, vm_table_vals_h.data(), vm_table_vals.size());
...
```
I encountered this while integrating the eamxx P3 module component to my model and not using the whole project/CIME framework, which might explain why the initialization sequence led to this observation. I hope this suggestion might help and thanks for your time and attention to this matter.
Contributor guide
Research direction
Start in p3_init_impl.hpp at p3_init and its io_impl method, then inspect when the P3 tables are populated and when the file-writing action runs. Compare the generated .dat files with and without write_tables = true; done means the output files contain the computed table values rather than zeros.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- hpc
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100