Hi @Bob_Carpenter !
Ok… you are hooked into Stan, for real, yes. I just looked at the matter of things and we can improve for sure. The current STAN_CPP_OPTIMS
flag is somewhat documented when you do a make help
in the cmdstan directory. For me this turns on flags which break stuff during linking the basic Bernoulli program such that I would not recommend it for the moment being on macOS. Here is what I’d recommend you (I am on macOS here):
library(cmdstanr)
## brute force version which isn't entirerly clean:
cmdstan_make_local(cpp_options=list(STAN_THREADS=TRUE,
##STAN_CPP_OPTIMS=FALSE, ## this option must not be defined as it will be in effect otherwise at the moment... thats a non-feature needing a fix, so don't define it if you don't want it for now.
STAN_NO_RANGE_CHECKS=TRUE,
## these optim variables are set by STAN_CPP_OPTIMS,
## but these are not working with my current Xcode from
## Jan 5th 2022
##CXXFLAGS_OPTIM=""
##CXXFLAGS_OPTIM_TBB="",
##CXXFLAGS_OPTIM_SUNDIALS=""
## brute-force make the tune stuff part of the compiler being called
CXX="clang++ -mtune=native -march=native",
CC="clang -mtune=native -march=native"
),
append=FALSE)
## cleaner version:
cmdstan_make_local(cpp_options=list(STAN_THREADS=TRUE,
##STAN_CPP_OPTIMS=FALSE, ## coupling this with the mtune/march fails for me
STAN_NO_RANGE_CHECKS=TRUE,
CXXFLAGS_OPTIM="-mtune=native -march=native",
CXXFLAGS_OPTIM_TBB="-mtune=native -march=native",
CXXFLAGS_OPTIM_SUNDIALS="-mtune=native -march=native"
),
append=FALSE)
rebuild_cmdstan(cores=4)
file <- file.path(cmdstan_path(), "examples", "bernoulli", "bernoulli.stan")
## let's check we get what we wanted (watch for the tune and arch settings)
mod <- cmdstan_model(file, force_recompile = TRUE, quiet=FALSE)
# names correspond to the data block in the Stan program
data_list <- list(N = 10, y = c(0,1,0,0,0,0,0,0,0,1))
fit <- mod$sample(
data = data_list,
seed = 123,
chains = 4,
parallel_chains = 4,
refresh = 500
)
ping @stevebronder the macOS settings for the optims thing need an update as it does break stuff right now. We also need to ensure that the optimisations are only turned on whenever STAN_CPP_OPTIMS is set equal to true. Right now they kick in whenever you define that variable.