R/zzz.R

Defines functions onUnload onLoad

### Copyright (C) 2014 Hao Yu 
.onLoad <- function (lib, pkg) {
    library.dynam("Rmpi", pkg, lib)
    if (!TRUE)
	stop("Fail to load Rmpi dynamic library.")
    if (!is.loaded("mpi_initialize"))
	stop("Probably Rmpi has been detached. Please quit R.")

    if(.Call("mpidist",PACKAGE="Rmpi") == 2){
    	if (length(try(system("lamnodes",TRUE,ignore.stderr = TRUE))) == 0){
    		#cat("\n\tLAM/MPI runtime environment is not operating.\n")
    		#cat("\tStarting LAM/MPI runtime environment.\n")
	    system("lamboot -H",ignore.stderr = TRUE)
	}
    }
	
    if(!.Call("mpi_initialize",PACKAGE = "Rmpi"))
		stop("Cannot start MPI_Init(). Exit")
	#e <- environment() 
	#f <- function(e){
	#	if (mpi.comm.size(1)>0)
	#		mpi.close.Rslaves()
	#}
	#reg.finalizer(e, f, onexit=TRUE)
}

.onUnload <- function(libpath){
	mpi.finalize()
	library.dynam.unload("Rmpi", libpath)
}

Try the Rmpi package in your browser

Any scripts or data that you put into this service are public.

Rmpi documentation built on Nov. 13, 2018, 9:03 a.m.