Skip to content

Commit b0db59c

Browse files
committed
automate cflags
1 parent ea15862 commit b0db59c

File tree

2 files changed

+51
-9
lines changed

2 files changed

+51
-9
lines changed

R/benchmark.data.table.R

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,32 @@
1-
benchmark.data.table = function(script="benchmarks.Rraw", rbin="Rscript", desc=character()) {
1+
benchmark.data.table = function(script="benchmarks.Rraw", rbin="Rscript", desc=character(), libs=NULL) {
22
stopifnot(length(script)==1L)
3-
# make revision && make build && make install && R -q -e 'data.table:::benchmark.data.table()'
4-
fn = setNames(file.path("inst","benchmarks", script), script) ## this path only for development, finally use system.file(package="data.table", "benchmarks", script)
3+
# make revision && Rscript inst/benchmarks/boot.R ## install to various libs with various compilation flags
4+
# R -q -e 'data.table:::benchmark.data.table(libs=list.dirs("library/gcc"))'
5+
fn = setNames(file.path("inst","benchmarks", script), script) ## this path only for development, ultimately use system.file(package="data.table", "benchmarks", script)
56
desc = if (length(desc)) paste0(" ", desc) else ""
7+
if (is.null(libs)) libs = .libPaths()[1L]
68
mth = max.th()
79
ths = unique(c(1L, as.integer(mth * c(0.1,0.25,0.5,0.75,1))))
810
ths = ths[ths>0L]
911
cat("benchmark.data.table() running: ", names(fn), "\n", sep="")
1012
init = proc.time()[[3L]]
11-
for (th in ths) {
12-
cmd = sprintf("R_DATATABLE_NUM_THREADS=%s R_DATATABLE_NUM_PROCS_PERCENT=100 %s %s%s", th, rbin, fn, desc)
13-
cat(cmd,"\n",sep="")
14-
system(cmd)
13+
for (lib in libs) {
14+
for (th in ths) {
15+
cmd = sprintf("R_LIBS_USER=%s R_DATATABLE_NUM_THREADS=%s R_DATATABLE_NUM_PROCS_PERCENT=100 %s %s%s", lib, th, rbin, fn, desc)
16+
cat(cmd,"\n",sep="")
17+
system(cmd)
18+
}
1519
}
1620
t = proc.time()[[3L]]
1721
cat("Benchmarks in ", names(fn), " completed in ", trunc(t-init), "s\n", sep="")
1822
invisible(TRUE)
1923
}
20-
2124
max.th = function() {
2225
old = setDTthreads(0L)
2326
th = getDTthreads()
2427
setDTthreads(old)
2528
th
2629
}
27-
2830
omp = function() {
2931
omp = capture.output(th<-getDTthreads(verbose=TRUE))
3032
val = function(x) tail(strsplit(x, " ", fixed=TRUE)[[1L]], 1L)
@@ -93,3 +95,8 @@ benchmark = function(num, expr, desc=NA_character_) {
9395
if (num>0) fwrite(l, "benchmarks.csv", append=TRUE, row.names=FALSE)
9496
invisible(TRUE)
9597
}
98+
summary.benchmark = function() {
99+
d = fread("benchmarks.csv")
100+
d[,.(cflags, num, fun, args, desc, th, user_self, sys_self, elapsed)]
101+
}
102+

inst/benchmarks/boot.R

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# make library structure and Makevars files
2+
3+
do_cflags = function(x) paste(paste0("-",sub("_","=",x,fixed=TRUE)), collapse=" ")
4+
lib_path = "library"
5+
cc = "gcc" ## const
6+
flags = c(
7+
"O3","O3-mtune_native","O3-g",
8+
"O2","O2-mtune_native","O2-g",
9+
"O0","O0-g"
10+
)
11+
libs = file.path(lib_path, cc, flags)
12+
vapply(libs, dir.create, showWarnings = TRUE, recursive=TRUE, NA)
13+
mvs = file.path(libs, "Makevars")
14+
cflags = vapply(strsplit(flags, "-", fixed=TRUE), do_cflags , "")
15+
cc_cflags = paste(sep="\n", paste0("CC=",cc), paste0("CFLAGS=",cflags))
16+
mapply(writeLines, cc_cflags, mvs)
17+
18+
# install using different compilation flags
19+
20+
#inst = sprintf("R_MAKEVARS_USER=%s R CMD INSTALL --library=%s %s", mvs, libs, "data.table_1.12.9.tar.gz")
21+
#sapply(inst, system)
22+
23+
inst = function(lib, tarball="data.table_1.12.9.tar.gz") { ## till R_MAKEVARS_USER works
24+
file.copy(file.path(lib,"Makevars"), "~/.R/Makevars", overwrite=TRUE)
25+
cmd = sprintf("R CMD INSTALL --library=%s %s", lib, tarball)
26+
cat(cmd,"\n",sep="")
27+
system(cmd)
28+
}
29+
sapply(libs, inst)
30+
31+
# cleanup
32+
inst("library/gcc/O3-mtune_native")
33+
34+
#unlink(lib_path, recursive=TRUE)
35+

0 commit comments

Comments
 (0)