From b0b710ee9f9bb9bbe9708676d0c5822465e02203 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Sat, 15 Apr 2023 15:35:06 +0200 Subject: Make predefined symbols safer We still need to create a parallel processing cluster _after_ creating a compiled model that is moved to a user defined location, at least I did not find another way to make it work. This is not a problem with parallel processing without a cluster, which is not available on Windows. --- .../hierarchical_kinetics/skeleton/skeleton.Rmd | 24 ++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'inst') diff --git a/inst/rmarkdown/templates/hierarchical_kinetics/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/hierarchical_kinetics/skeleton/skeleton.Rmd index 38a6bd20..cb328308 100644 --- a/inst/rmarkdown/templates/hierarchical_kinetics/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/hierarchical_kinetics/skeleton/skeleton.Rmd @@ -21,11 +21,18 @@ library(readxl) ```{r n_cores, cache = FALSE} n_cores <- detectCores() -if (Sys.info()["sysname"] == "Windows") { - cl <- makePSOCKcluster(n_cores) -} else { - cl <- makeForkCluster(n_cores) +# We need to start a new cluster after defining a compiled model that is +# saved as a DLL to the user directory, therefore we define a function +# This is used again after defining the pathway model +start_cluster <- function(n_cores) { + if (Sys.info()["sysname"] == "Windows") { + ret <- makePSOCKcluster(n_cores) + } else { + ret <- makeForkCluster(n_cores) + } + return(ret) } +cl <- start_cluster(n_cores) ``` \clearpage @@ -179,6 +186,10 @@ illparms(parent_best_pH_2) parms(parent_best_pH_2, ci = TRUE) |> kable(digits = 3) ``` +```{r} +stopCluster(cl) +``` + \clearpage # Pathway fits @@ -203,6 +214,7 @@ Separate evaluations of all datasets are performed with constant variance and using two-component error. ```{r path-1-sep, dependson = c("path-1-degmod", "ds")} +cl <- start_cluster(n_cores) sforb_sep_const <- mmkin(list(sforb_path = m_sforb_sfo2), ds, cluster = cl, quiet = TRUE) sforb_sep_tc <- update(sforb_sep_const, error_model = "tc") @@ -268,6 +280,10 @@ plot(path_1_refined) parms(path_1_refined, ci = TRUE) |> kable(digits = 3) ``` +```{r} +stopCluster(cl) +``` + \clearpage # Appendix -- cgit v1.2.1