library(oneMKL.MatrixCal)
library(data.table)
library(nanotime)
threadList <- 2^(0:5)
dimList <- 2^(8:13)
resDT_vanilla <- data.table(
method = "Vanilla",
dimension = dimList,
thread = 1,
time = rep(0, length(dimList)),
replications = rep(0, length(dimList))
)
resDT_mkl <- data.table(
method = "oneMKL.MatrixCal",
dimension = rep(dimList, length(threadList)),
thread = rep(threadList, each=length(dimList)),
time = rep(0, length(threadList) * length(dimList)),
replications = rep(0, length(threadList) * length(dimList))
)
for (i in seq_along(dimList)) {
set.seed(100)
d <- dimList[i]
replication <- ifelse(d >= 2048, 10, 50)
A <- matrix(rnorm(d*d), d, d)
B <- matrix(rnorm(d), d, d/16)
st <- nanotime(Sys.time())
for (k in 1:replication) {
A%*%B
# solve(A, B)
}
et <- nanotime(Sys.time())
resDT_vanilla[dimension == d, `:=`(time = as.integer(et - st) / 1000000 /replication, replications = replication)]
for (t in threadList) {
setMKLThreads(t)
st <- nanotime(Sys.time())
for (k in 1:replication) {
fMatProd(A, B)
# fMatSolve(A, B)
}
et <- nanotime(Sys.time())
resDT_mkl[(dimension == d) & (thread == t), `:=`(time = as.integer(et - st) / 1000000 /replication, replications = replication)]
}
}
fwrite(rbind(resDT_vanilla, resDT_mkl), "matrix_multiply_results.csv")
# fwrite(rbind(resDT_vanilla, resDT_mkl), "solve_results.csv")