stan-dev / rstan

RStan, the R interface to Stan
https://mc-stan.org
1.04k stars 269 forks source link

set_cppo('debug') broken #46

Closed jonathan-g closed 10 years ago

jonathan-g commented 10 years ago

This is not related to the problems with the new (11.0) release of Rcpp, but g++ won't compile stan models under the old (10.6) Rcpp if I set_cppo('debug').

Testing using the 8 schools model:

library(rstan)
set_cppo("fast")

schools_code <- '
  data {
    int<lower=0> J; // number of schools 
    real y[J]; // estimated treatment effects
    real<lower=0> sigma[J]; // s.e. of effect estimates 
  }
  parameters {
    real mu; 
    real<lower=0> tau;
    real eta[J];
  }
  transformed parameters {
    real theta[J];
    for (j in 1:J)
      theta[j] <- mu + tau * eta[j];
  }
  model {
    eta ~ normal(0, 1);
    y ~ normal(theta, sigma);
  }
'

schools_dat <- list(J = 8, 
                    y = c(28,  8, -3,  7, -1,  1, 18, 12),
                    sigma = c(15, 10, 16, 11,  9, 11, 10, 18))

fit <- stan(model_code = schools_code, data = schools_dat, 
            iter = 1000, chains = 4)

set_cppo("debug")
fit <- stan(model_code = schools_code, data = schools_dat, 
            iter = 1000, chains = 4)

produces output

TRANSLATING MODEL 'schools_code' FROM Stan CODE TO C++ CODE NOW.
COMPILING THE C++ CODE FOR MODEL 'schools_code' NOW.
cygwin warning:
  MS-DOS style path detected: C:/PROGRA~1/R/R-30~1.2/etc/x64/Makeconf
  Preferred POSIX equivalent is: /cygdrive/c/PROGRA~1/R/R-30~1.2/etc/x64/Makeconf
  CYGWIN environment variable option "nodosfilewarning" turns off this warning.
  Consult the user's guide for more details about POSIX paths:
    http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
C:/Users/JonathanGilligan/Documents/R/win-library/3.0/rstan/include//stansrc/stan/agrad/rev/var_stack.hpp:49:17: warning: 'void stan::agrad::free_memory()' defined but not used [-Wunused-function]
C:/Users/JonathanGilligan/Documents/R/win-library/3.0/rstan/include//stansrc/stan/agrad/rev/chainable.hpp:87:17: warning: 'void stan::agrad::set_zero_all_adjoints()' defined but not used [-Wunused-function]
SAMPLING FOR MODEL 'schools_code' NOW (CHAIN 1).
Iteration: 1000 / 1000 [100%]  (Sampling)
Elapsed Time: 0.026 seconds (Warm-up)
              0.027 seconds (Sampling)
              0.053 seconds (Total)

SAMPLING FOR MODEL 'schools_code' NOW (CHAIN 2).
Iteration: 1000 / 1000 [100%]  (Sampling)
Elapsed Time: 0.024 seconds (Warm-up)
              0.018 seconds (Sampling)
              0.042 seconds (Total)

SAMPLING FOR MODEL 'schools_code' NOW (CHAIN 3).
Iteration: 1000 / 1000 [100%]  (Sampling)
Elapsed Time: 0.027 seconds (Warm-up)
              0.018 seconds (Sampling)
              0.045 seconds (Total)

SAMPLING FOR MODEL 'schools_code' NOW (CHAIN 4).
Iteration: 1000 / 1000 [100%]  (Sampling)
Elapsed Time: 0.031 seconds (Warm-up)
              0.027 seconds (Sampling)
              0.058 seconds (Total)

for the 'fast' compile and

mode debug with DDEBUG for compiling C++ code is set

TRANSLATING MODEL 'schools_code' FROM Stan CODE TO C++ CODE NOW.
COMPILING THE C++ CODE FOR MODEL 'schools_code' NOW.
...
Error in compileCode(f, code, language = language, verbose = verbose) : 
  Compilation ERROR, function(s)/method(s) not created! cygwin warning:
  MS-DOS style path detected: C:/PROGRA~1/R/R-30~1.2/etc/x64/Makeconf
  Preferred POSIX equivalent is: /cygdrive/c/PROGRA~1/R/R-30~1.2/etc/x64/Makeconf
  CYGWIN environment variable option "nodosfilewarning" turns off this warning.
  Consult the user's guide for more details about POSIX paths:
    http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
C:/Users/JonathanGilligan/Documents/R/win-library/3.0/rstan/include//stansrc/stan/agrad/rev/var_stack.hpp:49:17: warning: 'void stan::agrad::free_memory()' defined but not used [-Wunused-function]
C:/Users/JonathanGilligan/Documents/R/win-library/3.0/rstan/include//stansrc/stan/agrad/rev/chainable.hpp:87:17: warning: 'void stan::agrad::set_zero_all_adjoints()' defined but not used [-Wunused-function]
c:/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/bin/as.exe: file1c9814344f2e.o: too many sections (37382)
C:\Users\JONA
In addition: Warning message:
running command 'C:/PROGRA~1/R/R-30~1.2/bin/x64/R CMD SHLIB file1c9814344f2e.cpp 2> file1c9814344f2e.cpp.err.txt' had status 1 

for the 'debug' compile (the "..." is omitting a 500+ line dump of the C++ code)

My G++ is from the latest RTools ("GCC 4.6.3 20111208 (prerelease) (GCC)")

My R sessionInfo is

> sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] rstan_2.1.0   Rcpp_0.10.6   inline_0.3.13

loaded via a namespace (and not attached):
[1] codetools_0.2-8 stats4_3.0.2    tools_3.0.2    
> 

For what it's worth, I'm working on 64-bit windows 7 Professional, 16 GB RAM, 86 GB free disk space. I have several similarly configured computers and see this problem with 100% reproducibility on all of them.

syclik commented 10 years ago

I think it's in the manual somewhere, but in Windows, we can't compile Stan models with the "-g" flag using the compiler provided by Rtools. That flag gets set when using debug mode. On Feb 8, 2014 12:47 PM, "jonathan-g" notifications@github.com wrote:

This is not related to the problems with the new (11.0) release of Rcpp, but I g++ won't compile stan models under the old (10.6) Rcpp.

Testing using the 8 schools model:

library(rstan) set_cppo("fast")

schools_code <- ' data { int J; // number of schools real y[J]; // estimated treatment effects real sigma[J]; // s.e. of effect estimates } parameters { real mu; real tau; real eta[J]; } transformed parameters { real theta[J]; for (j in 1:J) theta[j] <- mu + tau * eta[j]; } model { eta ~ normal(0, 1); y ~ normal(theta, sigma); } '

schools_dat <- list(J = 8, y = c(28, 8, -3, 7, -1, 1, 18, 12), sigma = c(15, 10, 16, 11, 9, 11, 10, 18))

fit <- stan(model_code = schools_code, data = schools_dat, iter = 1000, chains = 4)

set_cppo("debug") fit <- stan(model_code = schools_code, data = schools_dat, iter = 1000, chains = 4)

produces output

TRANSLATING MODEL 'schools_code' FROM Stan CODE TO C++ CODE NOW. COMPILING THE C++ CODE FOR MODEL 'schools_code' NOW. cygwin warning: MS-DOS style path detected: C:/PROGRA~1/R/R-30~1.2/etc/x64/Makeconf Preferred POSIX equivalent is: /cygdrive/c/PROGRA~1/R/R-30~1.2/etc/x64/Makeconf CYGWIN environment variable option "nodosfilewarning" turns off this warning. Consult the user's guide for more details about POSIX paths: http://cygwin.com/cygwin-ug-net/using.html#using-pathnames C:/Users/JonathanGilligan/Documents/R/win-library/3.0/rstan/include//stansrc/stan/agrad/rev/var_stack.hpp:49:17: warning: 'void stan::agrad::free_memory()' defined but not used [-Wunused-function] C:/Users/JonathanGilligan/Documents/R/win-library/3.0/rstan/include//stansrc/stan/agrad/rev/chainable.hpp:87:17: warning: 'void stan::agrad::set_zero_all_adjoints()' defined but not used [-Wunused-function] SAMPLING FOR MODEL 'schools_code' NOW (CHAIN 1). Iteration: 1000 / 1000 100% Elapsed Time: 0.026 seconds (Warm-up) 0.027 seconds (Sampling) 0.053 seconds (Total)

SAMPLING FOR MODEL 'schools_code' NOW (CHAIN 2). Iteration: 1000 / 1000 100% Elapsed Time: 0.024 seconds (Warm-up) 0.018 seconds (Sampling) 0.042 seconds (Total)

SAMPLING FOR MODEL 'schools_code' NOW (CHAIN 3). Iteration: 1000 / 1000 100% Elapsed Time: 0.027 seconds (Warm-up) 0.018 seconds (Sampling) 0.045 seconds (Total)

SAMPLING FOR MODEL 'schools_code' NOW (CHAIN 4). Iteration: 1000 / 1000 100% Elapsed Time: 0.031 seconds (Warm-up) 0.027 seconds (Sampling) 0.058 seconds (Total)

for the 'fast' compile and

mode debug with DDEBUG for compiling C++ code is set

TRANSLATING MODEL 'schools_code' FROM Stan CODE TO C++ CODE NOW. COMPILING THE C++ CODE FOR MODEL 'schools_code' NOW. ... Error in compileCode(f, code, language = language, verbose = verbose) : Compilation ERROR, function(s)/method(s) not created! cygwin warning: MS-DOS style path detected: C:/PROGRA~1/R/R-30~1.2/etc/x64/Makeconf Preferred POSIX equivalent is: /cygdrive/c/PROGRA~1/R/R-30~1.2/etc/x64/Makeconf CYGWIN environment variable option "nodosfilewarning" turns off this warning. Consult the user's guide for more details about POSIX paths: http://cygwin.com/cygwin-ug-net/using.html#using-pathnames C:/Users/JonathanGilligan/Documents/R/win-library/3.0/rstan/include//stansrc/stan/agrad/rev/var_stack.hpp:49:17: warning: 'void stan::agrad::free_memory()' defined but not used [-Wunused-function] C:/Users/JonathanGilligan/Documents/R/win-library/3.0/rstan/include//stansrc/stan/agrad/rev/chainable.hpp:87:17: warning: 'void stan::agrad::set_zero_all_adjoints()' defined but not used [-Wunused-function] c:/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/bin/as.exe: file1c9814344f2e.o: too many sections (37382) C:\Users\JONA In addition: Warning message: running command 'C:/PROGRA~1/R/R-30~1.2/bin/x64/R CMD SHLIB file1c9814344f2e.cpp 2> file1c9814344f2e.cpp.err.txt' had status 1

for the 'debug' compile (the "..." is omitting a 500+ line dump of the C++ code)

My G++ is from the latest RTools ("GCC 4.6.3 20111208 (prerelease) (GCC)")

My R sessionInfo is

sessionInfo() R version 3.0.2 (2013-09-25) Platform: x86_64-w64-mingw32/x64 (64-bit)

locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C [5] LC_TIME=English_United States.1252

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] rstan_2.1.0 Rcpp_0.10.6 inline_0.3.13

loaded via a namespace (and not attached): [1] codetools_0.2-8 stats4_3.0.2 tools_3.0.2

For what it's worth, I'm working on 64-bit windows 7 Professional, 16 GB RAM, 86 GB free disk space. I have several similarly configured computers and see this problem with 100% reproducibility on all of them.

Reply to this email directly or view it on GitHubhttps://github.com/stan-dev/rstan/issues/46 .