From cc0ac8ae38fc24a5cfdad069ab332f403cedefaf Mon Sep 17 00:00:00 2001 From: Rodrigo Canales Date: Thu, 28 Jul 2016 12:09:50 +0200 Subject: [PATCH] Auto-initialize MPI on loading and auto-finalize on detach --- DESCRIPTION | 3 ++- NAMESPACE | 2 ++ R/Environment.R | 2 -- R/zzz.R | 8 ++++++++ 4 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 R/zzz.R diff --git a/DESCRIPTION b/DESCRIPTION index 807b81c..9662af4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -12,4 +12,5 @@ Collate: Classes.R Methods.R Operators.R - pkgname.R \ No newline at end of file + pkgname.R + zzz.R \ No newline at end of file diff --git a/NAMESPACE b/NAMESPACE index 29abfa8..bede7ab 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,2 +1,4 @@ exportPattern("^[[:alpha:]]+") +export(".onLoad") +export(".onDetach") useDynLib(RElem) diff --git a/R/Environment.R b/R/Environment.R index 5ee8568..7db47ca 100644 --- a/R/Environment.R +++ b/R/Environment.R @@ -29,8 +29,6 @@ Initialize<-function(){ Finalize<-function(){ if( Initialized() ) .Call("finalize") - else - cat("Not initialized\n"); } WorldRank<-function(){ diff --git a/R/zzz.R b/R/zzz.R new file mode 100644 index 0000000..f11e7b2 --- /dev/null +++ b/R/zzz.R @@ -0,0 +1,8 @@ +.onLoad <- function(library = find.package("RElem"), package = "RElem"){ + Initialize() +} + +.onDetach <- function(library = find.package("RElem"), package = "RElem"){ + cat("MPI finalized") + Finalize() +}