Reputation: 57
I am using this double for loop to calculate the value temp
. rc
and tc
are results from two hashmap hash_rr and hash_tt. Is there a way to optimize the double forloop to reduce the computational time?
rc = as<IntegerMatrix>(hash_rr[std::to_string(r)]);
tc = as<IntegerMatrix>(hash_tt[std::to_string(t)]);
double temp = 0;
for (int i = 0; i < rc.nrow(); i++){
for (int j = 0; j < tc.nrow(); j++){
a1 = rc(i,0) - (b_eff_prev + 1);
a2 = rc(i,1);
b1 = tc(j,0);
b2 = tc(j,1);
// Rcpp::Rcout << "a,b: " << NumericVector::create(a1,b1,a2,b2) << std::endl;
temp += nonstop_grid_prev(a1, b1) * den_cpp(a2, b2, n, p);
}
}
I tried parallel computing of the double for loop, there is almost no improvement on the computation time.
omp_set_num_threads(omp_get_max_threads());
#pragma omp parallel for reduction(+:temp)
Upvotes: 0
Views: 27