Configuring complier flags in cmdstanpy

Hi all,

I wonder if there is a documentation somewhere about how to turn on/off complier flags in cmdstanpy?

At the stage, I want to explore if change turning on/off CXXFLGAS += -march=native -mtune=native or using external BLAS/LAPACK would speed up my GP fitting (



Looks like our cmdstanpy devs are all away from the forums, so I can help. Sorry it took so long for such a simple question.

The API doc for CmdStanModel explains how to configure compiler flags in C++:

Hi Bob,

Many thanks.

I would like to clarify a few things:

  1. How can I translate “CXXFLAGS+= -O3 -march=native -mtune=native” into the python dict cpp_options ?
    a. Do I need to include “-” as part of the key?
    b. For “O3”, there is not “=” sign. Should I treat the “O3” as key or “O” as key and “3” as value?

  2. In the linked thread, there was discussion about setting “STAN_CPP_OPTIMS=TRUE” . Is this still required/recommended? If so, how can I set this flag in cmdstanpy (Under stand_options or cpp_options)?



The way CmdStanPy treats the cpp_options dictionary is by pasting together the key and value with = and then adding it to the make invocation. It doesn’t try to be particularly smart

So if I wanted the effect of make examples/bernoulli/bernoulli FOO="-bar -baz" I would create the dictionary as {"FOO": "-bar -baz"}.

For the other things you mentioned, they could be written as {"CXXFLAGS_PROGRAM": "-march=native"} or {"STAN_CPP_OPTIMS": "TRUE"}

(I left out mtune since it is implied by march, and O=3 is the default. For why I used CXXFLAGS_PROGRAM vs CXXFLAGS, the make behavior is a bit odd with the former, see this issue)