Skip to content

Commit

Permalink
debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
qinatan committed Jun 28, 2023
1 parent db1d580 commit 903a608
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 19 deletions.
8 changes: 5 additions & 3 deletions include/micm/process/process_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,11 @@ namespace micm
cell_forcing[react_id[i_react]] -= rate;


// for (std::size_t i_prod = 0; i_prod < number_of_products_[i_rxn]; ++i_prod)
// cell_forcing[prod_id[i_prod]] += yield[i_prod] * rate;

for (std::size_t i_prod = 0; i_prod < number_of_products_[i_rxn]; ++i_prod){
std::cout << "this is cell_forcing data: "<< cell_forcing[prod_id[i_prod]]<<std::endl;
std:: cout << "this is yield data: "<< yield[i_prod] <<std::endl;
cell_forcing[prod_id[i_prod]] += yield[i_prod] * rate;
}
react_id += number_of_reactants_[i_rxn];
prod_id += number_of_products_[i_rxn];
yield += number_of_products_[i_rxn];
Expand Down
38 changes: 31 additions & 7 deletions src/process/process_set.cu
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ namespace micm {
double* rate_array_post,
double* state_variable,
double* cell_forcing,

double* cell_forcing_last,
size_t* yield,

double* rate_constants,
double* state_variables,
double* forcing,
Expand Down Expand Up @@ -53,17 +55,19 @@ namespace micm {
for (int i_reactant = 0; i_reactant < reactant_num; i_reactant++){
int reactant_ids_index = initial_reactant_ids_index + i_reactant;
int state_forcing_col_index = reactant_ids_[reactant_ids_index];

forcing[row_index * state_forcing_columns + state_forcing_col_index] -=rate;

cell_forcing[row_index * state_forcing_columns + state_forcing_col_index] = forcing[row_index * state_forcing_columns + state_forcing_col_index];

//debugging
cell_forcing[row_index * state_forcing_columns + state_forcing_col_index] = forcing[row_index * state_forcing_columns + state_forcing_col_index];
}

__syncthreads();
for (int i_product = 0; i_product < product_num; i_product++){
int yields_index = initial_yields_index + i_product;
int product_ids_index = initial_product_ids_index + i_product;
int forcing_col_index = product_ids_[product_ids_index];
if (tid == 0){
cell_forcing_last[i_product] = forcing[row_index * state_forcing_columns + forcing_col_index];
yield[i_product] = yields_[yields_index];
}
forcing[row_index * state_forcing_columns + forcing_col_index] += yields_[yields_index] * rate;
}
}
Expand Down Expand Up @@ -146,6 +150,17 @@ namespace micm {
cudaMalloc(&d_cell_forcing, sizeof(double) * 10);
cell_forcing = (double*)malloc(sizeof(double) * 10);
cudaMemcpy(d_cell_forcing, forcing_data, sizeof(double)* 10, cudaMemcpyHostToDevice);

double* d_cell_forcing_last;
double* cell_forcing_last;
cudaMalloc(&d_cell_forcing_last, sizeof(double) * 2);
cell_forcing_last = (double*)malloc(sizeof(double) * 2);

size_t* d_yield;
size_t* yield;
cudaMalloc(&d_yield, sizeof(size_t) * 2);
yield = (size_t*)malloc(sizeof(size_t) * 2);




Expand Down Expand Up @@ -192,7 +207,9 @@ namespace micm {
d_rate_array_post,
d_state_variable,
d_cell_forcing,

d_cell_forcing_last,
d_yield,

d_rate_constants,
d_state_variables,
d_forcing,
Expand Down Expand Up @@ -232,6 +249,13 @@ namespace micm {
for (int k = 0; k < 10; k++){
std::cout << "this is cell forcing after update"<< cell_forcing[k]<<std::endl;
}

cudaMemcpy(cell_forcing_last, d_cell_forcing_last, sizeof(double)* 2, cudaMemcpyDeviceToHost);
cudaMemcpy(yield, d_yield, sizeof(size_t) * 2, cudaMemcpyDeviceToHost);
for (int i = 0; i < 2; i++){
std:: cout << "this is cell forcing data "<< cell_forcing_last[i]<< std::endl;
std::cout << "this is yield" << yield[i]<<std::endl;
}

cudaFree(d_rate_constants);
cudaFree(d_state_variables);
Expand Down
11 changes: 2 additions & 9 deletions test/unit/process/test_cuda_process_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ TEST(ProcessSet, Constructor)
const double* yields = set.yields_vector().data();
int yields_size = set.yields_vector().size();

for (int i = 0; i < number_of_reactants_size; i++){
std::cout << number_of_reactants[i]<<std::endl;
for (int i = 0; i < number_of_products_size; i++){
std::cout << "number of products: "<< number_of_products[i]<<std::endl;
}

micm::cuda::AddForcingTerms_kernelSetup(
Expand Down Expand Up @@ -90,13 +90,6 @@ TEST(ProcessSet, Constructor)
EXPECT_EQ(forcing[0][4], 1000.0 + 10.0 * 0.1 * 0.3 * 2.4);
EXPECT_EQ(forcing[1][4], 1000.0 + 110.0 * 1.1 * 1.3 * 2.4);

// //debugging
// std::cout<< "After operation operation"<<std::endl;
// double* forcing_data_after = forcing.AsVector().data();

// for (int k = 0; k < forcing_data_size; k++){
// std::cout << forcing_data_after[k]<<std::endl;
// }


// auto non_zero_elements = set.NonZeroJacobianElements();
Expand Down

0 comments on commit 903a608

Please sign in to comment.