Skip to content
Merged
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
30 changes: 23 additions & 7 deletions src/examples/TChem_AerosolChemistry_RHSs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ int main(int argc, char *argv[]) {
bool verbose(true);
bool use_cloned_samples(false);
int number_of_particles(-1);
bool do_jac(true);
bool do_rhs(true);

/// parse command line arguments
TChem::CommandLineParser opts("This example computes the net production rates with a given state vector");
Expand All @@ -57,6 +59,9 @@ int main(int argc, char *argv[]) {
opts.set_option<int>("batch_size", " number of batches or samples, e.g. 10 ", &nBatch);
opts.set_option<bool>(
"use_cloned_samples", "If true, one state vector will be cloned.", &use_cloned_samples);
opts.set_option<bool>("do_jac", "Evaluate Jacobian matrix", &do_jac);
opts.set_option<bool>("do_rhs", "Evaluate RHS", &do_rhs);


const bool r_parse = opts.parse(argc, argv);
if (r_parse)
Expand Down Expand Up @@ -171,9 +176,8 @@ int main(int argc, char *argv[]) {
Kokkos::deep_copy(num_concentration, num_concentration_host);
}
// output
real_type_2d_view_type rhs("rhs", nBatch, number_of_equations);
real_type_2d_view_type fac("fac", nBatch, number_of_equations);
real_type_3d_view_type jacobian("jacobian", nBatch, number_of_equations, number_of_equations);
real_type_2d_view_type rhs("rhs", nBatch, number_of_equations);

using policy_type = typename TChem::UseThisTeamPolicy<TChem::exec_space>::type;

Expand All @@ -196,7 +200,9 @@ int main(int argc, char *argv[]) {

Kokkos::Timer timer;
FILE *fout_times = fopen(outputFileTimes.c_str(), "w");
{

if (do_rhs){
printf("..evaluating RHS\n");
fprintf(fout_times, "{\n");
fprintf(fout_times, " \"Aerosol RHSs\": \n {\n");
const ordinal_type level = 1;
Expand Down Expand Up @@ -273,10 +279,19 @@ int main(int argc, char *argv[]) {
fprintf(fout_times, "%s: %20.14e, \n","\"wall_time\"", t_device_batch);
fprintf(fout_times, "%s: %20.14e, \n","\"wall_time_per_sample\"", t_device_batch / real_type(nBatch));
fprintf(fout_times, "%s: %d \n","\"number_of_samples\"", nBatch);
fprintf(fout_times, "}, \n ");// reaction rates

if (do_jac){
fprintf(fout_times, "}, \n ");// reaction rates
}
else {
fprintf(fout_times, "} \n ");// reaction rates
}

}

{
if (do_jac){
printf("..evaluating Jacobian\n");
real_type_3d_view_type jacobian("jacobian", nBatch, number_of_equations, number_of_equations);
const ordinal_type level = 1;
fprintf(fout_times, " \"Aerosol Numerical Jacobian\": \n {\n");
const std::string profile_name = "TChem::AerosolChemistry::NumericalJacobian_evaluation";
Expand Down Expand Up @@ -355,10 +370,11 @@ int main(int argc, char *argv[]) {
fprintf(fout_times, "%s: %d \n","\"number_of_samples\"", nBatch);
fprintf(fout_times, "} \n ");// reaction rates
}
if (verbose) {

if (verbose & do_rhs) {

if (use_cloned_samples) {

if (use_cloned_samples) {
auto rhs_at_0 = Kokkos::subview(rhs, 0, Kokkos::ALL());
auto rhs_host_at_0 = Kokkos::create_mirror_view(rhs_at_0);
Kokkos::deep_copy(rhs_host_at_0, rhs_at_0);
Expand Down