Skip to content

Commit

Permalink
Progress. Can not remove fortran
Browse files Browse the repository at this point in the history
  • Loading branch information
jgfouca committed Nov 4, 2024
1 parent a2b0af0 commit 5e46e33
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void run_bfb()
d.randomize(engine, { {d.qc_incld, {C::QSMALL/2, C::QSMALL*2}} });
}

// Create copies of data for use by cxx. Needs to happen before fortran calls so that
// Create copies of data for use by cxx. Needs to happen before reads so that
// inout data is in original state
CloudSedData csds_cxx[num_runs] = {
CloudSedData(csds_baseline[0]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ struct UnitWrap::UnitTest<D>::TestEvapSublPrecip : public UnitWrap::UnitTest<D>:
constexpr Scalar latvap = C::LatVap;
constexpr Scalar latice = C::LatIce;

//fortran generated data is input to the following
//baseline generated data is input to the following
//This subroutine has 20 args, only 18 are supplied here for invoking it as last 2 are intent-outs
//note that dt is the same val for each row - this is needed since dt is a scalar and all rows are executed simultaneously on CPU in C++.
//row1: above freezing, should trigger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ struct UnitWrap::UnitTest<D>::TestIceDepositionSublimation : public UnitWrap::Un
// d.randomize();
//}

// Create copies of data for use by cxx and sync it to device. Needs to happen before fortran calls so that
// Create copies of data for use by cxx and sync it to device. Needs to happen before reads so that
// inout data is in original state
view_1d<IceDepositionSublimationData> cxx_device("cxx_device", max_pack_size);
const auto cxx_host = Kokkos::create_mirror_view(cxx_device);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void run_bfb_calc_bulk_rhime()
{5.164017E-10, 0.000000E+00, 0.000000E+00},
};

// Sync to device, needs to happen before fortran calls so that
// Sync to device, needs to happen before reads so that
// inout data is in original state
view_1d<CalcBulkRhoRimeData> cbrr_device("cbrr", max_pack_size);
const auto cbrr_host = Kokkos::create_mirror_view(cbrr_device);
Expand Down Expand Up @@ -150,7 +150,7 @@ void run_bfb_ice_sed()
d.randomize(engine, { {d.qi_incld, {C::QSMALL/2, C::QSMALL*2}} });
}

// Create copies of data for use by cxx. Needs to happen before fortran calls so that
// Create copies of data for use by cxx. Needs to happen before reads so that
// inout data is in original state
IceSedData isds_cxx[num_runs] = {
IceSedData(isds_baseline[0]),
Expand Down Expand Up @@ -233,7 +233,7 @@ void run_bfb_homogeneous_freezing()
}
}

// Create copies of data for use by cxx. Needs to happen before fortran calls so that
// Create copies of data for use by cxx. Needs to happen before reads so that
// inout data is in original state
HomogeneousFreezingData hfds_cxx[num_runs] = {
HomogeneousFreezingData(hfds_baseline[0]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct UnitWrap::UnitTest<D>::TestIceSupersatConservation : public UnitWrap::Uni
d.latent_heat_sublim = latvap+latice;
}

// Create copies of data for use by cxx and sync it to device. Needs to happen before fortran calls so that
// Create copies of data for use by cxx and sync it to device. Needs to happen before reads so that
// inout data is in original state
view_1d<IceSupersatConservationData> cxx_device("cxx_device", max_pack_size);
const auto cxx_host = Kokkos::create_mirror_view(cxx_device);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct UnitWrap::UnitTest<D>::TestNcConservation : public UnitWrap::UnitTest<D>:
d.dt = baseline_data[0].dt; // Hold this fixed, this is not packed data
}

// Create copies of data for use by cxx and sync it to device. Needs to happen before fortran calls so that
// Create copies of data for use by cxx and sync it to device. Needs to happen before reads so that
// inout data is in original state
view_1d<NcConservationData> cxx_device("cxx_device", max_pack_size);
const auto cxx_host = Kokkos::create_mirror_view(cxx_device);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct UnitWrap::UnitTest<D>::TestNiConservation : public UnitWrap::UnitTest<D>:
d.dt = baseline_data[0].dt; // hold dt fixed, it is not packed data
}

// Create copies of data for use by cxx and sync it to device. Needs to happen before fortran calls so that
// Create copies of data for use by cxx and sync it to device. Needs to happen before reads so that
// inout data is in original state
view_1d<NiConservationData> cxx_device("cxx_device", max_pack_size);
const auto cxx_host = Kokkos::create_mirror_view(cxx_device);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct UnitWrap::UnitTest<D>::TestNrConservation : public UnitWrap::UnitTest<D>:
d.nmltratio = baseline_data[0].nmltratio; // hold nmltratio fixed, it is not packed data
}

// Create copies of data for use by cxx and sync it to device. Needs to happen before fortran calls so that
// Create copies of data for use by cxx and sync it to device. Needs to happen before reads so that
// inout data is in original state
view_1d<NrConservationData> cxx_device("cxx_device", max_pack_size);
const auto cxx_host = Kokkos::create_mirror_view(cxx_device);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ struct UnitWrap::UnitTest<D>::TestPreventLiqSupersaturation : public UnitWrap::U
}

// Create copies of data for use by cxx and sync it to device. Needs to happen before
// fortran calls so that inout data is in original state
// reads so that inout data is in original state
view_1d<PreventLiqSupersaturationData> cxx_device("cxx_device", max_pack_size);
const auto cxx_host = Kokkos::create_mirror_view(cxx_device);
std::copy(&baseline_data[0], &baseline_data[0] + max_pack_size, cxx_host.data());
Expand Down
40 changes: 20 additions & 20 deletions components/eamxx/src/physics/p3/tests/p3_rain_sed_unit_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,35 +147,35 @@ void run_bfb_rain_sed()
constexpr Scalar dt = 1.800E+03;
#endif

RainSedData rsds_fortran[] = {
RainSedData rsds_baseline[] = {
// kts, kte, ktop, kbot, kdir, dt, inv_dt, precip_liq_surf
RainSedData(1, 72, 27, 72, -1, dt, 1/dt, 0.0),
RainSedData(1, 72, 72, 27, 1, dt, 1/dt, 1.0),
RainSedData(1, 72, 27, 27, -1, dt, 1/dt, 0.0),
RainSedData(1, 72, 27, 27, 1, dt, 1/dt, 2.0),
};

static constexpr Int num_runs = sizeof(rsds_fortran) / sizeof(RainSedData);
static constexpr Int num_runs = sizeof(rsds_baseline) / sizeof(RainSedData);

// Set up random input data
for (auto& d : rsds_fortran) {
for (auto& d : rsds_baseline) {
d.randomize(engine, { {d.qr_incld, {C::QSMALL/2, C::QSMALL*2}} });
}

// Create copies of data for use by cxx. Needs to happen before reads so that
// inout data is in original state
RainSedData rsds_cxx[num_runs] = {
RainSedData(rsds_fortran[0]),
RainSedData(rsds_fortran[1]),
RainSedData(rsds_fortran[2]),
RainSedData(rsds_fortran[3]),
RainSedData(rsds_baseline[0]),
RainSedData(rsds_baseline[1]),
RainSedData(rsds_baseline[2]),
RainSedData(rsds_baseline[3]),
};

// Read baseline data
std::string baseline_name = this->m_baseline_path + "/rain_sed.dat";
if (this->m_baseline_action == COMPARE) {
auto fid = ekat::FILEPtr(fopen(baseline_name.c_str(), "r"));
for (auto& d : rsds_fortran) {
for (auto& d : rsds_baseline) {
d.read(fid);
}
}
Expand All @@ -198,20 +198,20 @@ void run_bfb_rain_sed()
if (SCREAM_BFB_TESTING && this->m_baseline_action == COMPARE) {
for (Int i = 0; i < num_runs; ++i) {
// Due to pack issues, we must restrict checks to the active k space
Int start = std::min(rsds_fortran[i].kbot, rsds_fortran[i].ktop) - 1; // 0-based indx
Int end = std::max(rsds_fortran[i].kbot, rsds_fortran[i].ktop); // 0-based indx
Int start = std::min(rsds_baseline[i].kbot, rsds_baseline[i].ktop) - 1; // 0-based indx
Int end = std::max(rsds_baseline[i].kbot, rsds_baseline[i].ktop); // 0-based indx
for (Int k = start; k < end; ++k) {
REQUIRE(rsds_fortran[i].qr[k] == rsds_cxx[i].qr[k]);
REQUIRE(rsds_fortran[i].nr[k] == rsds_cxx[i].nr[k]);
REQUIRE(rsds_fortran[i].nr_incld[k] == rsds_cxx[i].nr_incld[k]);
REQUIRE(rsds_fortran[i].mu_r[k] == rsds_cxx[i].mu_r[k]);
REQUIRE(rsds_fortran[i].lamr[k] == rsds_cxx[i].lamr[k]);
REQUIRE(rsds_fortran[i].precip_liq_flux[k] == rsds_cxx[i].precip_liq_flux[k]);
REQUIRE(rsds_fortran[i].qr_tend[k] == rsds_cxx[i].qr_tend[k]);
REQUIRE(rsds_fortran[i].nr_tend[k] == rsds_cxx[i].nr_tend[k]);
REQUIRE(rsds_baseline[i].qr[k] == rsds_cxx[i].qr[k]);
REQUIRE(rsds_baseline[i].nr[k] == rsds_cxx[i].nr[k]);
REQUIRE(rsds_baseline[i].nr_incld[k] == rsds_cxx[i].nr_incld[k]);
REQUIRE(rsds_baseline[i].mu_r[k] == rsds_cxx[i].mu_r[k]);
REQUIRE(rsds_baseline[i].lamr[k] == rsds_cxx[i].lamr[k]);
REQUIRE(rsds_baseline[i].precip_liq_flux[k] == rsds_cxx[i].precip_liq_flux[k]);
REQUIRE(rsds_baseline[i].qr_tend[k] == rsds_cxx[i].qr_tend[k]);
REQUIRE(rsds_baseline[i].nr_tend[k] == rsds_cxx[i].nr_tend[k]);
}
REQUIRE(rsds_fortran[i].precip_liq_flux[end] == rsds_cxx[i].precip_liq_flux[end]);
REQUIRE(rsds_fortran[i].precip_liq_surf == rsds_cxx[i].precip_liq_surf);
REQUIRE(rsds_baseline[i].precip_liq_flux[end] == rsds_cxx[i].precip_liq_flux[end]);
REQUIRE(rsds_baseline[i].precip_liq_surf == rsds_cxx[i].precip_liq_surf);
}
}
else if (this->m_baseline_action == GENERATE) {
Expand Down
6 changes: 3 additions & 3 deletions components/eamxx/src/physics/p3/tests/p3_unit_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ struct UnitWrap::UnitTest<D>::TestP3UpdatePrognosticIce : public UnitWrap::UnitT
constexpr Scalar latvap = C::LatVap;
constexpr Scalar latice = C::LatIce;

//fortran generated data is input to the following
//baseline generated data is input to the following
P3UpdatePrognosticIceData pupidc[max_pack_size] = {

{4.9078E-19, 1.5312E-09, 4.4387E-09, 3.7961E+06, 1.7737E-04, 0.0000E+00, 3.8085E-08, 5.1281E+04, 1.9251E-15,
Expand Down Expand Up @@ -748,7 +748,7 @@ struct UnitWrap::UnitTest<D>::TestGetTimeSpacePhysVariables : public UnitWrap::U
constexpr Scalar latvap = C::LatVap;
constexpr Scalar latice = C::LatIce;

//fortran generated data is input to the following
//baseline generated data is input to the following
GetTimeSpacePhysVarsData gtspvd[max_pack_size] = {
// T_atm, pres, rho, latent_heat_vapor, latent_heat_sublim, qv_sat_l, qv_sat_i
{2.9792E+02, 9.8711E+04, 1.1532E+00, latvap, latvap+latice, 2.0321E-02, 2.0321E-02},
Expand Down Expand Up @@ -870,7 +870,7 @@ struct UnitWrap::UnitTest<D>::TestP3UpdatePrognosticLiq : public UnitWrap::UnitT
void update_prognostic_liquid_unit_bfb_tests() {
constexpr Scalar latvap = C::LatVap;

//fortran generated data is input to the following
//baseline generated data is input to the following
P3UpdatePrognosticLiqData pupldc[max_pack_size] = {

{1.0631E-12, 1.0631E+00, 1.5833E-12, 1.5833E+00, 2.4190E-02, 0.0000E+00, 0.0000E+00, 0.0000E+00, 4.2517E+00,
Expand Down

0 comments on commit 5e46e33

Please sign in to comment.