Skip to content

Commit 995e756

Browse files
authored
Merge branch 'bartgol/eamxx/avoid-views-in-output-class' (PR #7397)
Replaces manual parallel loops with usage of Field and Field utilities functions. [BFB]
2 parents 7b530d7 + 6b79441 commit 995e756

File tree

49 files changed

+1195
-1706
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1195
-1706
lines changed

components/eamxx/src/dynamics/homme/homme_grids_manager.cpp

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,6 @@ build_physics_grid (const ci_string& type, const ci_string& rebalance) {
312312

313313
void HommeGridsManager::
314314
initialize_vertical_coordinates (const nonconstgrid_ptr_type& dyn_grid) {
315-
using view_1d_host = AtmosphereInput::view_1d_host;
316-
using vos_t = std::vector<std::string>;
317315
using namespace ShortFieldTagsNames;
318316

319317
// If we put vcoords in the IC file, we open the ic file, whose name
@@ -329,11 +327,7 @@ initialize_vertical_coordinates (const nonconstgrid_ptr_type& dyn_grid) {
329327
filename = m_params.get<std::string>("ic_filename");
330328
}
331329

332-
// Read vcoords into host views
333-
ekat::ParameterList vcoord_reader_pl;
334-
vcoord_reader_pl.set("filename",filename);
335-
vcoord_reader_pl.set<vos_t>("field_names",{"hyai","hybi","hyam","hybm"});
336-
330+
// Create vcoords fields
337331
auto layout_mid = dyn_grid->get_vertical_layout(true);
338332
auto layout_int = dyn_grid->get_vertical_layout(false);
339333
constexpr auto nondim = ekat::units::Units::nondimensional();
@@ -343,39 +337,19 @@ initialize_vertical_coordinates (const nonconstgrid_ptr_type& dyn_grid) {
343337
auto hyam = dyn_grid->create_geometry_data("hyam",layout_mid,nondim);
344338
auto hybm = dyn_grid->create_geometry_data("hybm",layout_mid,nondim);
345339

346-
std::map<std::string,view_1d_host> host_views = {
347-
{ "hyai", hyai.get_view<Real*,Host>() },
348-
{ "hybi", hybi.get_view<Real*,Host>() },
349-
{ "hyam", hyam.get_view<Real*,Host>() },
350-
{ "hybm", hybm.get_view<Real*,Host>() }
351-
};
352-
std::map<std::string,FieldLayout> layouts = {
353-
{ "hyai", layout_int },
354-
{ "hybi", layout_int },
355-
{ "hyam", layout_mid },
356-
{ "hybm", layout_mid }
357-
};
358-
359-
AtmosphereInput vcoord_reader(vcoord_reader_pl,dyn_grid,host_views,layouts);
340+
std::vector<Field> fields = {hyai, hybi, hyam, hybm};
341+
AtmosphereInput vcoord_reader(filename,dyn_grid,fields);
360342
vcoord_reader.read_variables();
361343
vcoord_reader.finalize();
362344

363-
// Sync to device
364-
hyai.sync_to_dev();
365-
hybi.sync_to_dev();
366-
hyam.sync_to_dev();
367-
hybm.sync_to_dev();
368-
369-
// Pass host views data to hvcoord init function
370-
const auto ps0 = Homme::PhysicalConstants::p0;
371-
372345
// Set vcoords in f90
373346
// NOTE: homme does the check for these arrays, so no need to do any property check here
347+
const auto ps0 = Homme::PhysicalConstants::p0;
374348
prim_set_hvcoords_f90 (ps0,
375-
host_views["hyai"].data(),
376-
host_views["hybi"].data(),
377-
host_views["hyam"].data(),
378-
host_views["hybm"].data());
349+
hyai.get_internal_view_data<Real,Host>(),
350+
hybi.get_internal_view_data<Real,Host>(),
351+
hyam.get_internal_view_data<Real,Host>(),
352+
hybm.get_internal_view_data<Real,Host>());
379353
}
380354

381355
void HommeGridsManager::

components/eamxx/src/physics/mam/eamxx_mam_optics_process_interface.cpp

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,6 @@ void MAMOptics::initialize_impl(const RunType run_type) {
210210
{
211211
using namespace ShortFieldTagsNames;
212212

213-
using view_1d_host = typename KT::view_1d<Real>::HostMirror;
214-
215213
// Note: these functions do not set values for aerosol_optics_device_data_.
216214
mam4::modal_aer_opt::set_complex_views_modal_aero(
217215
aerosol_optics_device_data_);
@@ -220,23 +218,16 @@ void MAMOptics::initialize_impl(const RunType run_type) {
220218
mam4::modal_aer_opt::set_aerosol_optics_data_for_modal_aero_lw_views(
221219
aerosol_optics_device_data_);
222220

223-
mam_coupling::AerosolOpticsHostData aerosol_optics_host_data;
224-
225-
std::map<std::string, FieldLayout> layouts;
226-
std::map<std::string, view_1d_host> host_views;
227-
ekat::ParameterList rrtmg_params;
228-
229-
mam_coupling::set_parameters_table(aerosol_optics_host_data, rrtmg_params,
230-
layouts, host_views);
221+
auto aerosol_optics_fields = mam_coupling::create_optics_fields(grid_);
231222

232223
for(int imode = 0; imode < ntot_amode; imode++) {
233224
const auto key =
234225
"mam4_mode" + std::to_string(imode + 1) + "_physical_properties_file";
235226
const auto &fname = m_params.get<std::string>(key);
236227
mam_coupling::read_rrtmg_table(fname,
237228
imode, // mode No
238-
rrtmg_params, grid_, host_views, layouts,
239-
aerosol_optics_host_data,
229+
grid_,
230+
aerosol_optics_fields,
240231
aerosol_optics_device_data_);
241232
}
242233

@@ -249,14 +240,8 @@ void MAMOptics::initialize_impl(const RunType run_type) {
249240
aerosol_optics_device_data_.crefwsw);
250241
//
251242
{
252-
// make a list of host views
253-
std::map<std::string, view_1d_host> host_views_aero;
254-
// defines layouts
255-
std::map<std::string, FieldLayout> layouts_aero;
256-
ekat::ParameterList params_aero;
257243
std::string surname_aero = "aer";
258-
mam_coupling::set_refindex_names(surname_aero, params_aero,
259-
host_views_aero, layouts_aero);
244+
auto refindex_fields = mam_coupling::create_refindex_fields (surname_aero,grid_);
260245

261246
constexpr int maxd_aspectype = mam4::ndrop::maxd_aspectype;
262247
auto specrefndxsw_host = mam_coupling::complex_view_2d::HostMirror(
@@ -283,14 +268,12 @@ void MAMOptics::initialize_impl(const RunType run_type) {
283268
const auto &fname = m_params.get<std::string>(table_name);
284269
// read data
285270
// need to update table name
286-
params_aero.set("filename", fname);
287-
AtmosphereInput refindex_aerosol(params_aero, grid_, host_views_aero,
288-
layouts_aero);
271+
AtmosphereInput refindex_aerosol(fname, grid_, refindex_fields);
289272
refindex_aerosol.read_variables();
290273
refindex_aerosol.finalize();
291274
// copy data to device
292275
mam_coupling::set_refindex_aerosol(
293-
species_id, host_views_aero,
276+
species_id, refindex_fields,
294277
specrefndxsw_host, // complex refractive index for water visible
295278
specrefndxlw_host);
296279
} // done ispec

0 commit comments

Comments
 (0)