Skip to content

Commit

Permalink
Merge branch 'jgfouca/p3_cxx_init' into master (PR #6845)
Browse files Browse the repository at this point in the history
This removes the last f90 from P3.

Change list:
1) Move table read/write implementation to CXX in p3_init_impl.hpp
2) p3_init now returns a P3LookupTables object with all the views inside containing the tables.
3) Rename init_kokkos_tables to get_global_tables
4) Rename init_kokkos_ice_lookup_tables to get_global_ice_lookup_tables
5) Remove all f90 bridge code
6) Move p3_tables_setup to tests dir, cleans up top p3 directory
7) Fix p3_tables_setup implementation; it got broken in recent PRs but we didn't notice because it didn't get built by default
8) Remove P3GlobalForFortran test struct, just call p3_init!
9) Remove P3InitAP3Data test struct

Debatable change:

I really wanted to have P3LookupTables lookup_tables
be static in p3_init so they would not have to be re-created on every
p3_init call. Unfortunately, Kokkos does not allow static views to be
active on program shutdown, since this occurs after Kokkos::finalize,
so we would need add a p3_finalize method and ensure it was called at
the end of p3. This seems burdensome and error prone, so I just
decided to re-read all the tables every time p3_init is called.

There are some round-off level diffs in P3, so:

[non-BFB]

* jgfouca/p3_cxx_init:
  GPU fixes: need to use host views for init stuff
  Update PAM submodule
  Change new table names to not conflict with older tables
  Github feedback
  Convert p3_init from f90 to CXX
  • Loading branch information
jgfouca committed Jan 8, 2025
2 parents fbc8289 + b2666f4 commit 03ab204
Show file tree
Hide file tree
Showing 25 changed files with 397 additions and 530 deletions.
8 changes: 4 additions & 4 deletions components/eamxx/cime_config/namelist_defaults_scream.xml
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,10 @@ be lost if SCREAM_HACK_XML is not enabled.
<max_total_ni type="real" doc="maximum total ice concentration (sum of all categories)" constraints="gt 0">740.0e3</max_total_ni>
<tables type="array(file)">
${DIN_LOC_ROOT}/atm/scream/tables/p3_lookup_table_1.dat-v4.1.1,
${DIN_LOC_ROOT}/atm/scream/tables/mu_r_table_vals.dat8,
${DIN_LOC_ROOT}/atm/scream/tables/revap_table_vals.dat8,
${DIN_LOC_ROOT}/atm/scream/tables/vn_table_vals.dat8,
${DIN_LOC_ROOT}/atm/scream/tables/vm_table_vals.dat8
${DIN_LOC_ROOT}/atm/scream/tables/mu_r_table_vals_v2.dat8,
${DIN_LOC_ROOT}/atm/scream/tables/revap_table_vals_v2.dat8,
${DIN_LOC_ROOT}/atm/scream/tables/vn_table_vals_v2.dat8,
${DIN_LOC_ROOT}/atm/scream/tables/vm_table_vals_v2.dat8
</tables>
<autoconversion_prefactor type="real" doc="Autoconversion linear prefactor">1350.0</autoconversion_prefactor>
<autoconversion_qc_exponent type="real" doc="Autoconversion qc exponent">2.47</autoconversion_qc_exponent>
Expand Down
18 changes: 4 additions & 14 deletions components/eamxx/src/physics/p3/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
set(P3_SRCS
p3_iso_c.f90
${SCREAM_BASE_DIR}/../eam/src/physics/p3/scream/micro_p3.F90
eamxx_p3_process_interface.cpp
eamxx_p3_run.cpp
)
Expand Down Expand Up @@ -82,11 +80,7 @@ endif()
target_compile_definitions(p3 PUBLIC EAMXX_HAS_P3)

foreach (P3_LIB IN LISTS P3_LIBS)
set_target_properties(${P3_LIB} PROPERTIES
Fortran_MODULE_DIRECTORY ${P3_LIB}/modules
)
target_include_directories(${P3_LIB} PUBLIC
${CMAKE_CURRENT_BINARY_DIR}/${P3_LIB}/modules
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/impl
${SCREAM_BASE_DIR}/../eam/src/physics/cam
Expand All @@ -102,21 +96,17 @@ else()
endif()
set (P3_TABLES
scream/tables/p3_lookup_table_1.dat-v4.1.1
scream/tables/mu_r_table_vals.dat${PRECISION_SUFFIX}
scream/tables/revap_table_vals.dat${PRECISION_SUFFIX}
scream/tables/vm_table_vals.dat${PRECISION_SUFFIX}
scream/tables/vn_table_vals.dat${PRECISION_SUFFIX}
scream/tables/mu_r_table_vals_v2.dat${PRECISION_SUFFIX}
scream/tables/revap_table_vals_v2.dat${PRECISION_SUFFIX}
scream/tables/vm_table_vals_v2.dat${PRECISION_SUFFIX}
scream/tables/vn_table_vals_v2.dat${PRECISION_SUFFIX}
)

include (ScreamUtils)
foreach (file IN ITEMS ${P3_TABLES})
GetInputFile(${file})
endforeach()

# This executable can be used to re-generate tables in ${SCREAM_DATA_DIR}
add_executable(p3_tables_setup EXCLUDE_FROM_ALL p3_tables_setup.cpp)
target_link_libraries(p3_tables_setup p3)

if (NOT SCREAM_LIB_ONLY)
add_subdirectory(tests)
endif()
Expand Down
10 changes: 2 additions & 8 deletions components/eamxx/src/physics/p3/eamxx_p3_process_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ void P3Microphysics::initialize_impl (const RunType /* run_type */)
add_postcondition_check<FieldWithinIntervalCheck>(get_field_out("eff_radius_qr"),m_grid,0.0,5.0e3,false);

// Initialize p3
P3F::p3_init(/* write_tables = */ false,
this->get_comm().am_i_root());
lookup_tables = P3F::p3_init(/* write_tables = */ false,
this->get_comm().am_i_root());

// Initialize all of the structures that are passed to p3_main in run_impl.
// Note: Some variables in the structures are not stored in the field manager. For these
Expand Down Expand Up @@ -411,12 +411,6 @@ void P3Microphysics::initialize_impl (const RunType /* run_type */)
p3_postproc.set_mass_and_energy_fluxes(vapor_flux, water_flux, ice_flux, heat_flux);
}

// Load tables
P3F::init_kokkos_ice_lookup_tables(lookup_tables.ice_table_vals, lookup_tables.collect_table_vals);
P3F::init_kokkos_tables(lookup_tables.vn_table_vals, lookup_tables.vm_table_vals,
lookup_tables.revap_table_vals, lookup_tables.mu_r_table_vals,
lookup_tables.dnu_table_vals);

// Setup WSM for internal local variables
const auto policy = ekat::ExeSpaceUtils<KT::ExeSpace>::get_default_team_policy(m_num_cols, nk_pack);
workspace_mgr.setup(m_buffer.wsm_data, nk_pack_p1, 52, policy);
Expand Down
Loading

0 comments on commit 03ab204

Please sign in to comment.