Hello all, lately I’ve been spending a lot of time helping users of my RStan-dependent package troubleshoot toolchain configuration issues when installing the package from GitHub. In the course of that, I discovered something surprising on my own system: based on the flags used in a compiled model, as reported by
get_cxxflags(), the compiler seems to be ignoring the contents of my
This is my
> writeLines(readLines(Sys.getenv("R_MAKEVARS_USER"))) CXX14FLAGS += -Wno-unused -Wno-ignored-attributes -Wno-sign-compare -Wno-deprecated-declarations CXX14FLAGS += -Wno-attributes -Wno-parentheses -Wno-unknown-pragmas -Wno-infinite-recursion CXX14FLAGS += -mfpmath=sse -mstackrealign PKG_CPPFLAGS += -DUSE_STANC3 CXX14FLAGS += -mtune=native -O3 -mmmx -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2
The last line is what’s prescribed in the Configuring C++ Toolchain for Windows section of the RStan Getting Started wiki. All the no-warnings stuff is necessary to suppress extremely verbose and problematic compiler warnings, but the results I show below are unchanged if I delete everything before the last line.
Compiling the 8 schools model and querying the flags used, I get:
> mod <- stan_model(file = "8schools.stan") > get_cxxflags(mod)  "CXXFLAGS = -O2 -Wall $(DEBUGFLAG) -mfpmath=sse -msse2 -mstackrealign $(LTO)"
Same thing if I compile one of the much more complex Stan programs in my package (just compiling a single model, not installing the package). The flags returned by
get_cxxflags() are the same as the ones shown above, not the ones in
Does anyone have an idea why the compiler seems to be ignoring
Makevars.win? One thought I had was that perhaps
get_cxxflags() literally only reports the
CXXFLAGS (of which I have none specified) and ignores the
CXX14FLAGS, and/or that the models being compiled don’t require C++14 (caveat: I really have no idea what I’m talking about here). But the fact that the optimization flags, especially
-O3, don’t seem to be enforced appears to be a problem.
Thanks in advance for any suggestions.
R version 4.1.3 (2022-03-10) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 7 x64 (build 7601) Service Pack 1 Matrix products: default locale:  LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252  LC_MONETARY=English_United States.1252 LC_NUMERIC=C  LC_TIME=English_United States.1252 attached base packages:  stats graphics grDevices utils datasets methods base other attached packages:  rstan_2.26.1 StanHeaders_2.26.1 loaded via a namespace (and not attached):  Rcpp_1.0.8 compiler_4.1.3 pillar_1.7.0 tools_4.1.3  prettyunits_1.1.1 pkgbuild_1.3.1 jsonlite_1.8.0 lifecycle_1.0.1  tibble_3.1.6 gtable_0.3.0 pkgconfig_2.0.3 rlang_1.0.2  rstudioapi_0.13 DBI_1.1.2 cli_3.2.0 parallel_4.1.3  curl_4.3.2 loo_2.5.0 gridExtra_2.3 withr_2.5.0  dplyr_1.0.8 generics_0.1.2 vctrs_0.3.8 stats4_4.1.3  grid_4.1.3 tidyselect_1.1.2 glue_1.6.2 inline_0.3.19  R6_2.5.1 processx_3.5.2 fansi_1.0.2 ggplot2_3.3.5  callr_3.7.0 purrr_0.3.4 magrittr_2.0.2 codetools_0.2-18  matrixStats_0.61.0 scales_1.1.1 ps_1.6.0 ellipsis_0.3.2  assertthat_0.2.1 colorspace_2.0-3 V8_4.1.0 utf8_1.2.2  RcppParallel_5.1.5 munsell_0.5.0 crayon_1.5.0