initial snow demo
This commit is contained in:
parent
7a807aab47
commit
0b9fc2ab1c
3
demos/snow_package/mpi_snow_hello.sh
Normal file
3
demos/snow_package/mpi_snow_hello.sh
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
mpiexec -n 1 --hostfile /kube-openmpi/generated/hostfile R --vanilla -f snow-hello.R
|
6
demos/snow_package/slurm_submit_snow_hello.sh
Normal file
6
demos/snow_package/slurm_submit_snow_hello.sh
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#SBATCH --ntasks=5
|
||||||
|
|
||||||
|
cd $SLURM_SUBMIT_DIR
|
||||||
|
|
||||||
|
mpiexec -n 1 R --vanilla -f snow-hello.R
|
95
demos/snow_package/snow-hello.R
Normal file
95
demos/snow_package/snow-hello.R
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
### Paul Johnson
|
||||||
|
### 2017-07-20
|
||||||
|
|
||||||
|
### Garrett Mills
|
||||||
|
### 2019-05-02
|
||||||
|
|
||||||
|
### Demonstration of SNOW "Simple Network of Workstations" using MPI
|
||||||
|
### "Message Passing Interface" (OpenMPI implementation)
|
||||||
|
|
||||||
|
|
||||||
|
library(snow)
|
||||||
|
|
||||||
|
p <- rnorm(123, m = 33)
|
||||||
|
|
||||||
|
## Sub script asks for 18 cores, here cluster must
|
||||||
|
## be one smaller
|
||||||
|
CLUSTERSIZE <- mpi.universe.size()-1
|
||||||
|
|
||||||
|
cl <- makeCluster(CLUSTERSIZE, type = "MPI")
|
||||||
|
|
||||||
|
|
||||||
|
## One way to send function to each system.
|
||||||
|
## Could send identical arguments to nodes
|
||||||
|
clusterCall(cl, function() {
|
||||||
|
Sys.info()[c("nodename","machine")]
|
||||||
|
date()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
timeFn <- function(){
|
||||||
|
y1 <- Sys.info()[c("nodename","machine")]
|
||||||
|
y2 <- date()
|
||||||
|
list(y1, y2)
|
||||||
|
}
|
||||||
|
|
||||||
|
## Send function to each node
|
||||||
|
clusterExport(cl, c("timeFn"))
|
||||||
|
|
||||||
|
## Evaluates a string on a node
|
||||||
|
x1 <- clusterEvalQ(cl, timeFn())
|
||||||
|
|
||||||
|
print(x1)
|
||||||
|
|
||||||
|
|
||||||
|
clusterCall(cl, function() rnorm(1, 33, 1) )
|
||||||
|
|
||||||
|
|
||||||
|
myNorms <- matrix(rnorm(100*CLUSTERSIZE), ncol = CLUSTERSIZE)
|
||||||
|
|
||||||
|
## goes column by column
|
||||||
|
mypapply <- parApply(cl, myNorms, 2, print)
|
||||||
|
|
||||||
|
attributes(mypapply)
|
||||||
|
|
||||||
|
mypapply <- parApply(cl, myNorms, 2, mean )
|
||||||
|
|
||||||
|
mypapply
|
||||||
|
|
||||||
|
myNorms <- matrix(rnorm(100*CLUSTERSIZE), ncol = CLUSTERSIZE)
|
||||||
|
|
||||||
|
mySum <- function( v ){
|
||||||
|
s <-Sys.info()[c("nodename")]
|
||||||
|
s[2] <- date()
|
||||||
|
ms <- sum(v)
|
||||||
|
list(s, ms)
|
||||||
|
}
|
||||||
|
|
||||||
|
mypcapply <- parApply(cl, myNorms, 2, mySum)
|
||||||
|
|
||||||
|
mypcapply
|
||||||
|
|
||||||
|
myNorms <- matrix(rnorm(2500*CLUSTERSIZE), ncol = CLUSTERSIZE)
|
||||||
|
|
||||||
|
## Add the system date (includes time) before and after
|
||||||
|
## calculations to vector s
|
||||||
|
myMeans <- function(v){
|
||||||
|
s <- Sys.info()[c("nodename")]
|
||||||
|
s[2] <- date()
|
||||||
|
ms <- mean(v)
|
||||||
|
## want to slow this down so you can study the cluster? uncomment this:
|
||||||
|
## x <- rnorm(50000000); x <- log(50+x); sum(x); mean(x); quantile(x); gg <- cut(x, quantile(x))
|
||||||
|
s[3] <- date()
|
||||||
|
list(s, ms)
|
||||||
|
}
|
||||||
|
|
||||||
|
mypcapply <- parApply(cl, myNorms, 2, myMeans )
|
||||||
|
|
||||||
|
mypcapply
|
||||||
|
|
||||||
|
|
||||||
|
library(snow)
|
||||||
|
stopCluster(cl)
|
||||||
|
Rmpi::mpi.quit()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user