Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pynucastro networks for derived rate speedup #1529

Merged
merged 2 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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