Skip to content

Commit

Permalink
Merge remote-tracking branch 'niehs/main' into nlopt-update
Browse files Browse the repository at this point in the history
  • Loading branch information
sciome-bot committed Nov 8, 2024
2 parents 56b95c2 + 33aedad commit 0bbece6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
1 change: 0 additions & 1 deletion R/model_averaging_fits.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ ma_continuous_fit <- function(D, Y, model_list = NA, fit_type = "laplace",
Y <- as.matrix(Y)
D <- as.matrix(D)
.setseedGSL(seed)
.set_threads(threads)
is_neg <- .check_negative_response(Y)

DATA <- cbind(D, Y)
Expand Down
2 changes: 1 addition & 1 deletion src/code_base/seeder.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#include <seeder.h>

THREAD_LOCAL gsl_rng* Seeder::rng = nullptr;
THREAD_LOCAL gsl_rng* Seeder::rng = nullptr;
23 changes: 22 additions & 1 deletion src/include/seeder.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,27 @@ class Seeder {
return &instance;
}

void reset_max_threads(int threads) {
#ifndef NO_OMP
if(max_threads < threads) {
int num_prev_threads = max_threads;
max_threads = threads;

rngs.reserve(threads);
#pragma omp parallel for
for (int i = 0; i < threads; i++) {
int thread_num = omp_get_thread_num();
if (thread_num < num_prev_threads) {
continue;
}
thread_local gsl_rng* r_local = gsl_rng_alloc(T);
gsl_rng_set(r_local, currentSeed);
rngs[thread_num] = r_local;
}
}
#endif
}

~Seeder() {
if (rng) {
gsl_rng_free(rng);
Expand All @@ -56,7 +77,7 @@ class Seeder {
nlopt_srand(seed);
currentSeed = seed;
}

double get_uniform() {
if (!rng) {
Rcpp::warning("Error: RNG not initialized.");
Expand Down
1 change: 0 additions & 1 deletion src/set_omp_threads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ int set_threads(int num_threads) {
#ifndef NO_OMP
if(omp_get_max_threads() > 1){
if (num_threads > omp_get_num_threads()) {
#pragma omp master
{ omp_set_num_threads(num_threads); }
// Rcpp::Rcout << "OpenMP threads set to " << num_threads << std::endl;
return 1;
Expand Down

0 comments on commit 0bbece6

Please sign in to comment.