# threads configuration: run
# rthreadsSetup(nThreads=2,
# sharedVars=list(nextRowNum=c(1,1,3),m=c(10,100000000)))
setup <- function() # run in "manager thread"
{
# generate vectors to be sorted, of different sizes
tmp <- c(30000000,70000000)
set.seed(9999)
nvals <- sample(tmp,10,replace=TRUE) # 10 vectors to sort
for (i in 1:10) {
n <- nvals[i]
m[i,1:(n+1)] <- c(n,runif(n))
}
}
doSorts <- function() # run in all threads, maybe with system.time()
{
rowNum <- myGlobals$myID+1 # my first vector to sort
while (rowNum <= nrow(m)) {
# as illustration of parallel operation, see which threads execute
# sorts on which rows
print(rowNum)
n <- m[rowNum,1]
x <- m[rowNum,2:(n+1)]
m[rowNum,2:(n+1)] <- sort(x)
rowNum <- rthreadsAtomicInc('nextRowNum')
}
# rthreadsWaitDone()
rthreadsBarrier()
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.