Skip to content

Commit

Permalink
Update pynucastro networks for derived rate speedup (#1529)
Browse files Browse the repository at this point in the history
Includes improvements from pynucastro/pynucastro#726.
  • Loading branch information
yut23 authored Apr 4, 2024
1 parent 45f59b1 commit d82c8c8
Show file tree
Hide file tree
Showing 19 changed files with 932 additions and 564 deletions.
24 changes: 24 additions & 0 deletions networks/CNO_extras/partition_functions.H
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ namespace part_fun {

}

struct pf_cache_t {
// Store the coefficient and derivative adjacent in memory, as they're
// always accessed at the same time.
// The entries will be default-initialized to zero, which is fine since
// log10(x) is never zero.
amrex::Array2D<amrex::Real, 1, NumSpecTotal, 1, 2, Order::C> data{};
};

}

// main interface
Expand All @@ -88,6 +96,22 @@ void get_partition_function(const int inuc, [[maybe_unused]] const tf_t& tfactor

}

AMREX_GPU_HOST_DEVICE AMREX_INLINE
void get_partition_function_cached(const int inuc, const tf_t& tfactors,
part_fun::pf_cache_t& pf_cache,
amrex::Real& pf, amrex::Real& dpf_dT) {
if (pf_cache.data(inuc, 1) != 0.0_rt) {
// present in cache
amrex::ignore_unused(tfactors);
pf = pf_cache.data(inuc, 1);
dpf_dT = pf_cache.data(inuc, 2);
} else {
get_partition_function(inuc, tfactors, pf, dpf_dT);
pf_cache.data(inuc, 1) = pf;
pf_cache.data(inuc, 2) = dpf_dT;
}
}

// spins

AMREX_GPU_HOST_DEVICE AMREX_INLINE
Expand Down
24 changes: 24 additions & 0 deletions networks/ECSN/partition_functions.H
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ namespace part_fun {

}

struct pf_cache_t {
// Store the coefficient and derivative adjacent in memory, as they're
// always accessed at the same time.
// The entries will be default-initialized to zero, which is fine since
// log10(x) is never zero.
amrex::Array2D<amrex::Real, 1, NumSpecTotal, 1, 2, Order::C> data{};
};

}

// main interface
Expand All @@ -88,6 +96,22 @@ void get_partition_function(const int inuc, [[maybe_unused]] const tf_t& tfactor

}

AMREX_GPU_HOST_DEVICE AMREX_INLINE
void get_partition_function_cached(const int inuc, const tf_t& tfactors,
part_fun::pf_cache_t& pf_cache,
amrex::Real& pf, amrex::Real& dpf_dT) {
if (pf_cache.data(inuc, 1) != 0.0_rt) {
// present in cache
amrex::ignore_unused(tfactors);
pf = pf_cache.data(inuc, 1);
dpf_dT = pf_cache.data(inuc, 2);
} else {
get_partition_function(inuc, tfactors, pf, dpf_dT);
pf_cache.data(inuc, 1) = pf;
pf_cache.data(inuc, 2) = dpf_dT;
}
}

// spins

AMREX_GPU_HOST_DEVICE AMREX_INLINE
Expand Down
24 changes: 24 additions & 0 deletions networks/He-C-Fe-group/partition_functions.H
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,14 @@ namespace part_fun {

}

struct pf_cache_t {
// Store the coefficient and derivative adjacent in memory, as they're
// always accessed at the same time.
// The entries will be default-initialized to zero, which is fine since
// log10(x) is never zero.
amrex::Array2D<amrex::Real, 1, NumSpecTotal, 1, 2, Order::C> data{};
};

}

// main interface
Expand Down Expand Up @@ -927,6 +935,22 @@ void get_partition_function(const int inuc, [[maybe_unused]] const tf_t& tfactor

}

AMREX_GPU_HOST_DEVICE AMREX_INLINE
void get_partition_function_cached(const int inuc, const tf_t& tfactors,
part_fun::pf_cache_t& pf_cache,
amrex::Real& pf, amrex::Real& dpf_dT) {
if (pf_cache.data(inuc, 1) != 0.0_rt) {
// present in cache
amrex::ignore_unused(tfactors);
pf = pf_cache.data(inuc, 1);
dpf_dT = pf_cache.data(inuc, 2);
} else {
get_partition_function(inuc, tfactors, pf, dpf_dT);
pf_cache.data(inuc, 1) = pf;
pf_cache.data(inuc, 2) = dpf_dT;
}
}

// spins

AMREX_GPU_HOST_DEVICE AMREX_INLINE
Expand Down
Loading

0 comments on commit d82c8c8

Please sign in to comment.