stan-dev / stan-dev/rstan

CFLAGS from R_MAKEVARS_USER no longer respected when compiling stan model

Open
#621 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
R
Stars
1.1k
Forks
266
Avg merge
2h 56m
Merged PRs (30d)
1

Description

Summary:

It should be possible to set a custom Makevars file using the environment variable R_MAKEVARS_USER. This worked up until 2.18.1 (GitRev 398abb20baf6) , however it seems to be broken in 2.18.2

Description:

I use the R_MAKEVARS_USER file to set custom CFLAGS when compiling my stan models. In particular, I like to use -O0 when I am debugging the nuts and bolts of my model, and then use -O2 when I am actually running my model. In both cases, I leave out the '-g' flag since the debugging symbols slow down compiling, and are not particularly useful to me.

Reproducible Steps:

If I create a Makevar file:

CFLAGS =              -O0 -pipe  -std=gnu99 
CXXFLAGS =            -O0 -pipe -Wno-unused -std=c++11

CXX=g++

And set the appropriate environment variable, then look at the process as it is compiling, I see that my CFLAGS are ignored:

$ps aux|grep cc1
aaronjg  22382  0.0  1.0 135924 85424 pts/9    R+   22:31   0:00 /usr/lib/gcc/x86_64-linux-gnu/5/cc1plus -quiet -I /usr/share/R/include -I /home/aaronjg/R/x86_64-pc-linux-gnu-library/3.5/Rcpp/include/ -I /home/aaronjg/R/x86_64-pc-linux-gnu-library/3.5/RcppEigen/include/ -I /home/aaronjg/R/x86_64-pc-linux-gnu-library/3.5/RcppEigen/include/unsupported -I /home/aaronjg/R/x86_64-pc-linux-gnu-library/3.5/BH/include -I /home/aaronjg/R/x86_64-pc-linux-gnu-library/3.5/StanHeaders/include/src/ -I /home/aaronjg/R/x86_64-pc-linux-gnu-library/3.5/StanHeaders/include/ -I /home/aaronjg/R/x86_64-pc-linux-gnu-library/3.5/rstan/include -imultiarch x86_64-linux-gnu -D_GNU_SOURCE -D NDEBUG -D EIGEN_NO_DEBUG -D BOOST_DISABLE_ASSERTS -D _FORTIFY_SOURCE=2 file573053c287bf.cpp -quiet -dumpbase file573053c287bf.cpp -mtune=generic -march=x86-64 -auxbase-strip file573053c287bf.o -g -g -O2 -Wformat=1 -Werror=format-security -Wdate-time -std=gnu++14 -fpic -fstack-protector-strong -fstack-protector-strong -Wformat -Wformat-security -o /tmp/ccJvwHtD.s

This had worked fine in rstan 2.18.1 GitRev 398abb20baf6 (I have not yet tested it in the 2.18.1 final release)

If I set them as PKG_CFLAGS,

CFLAGS =              -O0 -pipe  -std=gnu99 
CXXFLAGS =            -O0 -pipe -Wno-unused -std=c++11

CXX=g++

PKG_CFLAGS =              -O0 -pipe  -std=gnu99 
PKG_CXXFLAGS =            -O0 -pipe -Wno-unused -std=c++11

they are included, but overridden by other CFLAGS that are coming from somewhere else.

aaronjg  22222  162  2.8 335968 227412 pts/9   R+   22:30   0:01 /usr/lib/gcc/x86_64-linux- gnu/5/cc1plus -quiet -I /usr/share/R/include -I /home/aaronjg/R/x86_64-pc-linux-gnu-library /3.5/Rcpp/include/ -I /home/aaronjg/R/x86_64-pc-linux-gnu-library/3.5/RcppEigen/include/ -I /home/aaronjg/R/x86_64-pc-linux-gnu-library/3.5/RcppEigen/include/unsupported -I /home/aaronjg/R/x86_64-pc-linux-gnu-library/3.5/BH/include -I /home/aaronjg/R/x86_64-pc-linux-gnu-library/3.5/StanHeaders/include/src/ -I /home/aaronjg/R/x86_64-pc-linux-gnu-library/3.5/StanHeaders/include/ -I /home/aaronjg/R/x86_64-pc-linux-gnu-library/3.5/rstan/include -imultiarch x86_64-linux-gnu -D_GNU_SOURCE -D NDEBUG -D EIGEN_NO_DEBUG -D BOOST_DISABLE_ASSERTS -D _FORTIFY_SOURCE=2 file567c1917208.cpp -quiet -dumpbase file567c1917208.cpp -mtune=generic -march=x86-64 -auxbase-strip file567c1917208.o -g -g -O0 -O2 -Wno-unused -Wformat=1 -Werror=format-security -Wdate-time -std=gnu++14 -std=c++11 -fpic -fstack-protector-strong -fstack-protector-strong -Wformat -Wformat-security -o -
RStan Version:

2.18.2

R Version:

R version 3.5.3 (2019-03-11)

Operating System:

Ubuntu 16.04

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the RStan 2.18.2 compilation with R_MAKEVARS_USER set to the shown Makevars contents, and compare the compiler command with the 2.18.1 behavior described in the issue. Trace how CFLAGS, CXXFLAGS, PKG_CFLAGS, and PKG_CXXFLAGS enter Stan model compilation; done means custom flags from R_MAKEVARS_USER are respected without unintended overrides.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, r
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
40/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.