C++ configuration

I have a question concerning the C++ configuration for the “rstan” package. My OS is Windows 10, 64 bit. The rstan version is 2.18.2, the R version is 3.5.1.

I followed the instructions on https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started to install and configure rstan. I also run the code from section “Configuration of the C++ Toolchain” which gave me the following content of the file “~/.R/Makevars.win”:

CXX14FLAGS=-O3 -march=native -mtune=native
CXX11FLAGS=-O3 -march=native -mtune=native

However, after running the “Eight schools” example, print()ing “schools_fit@stanmodel@dso” (with “schools_fit” denoting the stanfit object returned from stan()) gives:

Created on: ‘x86_64, mingw32’ with ‘CXXFLAGS = -O2 -Wall $(DEBUGFLAG) -mtune=generic’.

I was wondering if the CXXFLAGS shouldn’t rather be “-O3 -march=native -mtune=native” (because of the “~/.R/Makevars.win” file above). While searching for answer on the internet, I stumbled across the following GitHub site: https://github.com/davharris/rstan/wiki/Installing-RStan-on-Windows

According to this site, the content of the “~/.R/Makevars” file (note that it is not “~/.R/Makevars.win”, but I used it for the “~/.R/Makevars.win” file anyway) should be:

CXXFLAGS=-O3 -mtune=native -march=native -Wno-unused-variable -Wno-unused-function

When using this for the content of the “~/.R/Makevars.win” file, print()ing “schools_fit@stanmodel@dso” gives indeed:

Created on: ‘x86_64, mingw32’ with ‘CXXFLAGS=-O3 -mtune=native -march=native -Wno-unused-variable -Wno-unused-function’.

Now my question is: What is the correct content to be specified for the “~/.R/Makevars.win” file? Is the difference between the upper two instruction sites due to the latter one being valid only for Linux (or Mac)?

Furthermore, rstan gives a package startup message recommending “Sys.setenv(LOCAL_CPPFLAGS = ‘-march=native’)”. According to https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started, this is not necessary after running the code from the “C++ configuration” section. However, according to https://stackoverflow.com/questions/43597632/understanding-the-contents-of-the-makevars-file-in-r-macros-variables-r-ma?rq=1, there is a difference between the CXXFLAGS and the CPPFLAGS. So is it correct that LOCAL_CPPFLAGS doesn’t need to be specified even though only the CXX14FLAGS and the CXX11FLAGS were specified in the “Makevars” file?

I believe you are overthinking here. Either ~/.R/Makevars or ~/.R/Makevars.win are valid configuration files. What schools_fit@stanmodel@dso prints seems to be a bit out of date, now that we are using part of the C++14 standard, but if you have CXX11FLAGS=-O3 -march=native -mtune=native it will use those. Likewise, @davharris seems to have made a fork of the RStan repo two years ago and the instructions have changed since then (@davharris, you might pull the latest changes to help avoid this kind of confusion).