CmdStanR: how to set C++ flags?

I would like my models to be compiled with -march=native etc. Is there a straightforward way of setting C++ flags for the compile() method? I looked at cpp_options but I can’t figure out how to use it to pass this kind of information.

I think you just supply them as a string in a cpp_options list element named cxxflags:

mod$compile(
	quiet = F #to print the compile command
	, force = T #in case it was compiled before without the cpp_options
	, cpp_options = list(
		cxxflags = "-march=native"
	)
)

I haven’t done this before myself, so report back on whether I’m correct and it works for you.

Unfortunately, it doesn’t seem to work.

Ok, I have figured out how to do it. One needs to store the compiler flags in the CmdStan makefile (!!) and then rebuild the stan libraries. A bit complicated, but seems to work.

Basically something like this:

cpp_options <- list(
   "CXXFLAGS+= -O3 -march=native -mtune=native"
 )
cmdstan_make_local(cpp_options = cpp_options)
rebuild_cmdstan()

What is the output you get?

Output in which case? Modifying the makefile as I mention in the previous post works — and it has to be done anyway, since linked stan libraries must be build with the same flags anyway.

Ah, sorry, the app I’m using didn’t show all of your posts, just the one saying it didn’t work.