Skip to content
Open
Show file tree
Hide file tree
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
13 changes: 2 additions & 11 deletions R/BandsPartition_TMLA.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,7 @@ BandsPartition_TMLA <- function(evnVariables = NULL,

#Development
#Start Cluster
if (Sys.getenv("RSTUDIO") == "1" &&
!nzchar(Sys.getenv("RSTUDIO_TERM")) &&
Sys.info()["sysname"] == "Darwin" &&
as.numeric(gsub('[.]', '', getRversion())) >= 360) {
cl <- parallel::makeCluster(cores,outfile="", setup_strategy = "sequential")
}else{
cl <- parallel::makeCluster(cores,outfile="")
}
doParallel::registerDoParallel(cl)

cl <- start_cluster(cores)

#Separate data by groups
RecordsData <-
Expand Down Expand Up @@ -583,6 +574,6 @@ BandsPartition_TMLA <- function(evnVariables = NULL,
sep = "\t",
row.names = F
)
parallel::stopCluster(cl)
stop_cluster(cl)
return(FinalResult)
}
13 changes: 3 additions & 10 deletions R/BlockPartition_TMLA.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,7 @@ BlockPartition_TMLA <- function(evnVariables = NULL,
# BestGridList <- rep(list(NULL),length(RecordsData))

#Start Cluster
if (Sys.getenv("RSTUDIO") == "1" &&
!nzchar(Sys.getenv("RSTUDIO_TERM")) &&
Sys.info()["sysname"] == "Darwin" &&
as.numeric(gsub('[.]', '', getRversion())) >= 360) {
cl <- parallel::makeCluster(cores,outfile="", setup_strategy = "sequential")
}else{
cl <- parallel::makeCluster(cores,outfile="")
}
doParallel::registerDoParallel(cl)
cl <- start_cluster(cores)

# LOOP----
results <-
Expand Down Expand Up @@ -598,7 +590,8 @@ BlockPartition_TMLA <- function(evnVariables = NULL,
return(out)
}

parallel::stopCluster(cl)
stop_cluster(cl)

FinalResult <- dplyr::bind_rows(lapply(results, function(x) x[[1]]))
FinalInfoGrid <- dplyr::bind_rows(lapply(results, function(x) x[[2]]))

Expand Down
12 changes: 2 additions & 10 deletions R/Ensemble_TMLA.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,7 @@ Ensemble_TMLA <- function(DirR,
cores,
ensemble_metric = NULL) {
#Start Cluster----
if (Sys.getenv("RSTUDIO") == "1" &&
!nzchar(Sys.getenv("RSTUDIO_TERM")) &&
Sys.info()["sysname"] == "Darwin" &&
as.numeric(gsub('[.]', '', getRversion())) >= 360) {
cl <- parallel::makeCluster(cores,outfile="", setup_strategy = "sequential")
}else{
cl <- parallel::makeCluster(cores,outfile="")
}
doParallel::registerDoParallel(cl)
cl <- start_cluster(cores)

#Create Folders----
DirENS <- paste(DirR, "Ensemble", sep = "/")
Expand Down Expand Up @@ -629,5 +621,5 @@ Ensemble_TMLA <- function(DirR,
col.names = T,
row.names = F
)
parallel::stopCluster(cl)
stop_cluster(cl)
}
15 changes: 3 additions & 12 deletions R/FitENM_Parallel_TMLA.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,8 @@ FitENM_TMLA_Parallel <- function(RecordsData,
Ti <- Sys.time()
options(warn = -1)

#Start Cluster
# temporary parallel package debug for macOS systems
if (Sys.getenv("RSTUDIO") == "1" &&
!nzchar(Sys.getenv("RSTUDIO_TERM")) &&
Sys.info()["sysname"] == "Darwin" &&
as.numeric(gsub('[.]', '', getRversion())) >= 360) {
cl <- parallel::makeCluster(cores,outfile="", setup_strategy = "sequential")
}else{
cl <- parallel::makeCluster(cores,outfile="")
}
doParallel::registerDoParallel(cl)
#Start Cluster if necessary
cl <- start_cluster(cores)

# Directory to save----
folders <- paste(DirSave,"Algorithm",Algorithm,sep="/")
Expand Down Expand Up @@ -4058,5 +4049,5 @@ InfoModeling <- list(c("########################################################
lapply(InfoModeling, write,
paste(DirSave, "/InfoModeling.txt", sep=""), append=TRUE,
ncolumns=20, sep='\t')
parallel::stopCluster(cl)
stop_cluster(cl)
}
24 changes: 4 additions & 20 deletions R/M_delimited_TMLA.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,7 @@ M_delimited <- function(var,
return(x)
})

if (Sys.getenv("RSTUDIO") == "1" &&
!nzchar(Sys.getenv("RSTUDIO_TERM")) &&
Sys.info()["sysname"] == "Darwin" &&
as.numeric(gsub('[.]', '', getRversion())) >= 360) {
cl <- parallel::makeCluster(cores,outfile="", setup_strategy = "sequential")
}else{
cl <- parallel::makeCluster(cores,outfile="")
}
doParallel::registerDoParallel(cl)
cl <- start_cluster(cores)
foreach(i = 1:length(M_list),
.packages = c("raster")) %dopar% {
if (Buffer_Opt == 2) {
Expand All @@ -105,7 +97,7 @@ M_delimited <- function(var,
format = "GTiff",
overwrite = T)
}
parallel::stopCluster(cl)
stop_cluster(cl)
}

if (method == 'MASK') {
Expand Down Expand Up @@ -136,15 +128,7 @@ M_delimited <- function(var,
x <- x[x != 0]
})

if (Sys.getenv("RSTUDIO") == "1" &&
!nzchar(Sys.getenv("RSTUDIO_TERM")) &&
Sys.info()["sysname"] == "Darwin" &&
as.numeric(gsub('[.]', '', getRversion())) >= 360) {
cl <- parallel::makeCluster(cores,outfile="", setup_strategy = "sequential")
}else{
cl <- parallel::makeCluster(cores,outfile="")
}
doParallel::registerDoParallel(cl)
cl <- start_cluster(cores)
foreach(i = 1:length(sp.Ecoregions),
.packages = c("raster")) %dopar% {
EcoregionSp <- EcoregionsFile
Expand All @@ -159,7 +143,7 @@ M_delimited <- function(var,
overwrite = T
)
}
parallel::stopCluster(cl)
stop_cluster(cl)
}

if (method == 'USER-DEFINED') {
Expand Down
22 changes: 22 additions & 0 deletions R/cluster.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

start_cluster <- function(cores) {
cl <- NULL
if (cores > 1) {
if (Sys.getenv("RSTUDIO") == "1" &&
!nzchar(Sys.getenv("RSTUDIO_TERM")) &&
Sys.info()["sysname"] == "Darwin" &&
as.numeric(gsub('[.]', '', getRversion())) >= 360) {
cl <- parallel::makeCluster(cores,outfile="", setup_strategy = "sequential")
}else{
cl <- parallel::makeCluster(cores,outfile="")
}
doParallel::registerDoParallel(cl)
}
return(cl)
}

stop_cluster <- function(cluster) {
if (!is.null(cluster)) {
parallel::stopCluster(cluster)
}
}