Running rstan on grid engine causing compiling error

I am trying to run rstan on a grid engine to parallelize multiple scenarios that use the same stan file but with different data inputs.

i keep getting this error that i cant understand what it is the cause for the error.

Loading required package: bindrcpp
Loading required package: rstan
Loading required package: ggplot2
Loading required package: StanHeaders
rstan (Version 2.16.2, packaged: 2017-07-03 09:24:58 UTC, GitRev: 2e1f913d3ca3)
For execution on a local, multicore CPU with excess RAM we recommend calling
rstan_options(auto_write = TRUE)
options(mc.cores = parallel::detectCores())
Loading required package: rlecuyer
Error in compileCode(f, code, language = language, verbose = verbose) : 
  Compilation ERROR, function(s)/method(s) not created! In file included from /data/co/CSL0301/script/lib/rstan/include/rstan/rstaninc.hpp:3:0,
                 from file3f614e46f472.cpp:622:
/data/co/CSL0301/script/lib/rstan/include/rstan/stan_fit.hpp: In function ‘int rstan::{anonymous}::command(rstan::stan_args&, Model&, Rcpp::List&, const std::vector<long unsigned int>&, const std::vector<std::basic_string<char> >&, RNG_t&)’:
/data/co/CSL0301/script/lib/rstan/include/rstan/stan_fit.hpp:438:8: warning: ‘template<class> class std::auto_ptr’ is deprecated [-Wdeprecated-declarations]
   std::auto_ptr<stan::io::var_context> init_context_ptr;
        ^~~~~~~~
In file included from /usr/include/c++/6/bits/locale_conv.h:41:0,
                 from /usr/include/c++/6/locale:43,
                 from /data/co/CSL0301/script/lib/BH/include/boost/lexical_cast/detail/converter_lexical_streams.hpp:43,
                 from /data/co/CSL0301/script/lib/BH/include/boost/lexical_cast
Calls: FUN ... stan_model -> cxxfunctionplus -> cxxfunction -> compileCode
In addition: Warning message:
running command '/usr/lib/R/bin/R CMD SHLIB file3f614e46f472.cpp 2> file3f614e46f472.cpp.err.txt' had status 1 
Execution halted
R version 3.3.3 (2017-03-06)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.5 LTS

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
[1] bindrcpp_0.2         rstan_2.16.2         StanHeaders_2.16.0-1 ggplot2_2.2.1       

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.12       plyr_1.8.4         bindr_0.1          viridis_0.4.0      digest_0.6.12      viridisLite_0.2.0  jsonlite_1.5       tibble_1.3.3       gtable_0.2.0      
[10] lattice_0.20-34    pkgconfig_2.0.1    texPreview_1.0.0   rlang_0.1.1        rstudioapi_0.6     qapply_1.38        magick_0.4         parallel_3.3.3     mvtnorm_1.0-6     
[19] gridExtra_2.2.1    dplyr_0.7.2        httr_1.2.1         xml2_1.1.1         stats4_3.3.3       grid_3.3.3         glue_1.1.1         inline_0.3.14      R6_2.2.2          
[28] svgPanZoom_0.3.3   tidyr_0.6.3        slackr_1.4.3       magrittr_1.5       scales_0.4.1       assertthat_0.2.0   xtable_1.8-2       colorspace_1.3-2   labeling_0.3      
[37] DoseFinding_0.9-15 lazyeval_0.2.0     munsell_0.4.3  

Do you have -Werror in CXXFLAGS somewhere (either in the sitewide Makevars file or in ~/.R/Makevars)? I am not seeing an error message just a harmless warning about deprecated stuff and then compilation stops.

Are you using the same singular Stan file for your different scenarios? I don’t think that will run correctly – you may need to have separate Stan files for each scenario.

I was running something where I used the same Stan model but for 100 different datasets. I had to end up creating 100 identical Stan files (renamed, of course) for each dataset evaluation in order for it to run. I was also using a grid engine for this as well.

Hope that is helpful!

yeah. ive tried that too but w no success.

td <- file.path(tempdir(),'stantemp')
  
  dir.create(td,recursive = TRUE)
  
  thisfile <- sprintf('thismodel%s.stan',gsub('[.]','_',as.character(runif(1))))
  
  file.copy(system.file(paste0('stan_models/',endpoint, "SigmoidEmax.stan"),package = 'CSL0301'),
            file.path(td,thisfile)
            )
  
  stan.args <- list(file=file.path(td,thisfile),
                     data=data, init=init , pars = parameters, chains = nChains, iter = nIter, warmup = nBurnin,
                     control = list(adapt_delta = 0.9), thin=nThin,cores=1)
  
  
  fit <- do.call('stan',stan.args)

I get same error with simple toy model

f <- function(i,mod) {
  rstan::stan(model_code = mod)
}

model_code='
data {
}
parameters {
  real y;
}
model {
  y ~ normal(0, 1);
}'


x2 <-qapply::qapply(X = 1:30,
                    FUN = f,
                    fargs = list(mod=model_code),
                    nCores = 10,
                    workDir = 'qapply',
                    tag = 'teststan',
                    clearWd=FALSE)

That should not be necessary if you have saved the compiled model to the disk by first invoking rstan_options(auto_write = TRUE) and compiling it once.

I think you either are running out of RAM or you have -Werror in your configuration flags somewhere. Just using a deprecated part of Boost should not cause the compilation to stop. When there is a bona fide compilation error it says error: somewhere with a cryptic message following that.

starting worker pid=106375 on localhost:11291 at 18:23:51.061
In file included from /usr/lib/R/library/RcppEigen/include/Eigen/Core:276:0,
                 from /usr/lib/R/library/RcppEigen/include/Eigen/Dense:1,
                 from /usr/lib/R/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:4,
                 from /usr/lib/R/library/StanHeaders/include/stan/math/rev/mat/fun/Eigen_NumTraits.hpp:4,
                 from /usr/lib/R/library/StanHeaders/include/stan/math/rev/core/matrix_vari.hpp:4,
                 from /usr/lib/R/library/StanHeaders/include/stan/math/rev/core.hpp:14,
                 from /usr/lib/R/library/StanHeaders/include/stan/math/rev/mat.hpp:4,
                 from /usr/lib/R/library/StanHeaders/include/stan/math.hpp:4,
                 from /usr/lib/R/library/StanHeaders/include/src/stan/model/model_header.hpp:4,
                 from file19f05392900cc.cpp:8:
/usr/lib/R/library/RcppEigen/include/Eigen/src/Core/Functors.h:973:28: error: ‘template<class _Operation> class std::binder2nd’ is deprecated [-Werror=deprecated-declarations]
 struct functor_traits<std::binder2nd<T> >
                            ^~~~~~~~~
In file included from /usr/include/c++/6/bits/stl_function.h:1127:0,
                 from /usr/include/c++/6/string:48,
                 from /usr/include/c++/6/bits/locale_classes.h:40,
                 from /usr/include/c++/6/bits/ios_base.h:41,
                 from /usr/include/c++/6/ios:42,
                 from /usr/include/c++/6/istream:38,
                 from /usr/include/c++/6/sstream:38,
                 from /usr/lib/R/library/StanHeaders/include/stan/math/memory/stack_alloc.hpp:10,
                 from /usr/lib/R/library/StanHeaders/include/stan/math/rev/core/autodiffstackstorage.hpp:4,
                 from /usr/lib/R/library/StanHeaders/include/stan/math/rev/core.hpp:4,
                 from /usr/lib/R/library/StanHeaders/include/stan/math/rev/mat.hpp:4,
                 from /usr/lib/R/library/StanHeaders/include/stan/math.hpp:4,
                 from /usr/lib/R/library/StanHeaders/include/src/stan/model/model_header.hpp:4,
                 from file19f05392900cc.cpp:8:
/usr/include/c++/6/backward/binders.h:143:11: note: declared here
     class binder2nd
           ^~~~~~~~~
In file included from /usr/lib/R/library/RcppEigen/include/Eigen/Core:276:0,
                 from /usr/lib/R/library/RcppEigen/include/Eigen/Dense:1,
                 from /usr/lib/R/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:4,
                 from /usr/lib/R/library/StanHeaders/include/stan/math/rev/mat/fun/Eigen_NumTraits.hpp:4,
                 from /usr/lib/R/library/StanHeaders/include/stan/math/rev/core/matrix_vari.hpp:4,
                 from /usr/lib/R/library/StanHeaders/include/stan/math/rev/core.hpp:14,
                 from /usr/lib/R/library/StanHeaders/include/stan/math/rev/mat.hpp:4,
                 from /usr/lib/R/library/StanHeaders/include/stan/math.hpp:4,
                 from /usr/lib/R/library/StanHeaders/include/src/stan/model/model_header.hpp:4,
                 from file19f05392900cc.cpp:8:
/usr/lib/R/library/RcppEigen/include/Eigen/src/Core/Functors.h:977:28: error: ‘template<class _Operation> class std::binder1st’ is deprecated [-Werror=deprecated-declarations]
 struct functor_traits<std::binder1st<T> >
                            ^~~~~~~~~
In file included from /usr/include/c++/6/bits/stl_function.h:1127:0,
                 from /usr/include/c++/6/string:48,
                 from /usr/include/c++/6/bits/locale_classes.h:40,
                 from /usr/include/c++/6/bits/ios_base.h:41,
                 from /usr/include/c++/6/ios:42,
                 from /usr/include/c++/6/istream:38,
                 from /usr/include/c++/6/sstream:38,
                 from /usr/lib/R/library/StanHeaders/include/stan/math/memory/stack_alloc.hpp:10,
                 from /usr/lib/R/library/StanHeaders/include/stan/math/rev/core/autodiffstackstorage.hpp:4,
                 from /usr/lib/R/library/StanHeaders/include/stan/math/rev/core.hpp:4,
                 from /usr/lib/R/library/StanHeaders/include/stan/math/rev/mat.hpp:4,
                 from /usr/lib/R/library/StanHeaders/include/stan/math.hpp:4,
                 from /usr/lib/R/library/StanHeaders/include/src/stan/model/model_header.hpp:4,
                 from file19f05392900cc.cpp:8:
/usr/include/c++/6/backward/binders.h:108:11: note: declared here
     class binder1st
           ^~~~~~~~~
cc1plus: all warnings being treated as errors
make: *** [file19f05392900cc.o] Error 1

ERROR(s) during compilation: source code errors or compiler configuration errors!

Program source:
  1: 
  2: // includes from the plugin
  3: 
  4: 
  5: // user includes
  6: #define STAN__SERVICES__COMMAND_HPP// Code generated by Stan version 2.14
  7: 
  8: #include <stan/model/model_header.hpp>
  9: 
 10: namespace model19f053892e3a2_851b263221b353f53f6e5ee203c5b150_namespace {
 11: 
 12: using std::istream;
 13: using std::string;
 14: using std::stringstream;
 15: using std::vector;
 16: using stan::io::dump;
 17: using stan::math::lgamma;
 18: using stan::model::prob_grad;
 19: using namespace stan::math;
 20: 
 21: typedef Eigen::Matrix<double,Eigen::Dynamic,1> vector_d;
 22: typedef Eigen::Matrix<double,1,Eigen::Dynamic> row_vector_d;
 23: typedef Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic> matrix_d;
 24: 
 25: static int current_statement_begin__;
 26: 
 27: class model19f053892e3a2_851b263221b353f53f6e5ee203c5b150 : public prob_grad {
 28: private:
 29: public:
 30:     model19f053892e3a2_851b263221b353f53f6e5ee203c5b150(stan::io::var_context& context__,
 31:         std::ostream* pstream__ = 0)
 32:         : prob_grad(0) {
 33:         typedef boost::ecuyer1988 rng_t;
 34:         rng_t base_rng(0);  // 0 seed default
 35:         ctor_body(context__, base_rng, pstream__);
 36:     }
 37: 
 38:     template <class RNG>
 39:     model19f053892e3a2_851b263221b353f53f6e5ee203c5b150(stan::io::var_context& context__,
 40:         RNG& base_rng__,
 41:         std::ostream* pstream__ = 0)
 42:         : prob_grad(0) {
 43:         ctor_body(context__, base_rng__, pstream__);
 44:     }
 45: 
 46:     template <class RNG>
 47:     void ctor_body(stan::io::var_context& context__,
 48:                    RNG& base_rng__,
 49:                    std::ostream* pstream__) {
 50:         current_statement_begin__ = -1;
 51: 
 52:         static const char* function__ = "model19f053892e3a2_851b263221b353f53f6e5ee203c5b150_namespace::model19f053892e3a2_851b263221b353f53f6e5ee203c5b150";
 53:         (void) function__; // dummy call to supress warning
 54:         size_t pos__;
 55:         (void) pos__; // dummy call to supress warning
 56:         std::vector<int> vals_i__;
 57:         std::vector<double> vals_r__;
 58:         double DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
 59:         (void) DUMMY_VAR__;  // suppress unused var warning
 60: 
 61:         // initialize member variables
 62: 
 63:         // validate, data variables
 64:         // initialize data variables
 65: 
 66:         try {
 67:         } catch (const std::exception& e) {
 68:             stan::lang::rethrow_located(e,current_statement_begin__);
 69:             // Next line prevents compiler griping about no return
 70:             throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
 71:         }
 72: 
 73:         // validate transformed data
 74: 
 75:         // set parameter ranges
 76:         num_params_r__ = 0U;
 77:         param_ranges_i__.clear();
 78:         ++num_params_r__;
 79:     }
 80: 
 81:     ~model19f053892e3a2_851b263221b353f53f6e5ee203c5b150() { }
 82: 
 83: 
 84:     void transform_inits(const stan::io::var_context& context__,
 85:                          std::vector<int>& params_i__,
 86:                          std::vector<double>& params_r__,
 87:                          std::ostream* pstream__) const {
 88:         stan::io::writer<double> writer__(params_r__,params_i__);
 89:         size_t pos__;
 90:         (void) pos__; // dummy call to supress warning
 91:         std::vector<double> vals_r__;
 92:         std::vector<int> vals_i__;
 93: 
 94:         if (!(context__.contains_r("y")))
 95:             throw std::runtime_error("variable y missing");
 96:         vals_r__ = context__.vals_r("y");
 97:         pos__ = 0U;
 98:         context__.validate_dims("initialization", "y", "double", context__.to_vec());
 99:         // generate_declaration y
100:         double y(0);
101:         y = vals_r__[pos__++];
102:         try {
103:             writer__.scalar_unconstrain(y);
104:         } catch (const std::exception& e) { 
105:             throw std::runtime_error(std::string("Error transforming variable y: ") + e.what());
106:         }
107: 
108:         params_r__ = writer__.data_r();
109:         params_i__ = writer__.data_i();
110:     }
111: 
112:     void transform_inits(const stan::io::var_context& context,
113:                          Eigen::Matrix<double,Eigen::Dynamic,1>& params_r,
114:                          std::ostream* pstream__) const {
115:       std::vector<double> params_r_vec;
116:       std::vector<int> params_i_vec;
117:       transform_inits(context, params_i_vec, params_r_vec, pstream__);
118:       params_r.resize(params_r_vec.size());
119:       for (int i = 0; i < params_r.size(); ++i)
120:         params_r(i) = params_r_vec[i];
121:     }
122: 
123: 
124:     template <bool propto__, bool jacobian__, typename T__>
125:     T__ log_prob(vector<T__>& params_r__,
126:                  vector<int>& params_i__,
127:                  std::ostream* pstream__ = 0) const {
128: 
129:         T__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
130:         (void) DUMMY_VAR__;  // suppress unused var warning
131: 
132:         T__ lp__(0.0);
133:         stan::math::accumulator<T__> lp_accum__;
134: 
135:         // model parameters
136:         stan::io::reader<T__> in__(params_r__,params_i__);
137: 
138:         T__ y;
139:         (void) y;  // dummy to suppress unused var warning
140:         if (jacobian__)
141:             y = in__.scalar_constrain(lp__);
142:         else
143:             y = in__.scalar_constrain();
144: 
145: 
146:         // transformed parameters
147: 
148: 
149:         try {
150:         } catch (const std::exception& e) {
151:             stan::lang::rethrow_located(e,current_statement_begin__);
152:             // Next line prevents compiler griping about no return
153:             throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
154:         }
155: 
156:         // validate transformed parameters
157: 
158:         const char* function__ = "validate transformed params";
159:         (void) function__;  // dummy to suppress unused var warning
160: 
161:         // model body
162:         try {
163: 
164:             current_statement_begin__ = 8;
165:             lp_accum__.add(normal_log<propto__>(y, 0, 1));
166:         } catch (const std::exception& e) {
167:             stan::lang::rethrow_located(e,current_statement_begin__);
168:             // Next line prevents compiler griping about no return
169:             throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
170:         }
171: 
172:         lp_accum__.add(lp__);
173:         return lp_accum__.sum();
174: 
175:     } // log_prob()
176: 
177:     template <bool propto, bool jacobian, typename T_>
178:     T_ log_prob(Eigen::Matrix<T_,Eigen::Dynamic,1>& params_r,
179:                std::ostream* pstream = 0) const {
180:       std::vector<T_> vec_params_r;
181:       vec_params_r.reserve(params_r.size());
182:       for (int i = 0; i < params_r.size(); ++i)
183:         vec_params_r.push_back(params_r(i));
184:       std::vector<int> vec_params_i;
185:       return log_prob<propto,jacobian,T_>(vec_params_r, vec_params_i, pstream);
186:     }
187: 
188: 
189:     void get_param_names(std::vector<std::string>& names__) const {
190:         names__.resize(0);
191:         names__.push_back("y");
192:     }
193: 
194: 
195:     void get_dims(std::vector<std::vector<size_t> >& dimss__) const {
196:         dimss__.resize(0);
197:         std::vector<size_t> dims__;
198:         dims__.resize(0);
199:         dimss__.push_back(dims__);
200:     }
201: 
202:     template <typename RNG>
203:     void write_array(RNG& base_rng__,
204:                      std::vector<double>& params_r__,
205:                      std::vector<int>& params_i__,
206:                      std::vector<double>& vars__,
207:                      bool include_tparams__ = true,
208:                      bool include_gqs__ = true,
209:                      std::ostream* pstream__ = 0) const {
210:         vars__.resize(0);
211:         stan::io::reader<double> in__(params_r__,params_i__);
212:         static const char* function__ = "model19f053892e3a2_851b263221b353f53f6e5ee203c5b150_namespace::write_array";
213:         (void) function__; // dummy call to supress warning
214:         // read-transform, write parameters
215:         double y = in__.scalar_constrain();
216:         vars__.push_back(y);
217: 
218:         if (!include_tparams__) return;
219:         // declare and define transformed parameters
220:         double lp__ = 0.0;
221:         (void) lp__; // dummy call to supress warning
222:         stan::math::accumulator<double> lp_accum__;
223: 
224:         double DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
225:         (void) DUMMY_VAR__;  // suppress unused var warning
226: 
227: 
228: 
229:         try {
230:         } catch (const std::exception& e) {
231:             stan::lang::rethrow_located(e,current_statement_begin__);
232:             // Next line prevents compiler griping about no return
233:             throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
234:         }
235: 
236:         // validate transformed parameters
237: 
238:         // write transformed parameters
239: 
240:         if (!include_gqs__) return;
241:         // declare and define generated quantities
242: 
243: 
244:         try {
245:         } catch (const std::exception& e) {
246:             stan::lang::rethrow_located(e,current_statement_begin__);
247:             // Next line prevents compiler griping about no return
248:             throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
249:         }
250: 
251:         // validate generated quantities
252: 
253:         // write generated quantities
254:     }
255: 
256:     template <typename RNG>
257:     void write_array(RNG& base_rng,
258:                      Eigen::Matrix<double,Eigen::Dynamic,1>& params_r,
259:                      Eigen::Matrix<double,Eigen::Dynamic,1>& vars,
260:                      bool include_tparams = true,
261:                      bool include_gqs = true,
262:                      std::ostream* pstream = 0) const {
263:       std::vector<double> params_r_vec(params_r.size());
264:       for (int i = 0; i < params_r.size(); ++i)
265:         params_r_vec[i] = params_r(i);
266:       std::vector<double> vars_vec;
267:       std::vector<int> params_i_vec;
268:       write_array(base_rng,params_r_vec,params_i_vec,vars_vec,include_tparams,include_gqs,pstream);
269:       vars.resize(vars_vec.size());
270:       for (int i = 0; i < vars.size(); ++i)
271:         vars(i) = vars_vec[i];
272:     }
273: 
274:     static std::string model_name() {
275:         return "model19f053892e3a2_851b263221b353f53f6e5ee203c5b150";
276:     }
277: 
278: 
279:     void constrained_param_names(std::vector<std::string>& param_names__,
280:                                  bool include_tparams__ = true,
281:                                  bool include_gqs__ = true) const {
282:         std::stringstream param_name_stream__;
283:         param_name_stream__.str(std::string());
284:         param_name_stream__ << "y";
285:         param_names__.push_back(param_name_stream__.str());
286: 
287:         if (!include_gqs__ && !include_tparams__) return;
288: 
289:         if (!include_gqs__) return;
290:     }
291: 
292: 
293:     void unconstrained_param_names(std::vector<std::string>& param_names__,
294:                                    bool include_tparams__ = true,
295:                                    bool include_gqs__ = true) const {
296:         std::stringstream param_name_stream__;
297:         param_name_stream__.str(std::string());
298:         param_name_stream__ << "y";
299:         param_names__.push_back(param_name_stream__.str());
300: 
301:         if (!include_gqs__ && !include_tparams__) return;
302: 
303:         if (!include_gqs__) return;
304:     }
305: 
306: }; // model
307: 
308: } // namespace
309: 
310: typedef model19f053892e3a2_851b263221b353f53f6e5ee203c5b150_namespace::model19f053892e3a2_851b263221b353f53f6e5ee203c5b150 stan_model;
311: 
312: #include <rstan/rstaninc.hpp>
313: /**
314:  * Define Rcpp Module to expose stan_fit's functions to R.
315:  */
316: RCPP_MODULE(stan_fit4model19f053892e3a2_851b263221b353f53f6e5ee203c5b150_mod){
317:   Rcpp::class_<rstan::stan_fit<model19f053892e3a2_851b263221b353f53f6e5ee203c5b150_namespace::model19f053892e3a2_851b263221b353f53f6e5ee203c5b150,
318:                boost::random::ecuyer1988> >("stan_fit4model19f053892e3a2_851b263221b353f53f6e5ee203c5b150")
319:     // .constructor<Rcpp::List>()
320:     .constructor<SEXP, SEXP>()
321:     // .constructor<SEXP, SEXP>()
322:     .method("call_sampler",
323:             &rstan::stan_fit<model19f053892e3a2_851b263221b353f53f6e5ee203c5b150_namespace::model19f053892e3a2_851b263221b353f53f6e5ee203c5b150, boost::random::ecuyer1988>::call_sampler)
324:     .method("param_names",
325:             &rstan::stan_fit<model19f053892e3a2_851b263221b353f53f6e5ee203c5b150_namespace::model19f053892e3a2_851b263221b353f53f6e5ee203c5b150, boost::random::ecuyer1988>::param_names)
326:     .method("param_names_oi",
327:             &rstan::stan_fit<model19f053892e3a2_851b263221b353f53f6e5ee203c5b150_namespace::model19f053892e3a2_851b263221b353f53f6e5ee203c5b150, boost::random::ecuyer1988>::param_names_oi)
328:     .method("param_fnames_oi",
329:             &rstan::stan_fit<model19f053892e3a2_851b263221b353f53f6e5ee203c5b150_namespace::model19f053892e3a2_851b263221b353f53f6e5ee203c5b150, boost::random::ecuyer1988>::param_fnames_oi)
330:     .method("param_dims",
331:             &rstan::stan_fit<model19f053892e3a2_851b263221b353f53f6e5ee203c5b150_namespace::model19f053892e3a2_851b263221b353f53f6e5ee203c5b150, boost::random::ecuyer1988>::param_dims)
332:     .method("param_dims_oi",
333:             &rstan::stan_fit<model19f053892e3a2_851b263221b353f53f6e5ee203c5b150_namespace::model19f053892e3a2_851b263221b353f53f6e5ee203c5b150, boost::random::ecuyer1988>::param_dims_oi)
334:     .method("update_param_oi",
335:             &rstan::stan_fit<model19f053892e3a2_851b263221b353f53f6e5ee203c5b150_namespace::model19f053892e3a2_851b263221b353f53f6e5ee203c5b150, boost::random::ecuyer1988>::update_param_oi)
336:     .method("param_oi_tidx",
337:             &rstan::stan_fit<model19f053892e3a2_851b263221b353f53f6e5ee203c5b150_namespace::model19f053892e3a2_851b263221b353f53f6e5ee203c5b150, boost::random::ecuyer1988>::param_oi_tidx)
338:     .method("grad_log_prob",
339:             &rstan::stan_fit<model19f053892e3a2_851b263221b353f53f6e5ee203c5b150_namespace::model19f053892e3a2_851b263221b353f53f6e5ee203c5b150, boost::random::ecuyer1988>::grad_log_prob)
340:     .method("log_prob",
341:             &rstan::stan_fit<model19f053892e3a2_851b263221b353f53f6e5ee203c5b150_namespace::model19f053892e3a2_851b263221b353f53f6e5ee203c5b150, boost::random::ecuyer1988>::log_prob)
342:     .method("unconstrain_pars",
343:             &rstan::stan_fit<model19f053892e3a2_851b263221b353f53f6e5ee203c5b150_namespace::model19f053892e3a2_851b263221b353f53f6e5ee203c5b150, boost::random::ecuyer1988>::unconstrain_pars)
344:     .method("constrain_pars",
345:             &rstan::stan_fit<model19f053892e3a2_851b263221b353f53f6e5ee203c5b150_namespace::model19f053892e3a2_851b263221b353f53f6e5ee203c5b150, boost::random::ecuyer1988>::constrain_pars)
346:     .method("num_pars_unconstrained",
347:             &rstan::stan_fit<model19f053892e3a2_851b263221b353f53f6e5ee203c5b150_namespace::model19f053892e3a2_851b263221b353f53f6e5ee203c5b150, boost::random::ecuyer1988>::num_pars_unconstrained)
348:     .method("unconstrained_param_names",
349:             &rstan::stan_fit<model19f053892e3a2_851b263221b353f53f6e5ee203c5b150_namespace::model19f053892e3a2_851b263221b353f53f6e5ee203c5b150, boost::random::ecuyer1988>::unconstrained_param_names)
350:     .method("constrained_param_names",
351:             &rstan::stan_fit<model19f053892e3a2_851b263221b353f53f6e5ee203c5b150_namespace::model19f053892e3a2_851b263221b353f53f6e5ee203c5b150, boost::random::ecuyer1988>::constrained_param_names)
352:     ;
353: }
354: 
355: // declarations
356: extern "C" {
357: SEXP file19f05392900cc( ) ;
358: }
359: 
360: // definition
361: 
362: SEXP file19f05392900cc(  ){
363:  return Rcpp::wrap("851b263221b353f53f6e5ee203c5b150");
364: }
365: 
366: 
Error in compileCode(f, code, language = language, verbose = verbose) : 
  Compilation ERROR, function(s)/method(s) not created! In file included from /usr/lib/R/library/RcppEigen/include/Eigen/Core:276:0,
                 from /usr/lib/R/library/RcppEigen/include/Eigen/Dense:1,
                 from /usr/lib/R/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:4,
                 from /usr/lib/R/library/StanHeaders/include/stan/math/rev/mat/fun/Eigen_NumTraits.hpp:4,
                 from /usr/lib/R/library/StanHeaders/include/stan/math/rev/core/matrix_vari.hpp:4,
                 from /usr/lib/R/library/StanHeaders/include/stan/math/rev/core.hpp:14,
                 from /usr/lib/R/library/StanHeaders/include/stan/math/rev/mat.hpp:4,
                 from /usr/lib/R/library/StanHeaders/include/stan/math.hpp:4,
                 from /usr/lib/R/library/StanHeaders/include/src/stan/model/model_header.hpp:4,
                 from file19f05392900cc.cpp:8:
/usr/lib/R/library/RcppEigen/include/Eigen/src/Core/Functors.h:973:28: error: ‘templat
In addition: Warning message:
running command '/usr/lib/R/bin/R CMD SHLIB file19f05392900cc.cpp 2> file19f05392900cc.cpp.err.txt' had status 1 

like this?
/usr/lib/R/library/RcppEigen/include/Eigen/src/Core/Functors.h:977:28: error: ‘template<class _Operation> class std::binder1st’ is deprecated [-Werror=deprecated-declarations]?

Yes, you need to get -Werror out of your configuration.

and putting in the Makevars CXXFLAGS= -Werror will do that?

No, removing -Werror from CXXFLAGS in Makevars will do that.

> rstan::stan(model_code = model_code)
In file included from /data/co/CSL0301/script/lib/rstan/include/rstan/rstaninc.hpp:3:0,
                 from file76f20b5be95.cpp:319:
/data/co/CSL0301/script/lib/rstan/include/rstan/stan_fit.hpp: In function ‘int rstan::{anonymous}::command(rstan::stan_args&, Model&, Rcpp::List&, const std::vector<long unsigned int>&, const std::vector<std::basic_string<char> >&, RNG_t&)’:
/data/co/CSL0301/script/lib/rstan/include/rstan/stan_fit.hpp:438:8: warning: ‘template<class> class std::auto_ptr’ is deprecated [-Wdeprecated-declarations]
   std::auto_ptr<stan::io::var_context> init_context_ptr;
        ^~~~~~~~
In file included from /usr/include/c++/6/bits/locale_conv.h:41:0,
                 from /usr/include/c++/6/locale:43,
                 from /data/co/CSL0301/script/lib/BH/include/boost/lexical_cast/detail/converter_lexical_streams.hpp:43,
                 from /data/co/CSL0301/script/lib/BH/include/boost/lexical_cast/detail/converter_lexical.hpp:54,
                 from /data/co/CSL0301/script/lib/BH/include/boost/lexical_cast/try_lexical_convert.hpp:42,
                 from /data/co/CSL0301/script/lib/BH/include/boost/lexical_cast.hpp:32,
                 from /data/co/CSL0301/script/lib/BH/include/boost/math/tools/convert_from_string.hpp:15,
                 from /data/co/CSL0301/script/lib/BH/include/boost/math/constants/constants.hpp:13,
                 from /data/co/CSL0301/script/lib/StanHeaders/include/stan/math/prim/scal/fun/constants.hpp:4,
                 from /data/co/CSL0301/script/lib/StanHeaders/include/stan/math/rev/core/operator_unary_plus.hpp:7,
                 from /data/co/CSL0301/script/lib/StanHeaders/include/stan/math/rev/core.hpp:34,
                 from /data/co/CSL0301/script/lib/StanHeaders/include/stan/math/rev/mat.hpp:4,
                 from /data/co/CSL0301/script/lib/StanHeaders/include/stan/math.hpp:4,
                 from /data/co/CSL0301/script/lib/StanHeaders/include/src/stan/model/model_header.hpp:4,
                 from file76f20b5be95.cpp:8:
/usr/include/c++/6/bits/unique_ptr.h:49:28: note: declared here
   template<typename> class auto_ptr;
                            ^~~~~~~~
In file included from /data/co/CSL0301/script/lib/rstan/include/rstan/rstaninc.hpp:3:0,
                 from file76f20b5be95.cpp:319:
/data/co/CSL0301/script/lib/rstan/include/rstan/stan_fit.hpp:547:10: warning: ‘template<class> class std::auto_ptr’ is deprecated [-Wdeprecated-declarations]
     std::auto_ptr<rstan_sample_writer> sample_writer_ptr;
          ^~~~~~~~
In file included from /usr/include/c++/6/bits/locale_conv.h:41:0,
                 from /usr/include/c++/6/locale:43,
                 from /data/co/CSL0301/script/lib/BH/include/boost/lexical_cast/detail/converter_lexical_streams.hpp:43,
                 from /data/co/CSL0301/script/lib/BH/include/boost/lexical_cast/detail/converter_lexical.hpp:54,
                 from /data/co/CSL0301/script/lib/BH/include/boost/lexical_cast/try_lexical_convert.hpp:42,
                 from /data/co/CSL0301/script/lib/BH/include/boost/lexical_cast.hpp:32,
                 from /data/co/CSL0301/script/lib/BH/include/boost/math/tools/convert_from_string.hpp:15,
                 from /data/co/CSL0301/script/lib/BH/include/boost/math/constants/constants.hpp:13,
                 from /data/co/CSL0301/script/lib/StanHeaders/include/stan/math/prim/scal/fun/constants.hpp:4,
                 from /data/co/CSL0301/script/lib/StanHeaders/include/stan/math/rev/core/operator_unary_plus.hpp:7,
                 from /data/co/CSL0301/script/lib/StanHeaders/include/stan/math/rev/core.hpp:34,
                 from /data/co/CSL0301/script/lib/StanHeaders/include/stan/math/rev/mat.hpp:4,
                 from /data/co/CSL0301/script/lib/StanHeaders/include/stan/math.hpp:4,
                 from /data/co/CSL0301/script/lib/StanHeaders/include/src/stan/model/model_header.hpp:4,
                 from file76f20b5be95.cpp:8:
/usr/include/c++/6/bits/unique_ptr.h:49:28: note: declared here
   template<typename> class auto_ptr;
                            ^~~~~~~~
Error in .Object$initialize(...) : 
  could not find function "cpp_object_initializer"
trying deprecated constructor; please alert package maintainer
Error in .Object$initialize(...) : 
  could not find function "cpp_object_initializer"
failed to create the sampler; sampling not done

should i remove -Wdeprecated-declarations?

I suspect you are calling your .R file from Rscript. In that case, you need library(Rcpp) in your .R file or you need to put --default-packages=Rcpp into the invocation of Rscript.

library(rstan)
library(Rcpp)

f <- function(i,mod) {
  rstan::stan(model_code = mod)
}

model_code='
data {
}
parameters {
  real y;
}
model {
  y ~ normal(0, 1);
}'


x2 <-qapply::qapply(X = 1:30,
                    FUN = f,
                    fargs = list(mod=model_code),
                    nCores = 10,
                    workDir = 'qapply',
                    tag = 'teststan',
                    clearWd=FALSE)
Loading required package: Rcpp
Loading required package: rstan
Loading required package: ggplot2
Loading required package: StanHeaders
rstan (Version 2.16.2, packaged: 2017-07-03 09:24:58 UTC, GitRev: 2e1f913d3ca3)
For execution on a local, multicore CPU with excess RAM we recommend calling
rstan_options(auto_write = TRUE)
options(mc.cores = parallel::detectCores())
Loading required package: rlecuyer
Error in compileCode(f, code, language = language, verbose = verbose) : 
  Compilation ERROR, function(s)/method(s) not created! In file included from /data/co/CSL0301/script/lib/rstan/include/rstan/rstaninc.hpp:3:0,
                 from file275a7dd10e58.cpp:319:
/data/co/CSL0301/script/lib/rstan/include/rstan/stan_fit.hpp: In function ‘int rstan::{anonymous}::command(rstan::stan_args&, Model&, Rcpp::List&, const std::vector<long unsigned int>&, const std::vector<std::basic_string<char> >&, RNG_t&)’:
/data/co/CSL0301/script/lib/rstan/include/rstan/stan_fit.hpp:438:8: warning: ‘template<class> class std::auto_ptr’ is deprecated [-Wdeprecated-declarations]
   std::auto_ptr<stan::io::var_context> init_context_ptr;
        ^~~~~~~~
In file included from /usr/include/c++/6/bits/locale_conv.h:41:0,
                 from /usr/include/c++/6/locale:43,
                 from /data/co/CSL0301/script/lib/BH/include/boost/lexical_cast/detail/converter_lexical_streams.hpp:43,
                 from /data/co/CSL0301/script/lib/BH/include/boost/lexical_cast
Calls: do.call ... stan_model -> cxxfunctionplus -> cxxfunction -> compileCode
In addition: Warning message:
running command '/usr/lib/R/bin/R CMD SHLIB file275a7dd10e58.cpp 2> file275a7dd10e58.cpp.err.txt' had status 1 
Execution halted

This output does not state what the error is. You may need to load Rcpp on the compute nodes.

But again, you should be able to write a .stan program on the disk, compile it once with auto_write = TRUE, and pass the (perhaps full) path to the .stan program to each compute node and they should read the compiled model off the disk.

that output was from a compute node (shows Rcpp being loaded). I’ll try loading the compiled program

i would need to copy the .h, .so created in the tempdir of the master node after compilation to the tempdir of a compute node, for rstan to pick it up?

That would only work if the different grid nodes use the same tempdir, which they ordinarily would not if they are different R processes. You can force them to with an environmental variable, which is documented in ?tempdir.