Skip to content

Commit

Permalink
Not in parallel when ncores is one.
Browse files Browse the repository at this point in the history
  • Loading branch information
pbastide committed Feb 27, 2024
1 parent a837f8d commit b69f4e1
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions R/phylogeneticCorrelations.R
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,17 @@ get_consensus_tree <- function(y_data, design, phy, model, measurement_error, we
starting_values <- get_starting_values(alpha_bounds, ...)
dots_args <- get_dots_args(...)

cl <- parallel::makeCluster(ncores) # , outfile = ""
doParallel::registerDoParallel(cl)
on.exit(parallel::stopCluster(cl))
if (ncores > 1) {
cl <- parallel::makeCluster(ncores) # , outfile = ""
doParallel::registerDoParallel(cl)
on.exit(parallel::stopCluster(cl))
`%myinfix%` <- `%dopar%`
} else {
`%myinfix%` <- `%do%`
}
reqpckg <- c("phylolm")

all_fits <- foreach::foreach(i = 1:nrow(y_data), .packages = reqpckg) %dopar% {
all_fits <- foreach::foreach(i = 1:nrow(y_data), .packages = reqpckg) %myinfix% {
y <- y_data[i, ]
# w <- weights[i, ]

Expand Down

0 comments on commit b69f4e1

Please sign in to comment.