<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic In R session, first Sys.setenv(MKL_MIC_ENABLE = 0), then 1 in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/In-R-session-first-Sys-setenv-MKL-MIC-ENABLE-0-then-1/m-p/1109820#M24285</link>
    <description>&lt;P&gt;Dear All,&lt;/P&gt;

&lt;P&gt;I'm trying to benchmark automatic offload to Xeon Phi by in R by changing OS environment variables (MKL_MIC_ENABLE, etc.) exclusively from within R via the base function Sys.setenv.&lt;/P&gt;

&lt;P&gt;Here's my Linux OS:&lt;/P&gt;

&lt;P&gt;uname -a&lt;BR /&gt;
	Linux cypress1 2.6.32-431.23.3.el6.x86_64 #1 SMP Thu Jul 31 17:20:51 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux&lt;/P&gt;

&lt;P&gt;I'm running the following version of R - built by our sys admin with MKL:&lt;/P&gt;

&lt;P&gt;&amp;gt; R.version&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;_&lt;BR /&gt;
	platform &amp;nbsp; &amp;nbsp; &amp;nbsp; x86_64-pc-linux-gnu&lt;BR /&gt;
	arch &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; x86_64&lt;BR /&gt;
	os &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; linux-gnu&lt;BR /&gt;
	system &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; x86_64, linux-gnu&lt;BR /&gt;
	status&lt;BR /&gt;
	major &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;BR /&gt;
	minor &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2.5&lt;BR /&gt;
	year &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2016&lt;BR /&gt;
	month &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;04&lt;BR /&gt;
	day &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;14&lt;BR /&gt;
	svn rev &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;70478&lt;BR /&gt;
	language &amp;nbsp; &amp;nbsp; &amp;nbsp; R&lt;BR /&gt;
	version.string R version 3.2.5 (2016-04-14)&lt;BR /&gt;
	nickname &amp;nbsp; &amp;nbsp; &amp;nbsp; Very, Very Secure Dishes&lt;/P&gt;

&lt;P&gt;Also see the following R files pasted below: multiGemm.R, gemm.R.&lt;/P&gt;

&lt;P&gt;When I run the following command...&lt;/P&gt;

&lt;P&gt;Rscript multiGemm.R&lt;/P&gt;

&lt;P&gt;...I observe that the automatic offload never occurs - even after the environment variable MKL_MIC_ENABLE has been set (changed from initially 0) to 1 within the R session via the base function "Sys.setenv".&lt;/P&gt;

&lt;P&gt;Is this a problem with our version of R - or is it simply not possible to change MKL_MIC_ENABLE from it's initial value from within R?&lt;/P&gt;

&lt;P&gt;Please advise, thanks.&lt;/P&gt;

&lt;P&gt;Best,&lt;/P&gt;

&lt;P&gt;CB&lt;/P&gt;

&lt;P&gt;gemm.R&lt;/P&gt;

&lt;P&gt;# See &lt;A href="https://software.intel.com/en-us/forums/intel-many-integrated-core/topic/538102" target="_blank"&gt;https://software.intel.com/en-us/forums/intel-many-integrated-core/topic/538102&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;require(Matrix)&lt;BR /&gt;
	#sink("output.txt")&lt;BR /&gt;
	cat("Initialization...\n")&lt;BR /&gt;
	a &amp;lt;- matrix(runif(N*N), ncol=N, nrow=N);&lt;BR /&gt;
	b &amp;lt;- matrix(runif(N*N), ncol=N, nrow=N);&lt;BR /&gt;
	cat("Matrix-matrix multiplication of size ", N, "x", N, ":\n")&lt;BR /&gt;
	timeVec &amp;lt;- gflopsVec &amp;lt;- c()&lt;BR /&gt;
	for (i in 1:5) {&lt;BR /&gt;
	&amp;nbsp; dt=system.time( c &amp;lt;- a %*% b )&lt;BR /&gt;
	&amp;nbsp; gflops = 2*N*N*N*1e-9/dt[3]&lt;BR /&gt;
	&amp;nbsp; names(gflops) &amp;lt;- NULL&lt;BR /&gt;
	&amp;nbsp; cat("Trial: ", i, ", time: ", dt[3], " sec, performance: ", gflops, " GFLOP/s\n")&lt;BR /&gt;
	&amp;nbsp; timeVec &amp;lt;- c(timeVec, dt[3])&lt;BR /&gt;
	&amp;nbsp; gflopsVec &amp;lt;- c(gflopsVec, gflops)&lt;BR /&gt;
	}&lt;BR /&gt;
	cat("Average time: ", mean(timeVec), " sec, average performance: ", mean(gflopsVec), " GFLOP/s\n")&lt;/P&gt;

&lt;P&gt;---&lt;/P&gt;

&lt;P&gt;multiGemm.R&lt;/P&gt;

&lt;P&gt;# See, e.g., &lt;A href="https://software.intel.com/en-us/forums/intel-many-integrated-core/topic/538102" target="_blank"&gt;https://software.intel.com/en-us/forums/intel-many-integrated-core/topic/538102&lt;/A&gt;&lt;BR /&gt;
	if ((.Platform$OS.type == "unix") &amp;amp;&amp;amp;&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; (grepl("cypress", system("uname -a", intern = T)))) {&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; setwd('~/R/benchmarks')&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; } else {&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; setwd('~/Documents/R/benchmarks')&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; }&lt;BR /&gt;
	stopifnot(file.exists("gemm.R"))&lt;/P&gt;

&lt;P&gt;micSettings &amp;lt;- &amp;nbsp;list(&lt;BR /&gt;
	&amp;nbsp; "Host CPU only" = list(&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; MKL_MIC_ENABLE="0",&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; OFFLOAD_REPORT="2"&lt;BR /&gt;
	&amp;nbsp; ),&lt;BR /&gt;
	&amp;nbsp; "MIC Affinity Balanced" = list(&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; MKL_MIC_ENABLE="1",&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; MIC_KMP_AFFINITY="balanced,verbose"&lt;BR /&gt;
	&amp;nbsp; ),&lt;BR /&gt;
	&amp;nbsp; "MIC Affinity Compact" = list(&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; MIC_KMP_AFFINITY="compact,verbose"&lt;BR /&gt;
	&amp;nbsp; ),&lt;BR /&gt;
	&amp;nbsp; "MIC Affinity Scatter" = list(&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; MIC_KMP_AFFINITY="scatter,verbose"&lt;BR /&gt;
	&amp;nbsp; )&lt;BR /&gt;
	)&lt;/P&gt;

&lt;P&gt;N &amp;lt;- 16000 # set N for gemm.R&lt;BR /&gt;
	multiGemm &amp;lt;- lapply(micSettings, function(settings) {&lt;BR /&gt;
	&amp;nbsp; cat("Settings=..\n")&lt;BR /&gt;
	&amp;nbsp; print(settings, row.names=F, sep = "\n")&lt;BR /&gt;
	&amp;nbsp; do.call(Sys.setenv, settings)&lt;BR /&gt;
	&amp;nbsp; source("gemm.R")&lt;BR /&gt;
	})&lt;BR /&gt;
	multiGemm &amp;lt;- as.data.frame(do.call(cbind, multiGemm))&lt;BR /&gt;
	rVersion &amp;lt;- with(R.version, paste(major, minor, sep = "."))&lt;BR /&gt;
	names(multiGemm) &amp;lt;- paste(rVersion, names(multiGemm), sep = "\n")&lt;BR /&gt;
	rdsPath &amp;lt;- paste('multiGemmR', rVersion, 'rds', sep = ".")&lt;BR /&gt;
	saveRDS(multiGemm, rdsPath)&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 11 Oct 2016 19:02:08 GMT</pubDate>
    <dc:creator>Carl_B_</dc:creator>
    <dc:date>2016-10-11T19:02:08Z</dc:date>
    <item>
      <title>In R session, first Sys.setenv(MKL_MIC_ENABLE = 0), then 1</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/In-R-session-first-Sys-setenv-MKL-MIC-ENABLE-0-then-1/m-p/1109820#M24285</link>
      <description>&lt;P&gt;Dear All,&lt;/P&gt;

&lt;P&gt;I'm trying to benchmark automatic offload to Xeon Phi by in R by changing OS environment variables (MKL_MIC_ENABLE, etc.) exclusively from within R via the base function Sys.setenv.&lt;/P&gt;

&lt;P&gt;Here's my Linux OS:&lt;/P&gt;

&lt;P&gt;uname -a&lt;BR /&gt;
	Linux cypress1 2.6.32-431.23.3.el6.x86_64 #1 SMP Thu Jul 31 17:20:51 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux&lt;/P&gt;

&lt;P&gt;I'm running the following version of R - built by our sys admin with MKL:&lt;/P&gt;

&lt;P&gt;&amp;gt; R.version&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;_&lt;BR /&gt;
	platform &amp;nbsp; &amp;nbsp; &amp;nbsp; x86_64-pc-linux-gnu&lt;BR /&gt;
	arch &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; x86_64&lt;BR /&gt;
	os &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; linux-gnu&lt;BR /&gt;
	system &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; x86_64, linux-gnu&lt;BR /&gt;
	status&lt;BR /&gt;
	major &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;BR /&gt;
	minor &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2.5&lt;BR /&gt;
	year &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2016&lt;BR /&gt;
	month &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;04&lt;BR /&gt;
	day &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;14&lt;BR /&gt;
	svn rev &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;70478&lt;BR /&gt;
	language &amp;nbsp; &amp;nbsp; &amp;nbsp; R&lt;BR /&gt;
	version.string R version 3.2.5 (2016-04-14)&lt;BR /&gt;
	nickname &amp;nbsp; &amp;nbsp; &amp;nbsp; Very, Very Secure Dishes&lt;/P&gt;

&lt;P&gt;Also see the following R files pasted below: multiGemm.R, gemm.R.&lt;/P&gt;

&lt;P&gt;When I run the following command...&lt;/P&gt;

&lt;P&gt;Rscript multiGemm.R&lt;/P&gt;

&lt;P&gt;...I observe that the automatic offload never occurs - even after the environment variable MKL_MIC_ENABLE has been set (changed from initially 0) to 1 within the R session via the base function "Sys.setenv".&lt;/P&gt;

&lt;P&gt;Is this a problem with our version of R - or is it simply not possible to change MKL_MIC_ENABLE from it's initial value from within R?&lt;/P&gt;

&lt;P&gt;Please advise, thanks.&lt;/P&gt;

&lt;P&gt;Best,&lt;/P&gt;

&lt;P&gt;CB&lt;/P&gt;

&lt;P&gt;gemm.R&lt;/P&gt;

&lt;P&gt;# See &lt;A href="https://software.intel.com/en-us/forums/intel-many-integrated-core/topic/538102" target="_blank"&gt;https://software.intel.com/en-us/forums/intel-many-integrated-core/topic/538102&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;require(Matrix)&lt;BR /&gt;
	#sink("output.txt")&lt;BR /&gt;
	cat("Initialization...\n")&lt;BR /&gt;
	a &amp;lt;- matrix(runif(N*N), ncol=N, nrow=N);&lt;BR /&gt;
	b &amp;lt;- matrix(runif(N*N), ncol=N, nrow=N);&lt;BR /&gt;
	cat("Matrix-matrix multiplication of size ", N, "x", N, ":\n")&lt;BR /&gt;
	timeVec &amp;lt;- gflopsVec &amp;lt;- c()&lt;BR /&gt;
	for (i in 1:5) {&lt;BR /&gt;
	&amp;nbsp; dt=system.time( c &amp;lt;- a %*% b )&lt;BR /&gt;
	&amp;nbsp; gflops = 2*N*N*N*1e-9/dt[3]&lt;BR /&gt;
	&amp;nbsp; names(gflops) &amp;lt;- NULL&lt;BR /&gt;
	&amp;nbsp; cat("Trial: ", i, ", time: ", dt[3], " sec, performance: ", gflops, " GFLOP/s\n")&lt;BR /&gt;
	&amp;nbsp; timeVec &amp;lt;- c(timeVec, dt[3])&lt;BR /&gt;
	&amp;nbsp; gflopsVec &amp;lt;- c(gflopsVec, gflops)&lt;BR /&gt;
	}&lt;BR /&gt;
	cat("Average time: ", mean(timeVec), " sec, average performance: ", mean(gflopsVec), " GFLOP/s\n")&lt;/P&gt;

&lt;P&gt;---&lt;/P&gt;

&lt;P&gt;multiGemm.R&lt;/P&gt;

&lt;P&gt;# See, e.g., &lt;A href="https://software.intel.com/en-us/forums/intel-many-integrated-core/topic/538102" target="_blank"&gt;https://software.intel.com/en-us/forums/intel-many-integrated-core/topic/538102&lt;/A&gt;&lt;BR /&gt;
	if ((.Platform$OS.type == "unix") &amp;amp;&amp;amp;&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; (grepl("cypress", system("uname -a", intern = T)))) {&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; setwd('~/R/benchmarks')&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; } else {&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; setwd('~/Documents/R/benchmarks')&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; }&lt;BR /&gt;
	stopifnot(file.exists("gemm.R"))&lt;/P&gt;

&lt;P&gt;micSettings &amp;lt;- &amp;nbsp;list(&lt;BR /&gt;
	&amp;nbsp; "Host CPU only" = list(&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; MKL_MIC_ENABLE="0",&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; OFFLOAD_REPORT="2"&lt;BR /&gt;
	&amp;nbsp; ),&lt;BR /&gt;
	&amp;nbsp; "MIC Affinity Balanced" = list(&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; MKL_MIC_ENABLE="1",&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; MIC_KMP_AFFINITY="balanced,verbose"&lt;BR /&gt;
	&amp;nbsp; ),&lt;BR /&gt;
	&amp;nbsp; "MIC Affinity Compact" = list(&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; MIC_KMP_AFFINITY="compact,verbose"&lt;BR /&gt;
	&amp;nbsp; ),&lt;BR /&gt;
	&amp;nbsp; "MIC Affinity Scatter" = list(&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; MIC_KMP_AFFINITY="scatter,verbose"&lt;BR /&gt;
	&amp;nbsp; )&lt;BR /&gt;
	)&lt;/P&gt;

&lt;P&gt;N &amp;lt;- 16000 # set N for gemm.R&lt;BR /&gt;
	multiGemm &amp;lt;- lapply(micSettings, function(settings) {&lt;BR /&gt;
	&amp;nbsp; cat("Settings=..\n")&lt;BR /&gt;
	&amp;nbsp; print(settings, row.names=F, sep = "\n")&lt;BR /&gt;
	&amp;nbsp; do.call(Sys.setenv, settings)&lt;BR /&gt;
	&amp;nbsp; source("gemm.R")&lt;BR /&gt;
	})&lt;BR /&gt;
	multiGemm &amp;lt;- as.data.frame(do.call(cbind, multiGemm))&lt;BR /&gt;
	rVersion &amp;lt;- with(R.version, paste(major, minor, sep = "."))&lt;BR /&gt;
	names(multiGemm) &amp;lt;- paste(rVersion, names(multiGemm), sep = "\n")&lt;BR /&gt;
	rdsPath &amp;lt;- paste('multiGemmR', rVersion, 'rds', sep = ".")&lt;BR /&gt;
	saveRDS(multiGemm, rdsPath)&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Oct 2016 19:02:08 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/In-R-session-first-Sys-setenv-MKL-MIC-ENABLE-0-then-1/m-p/1109820#M24285</guid>
      <dc:creator>Carl_B_</dc:creator>
      <dc:date>2016-10-11T19:02:08Z</dc:date>
    </item>
  </channel>
</rss>

