primer.r

# Using Erathosthenes's Sieve to test MPI

# Load in the helper script for parallel tasks
#source("c-tools.r")
library("ctools")

c.start()

getP <- function(n){
	a <- c(2:n)
	I <- 2
	r <- c()

	while(I*I < n){
		r <- c(r,a[1])
		a <- a[-(which(a%%I == 0))]
		I <- a[1]
	}
	c(r,a)
}

# Need to export this
#c.export("getP")

loopy <- function(n){
	for(i in 3:n){
		primes <- getP(i)
	}
	# We actually don't need the primes, we need CPU cycles
	# and a way to check which machines are running the code

	host <- Sys.info()['nodename']
	print(paste("Hostname is",host))

}

# Need to export this
#c.export("loopy")

nums <- 5000:5007

# Need to export this
#c.export("nums")

# Do the actual exporting
c.export(T,"getP","loopy","nums")
#c.export(T)

c.lapply(X=nums,FUN=loopy)

c.done()
bamonroe/ctools documentation built on May 11, 2019, 6:19 p.m.