Rstan 2.26 crashes with no error when (accidentally) using # as comment

Hello, I am trying to compile 8 schools with rstan 2.26

// saved as schools.stan
data {
  int<lower=0> J;         // number of schools 
  real y[J];              // estimated treatment effects
  real<lower=0> sigma[J]; // standard error of effect estimates 
}
parameters {
  real mu;                // population treatment effect
  real<lower=0> tau;      // standard deviation in treatment effects
  vector[J] eta;          // unscaled deviation from mu by school
}
transformed parameters {
  vector[J] theta = mu + tau * eta;        // school treatment effects
}
model {
  target += normal_lpdf(eta | 0, 1);       // prior log-density
  target += normal_lpdf(y | theta, sigma); // log-likelihood
}

But I get

[...]
  echo g++ -std=c++14 -shared -L"/stornext/System/data/apps/R/R-4.1.0/lib64/R/lib" -L/usr/local/lib64 -o file100177576684.so file100177576684.o  '/stornext/Home/data/allstaff/m/mangiola.s/R/library_for_cell_sig_with_new_rstan/rstudio/rstan/lib//libStanServices.a' -L'/stornext/Home/data/allstaff/m/mangiola.s/R/library_for_cell_sig_with_new_rstan/rstudio/StanHeaders/lib/' -lStanHeaders -L'/stornext/Home/data/allstaff/m/mangiola.s/R/library_for_cell_sig_with_new_rstan/rstudio/RcppParallel/lib/' -ltbb   -L"/stornext/System/data/apps/R/R-4.1.0/lib64/R/lib" -lR; \
  g++ -std=c++14 -shared -L"/stornext/System/data/apps/R/R-4.1.0/lib64/R/lib" -L/usr/local/lib64 -o file100177576684.so file100177576684.o  '/stornext/Home/data/allstaff/m/mangiola.s/R/library_for_cell_sig_with_new_rstan/rstudio/rstan/lib//libStanServices.a' -L'/stornext/Home/data/allstaff/m/mangiola.s/R/library_for_cell_sig_with_new_rstan/rstudio/StanHeaders/lib/' -lStanHeaders -L'/stornext/Home/data/allstaff/m/mangiola.s/R/library_for_cell_sig_with_new_rstan/rstudio/RcppParallel/lib/' -ltbb   -L"/stornext/System/data/apps/R/R-4.1.0/lib64/R/lib" -lR; \
fi

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

Program source:
  1: 
  2: // includes from the plugin
  3: // [[Rcpp::plugins(cpp14)]]
  4: 
  5: 
  6: // user includes
  7: #include <Rcpp.h>
  8: using namespace Rcpp;
  9: #ifndef MODELS_HPP
 10: #define MODELS_HPP
 11: #define STAN__SERVICES__COMMAND_HPP
 12: #include <rstan/rstaninc.hpp>
 13: #ifndef USE_STANC3
 14: #define USE_STANC3
 15: #endif
 16: #ifdef STAN_THREADS
 17: #ifndef RSTAN_THREADING
 18: #define RSTAN_THREADING
 19: #include <stan/math/prim/core/init_threadpool_tbb.hpp>
 20: auto tbb_init = stan::math::init_threadpool_tbb();
 21: #endif
 22: #endif
 23: 
 24: // Code generated by stanc v2.26.1
 25: #include <stan/model/model_header.hpp>
 26: namespace model_logistic1_namespace {
 27: 
 28: 
 29: inline void validate_positive_index(const char* var_name, const char* expr,
 30:                                     int val) {
 31:   if (val < 1) {
 32:     std::stringstream msg;
 33:     msg << "Found dimension size less than one in simplex declaration"
 [...]
174:     } catch (const std::exception& e) {
175:       stan::lang::rethrow_located(e, locations_array__[current_statement__]);
176:       // Next line prevents compiler griping about no return
177:       throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); 
178:     }
179:     num_params_r__ = 0U;
180:     
181:     try {
182:       num_params_r__ += 1;
183:       num_params_r__ += 1;
184:       num_params_r__ += J;
185:     } catch (const std::exception& e) {
186:       stan::lang::rethrow_located(e, locations_array__[current_statement__]);
187:       // Next line prevents compiler griping about no return
188:       throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); 
189:     }
190:   }
191:   template <bool propto__, bool jacobian__, typename VecR, typename VecI, stan::require_vector_like_t<VecR>* = nullptr, stan::require_vector_like_vt<std::is_integral, VecI>* = nullptr>
192:   inline stan::scalar_type_t<VecR> log_prob_impl(VecR& params_r__,
193:                                                  VecI& params_i__,
194:                                                  std::ostream* pstream__ = nullptr) const {
195:     using T__ = stan::scalar_type_t<VecR>;
196:     using local_scalar_t__ = T__;
197:     T__ lp__(0.0);
198:     stan::math::accumulator<T__> lp_accum__;
199:     static const char* function__ = "model_logistic1_namespace::log_prob";
200: (void) function__;  // suppress unused var warning
201: 
202:     stan::io::reader<local_scalar_t__> in__(params_r__, params_i__);
203:     local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
204:     (void) DUMMY_VAR__;  // suppress unused var warning
205: 
206:     
207:     try {
208:       local_scalar_t__ mu;
209:       mu = DUMMY_VAR__;
210:       
211:       current_statement__ = 1;
212:       mu = in__.scalar();
213:       local_scalar_t__ tau;
214:       tau = DUMMY_VAR__;
215:       
216:       current_statement__ = 2;
217:       tau = in__.scalar();
218:       current_statement__ = 2;
219:       if (jacobian__) {
220:         current_statement__ = 2;
221:         tau = stan::math::lb_constrain(tau, 0, lp__);
222:       } else {
223:         current_statement__ = 2;
224:         tau = stan::math::lb_constrain(tau, 0);
225:       }
226:       Eigen::Matrix<local_scalar_t__, -1, 1> eta;
227:       eta = Eigen::Matrix<local_scalar_t__, -1, 1>(J);
228:       stan::math::fill(eta, DUMMY_VAR__);
229:       
230:       current_statement__ = 3;
231:       eta = in__.vector(J);
232:       Eigen::Matrix<local_scalar_t__, -1, 1> theta;
233:       theta = Eigen::Matrix<local_scalar_t__, -1, 1>(J);
234:       stan::math::fill(theta, DUMMY_VAR__);
235:       
236:       current_statement__ = 4;
237:       assign(theta, nil_index_list(), add(mu, multiply(tau, eta)),
238:         "assigning variable theta");
239:       {
240:         current_statement__ = 5;
241:         lp_accum__.add(normal_lpdf<false>(eta, 0, 1));
242:         current_statement__ = 6;
243:         lp_accum__.add(normal_lpdf<false>(y, theta, sigma));
244:       }
245:     } catch (const std::exception& e) {
246:       stan::lang::rethrow_located(e, locations_array__[current_statement__]);
247:       // Next line prevents compiler griping about no return
248:       throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); 
249:     }
250:     lp_accum__.add(lp__);
251:     return lp_accum__.sum();
252:     } // log_prob_impl() 
253:     
254:   template <typename RNG, typename VecR, typename VecI, typename VecVar, stan::require_vector_like_vt<std::is_floating_point, VecR>* = nullptr, stan::require_vector_like_vt<std::is_integral, VecI>* = nullptr, stan::require_std_vector_vt<std::is_floating_point, VecVar>* = nullptr>
255:   inline void write_array_impl(RNG& base_rng__, VecR& params_r__,
256:                                VecI& params_i__, VecVar& vars__,
257:                                const bool emit_transformed_parameters__ = true,
258:                                const bool emit_generated_quantities__ = true,
259:                                std::ostream* pstream__ = nullptr) const {
260:     using local_scalar_t__ = double;
261:     vars__.resize(0);
262:     stan::io::reader<local_scalar_t__> in__(params_r__, params_i__);
263:     static const char* function__ = "model_logistic1_namespace::write_array";
264: (void) function__;  // suppress unused var warning
265: 
266:     (void) function__;  // suppress unused var warning
267: 
268:     double lp__ = 0.0;
269:     (void) lp__;  // dummy to suppress unused var warning
270:     stan::math::accumulator<double> lp_accum__;
271:     local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
272:     (void) DUMMY_VAR__;  // suppress unused var warning
273: 
274:     
275:     try {
276:       double mu;
277:       mu = std::numeric_limits<double>::quiet_NaN();
278:       
279:       current_statement__ = 1;
280:       mu = in__.scalar();
281:       double tau;
282:       tau = std::numeric_limits<double>::quiet_NaN();
283:       
284:       current_statement__ = 2;
285:       tau = in__.scalar();
286:       current_statement__ = 2;
287:       tau = stan::math::lb_constrain(tau, 0);
288:       Eigen::Matrix<double, -1, 1> eta;
289:       eta = Eigen::Matrix<double, -1, 1>(J);
290:       stan::math::fill(eta, std::numeric_limits<double>::quiet_NaN());
291:       
292:       current_statement__ = 3;
293:       eta = in__.vector(J);
294:       Eigen::Matrix<double, -1, 1> theta;
295:       theta = Eigen::Matrix<double, -1, 1>(J);
296:       stan::math::fill(theta, std::numeric_limits<double>::quiet_NaN());
297:       
298:       vars__.emplace_back(mu);
299:       vars__.emplace_back(tau);
300:       for (int sym1__ = 1; sym1__ <= J; ++sym1__) {
301:         vars__.emplace_back(eta[(sym1__ - 1)]);}
302:       if (logical_negation((primitive_value(emit_transformed_parameters__) ||
303:             primitive_value(emit_generated_quantities__)))) {
304:         return ;
305:       } 
306:       current_statement__ = 4;
307:       assign(theta, nil_index_list(), add(mu, multiply(tau, eta)),
308:         "assigning variable theta");
309:       if (emit_transformed_parameters__) {
310:         for (int sym1__ = 1; sym1__ <= J; ++sym1__) {
311:           vars__.emplace_back(theta[(sym1__ - 1)]);}
312:       } 
313:       if (logical_negation(emit_generated_quantities__)) {
314:         return ;
315:       } 
316:     } catch (const std::exception& e) {
317:       stan::lang::rethrow_located(e, locations_array__[current_statement__]);
318:       // Next line prevents compiler griping about no return
319:       throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); 
320:     }
321:     } // write_array_impl() 
322:     
323:   template <typename VecVar, typename VecI, stan::require_std_vector_t<VecVar>* = nullptr, stan::require_vector_like_vt<std::is_integral, VecI>* = nullptr>
324:   inline void transform_inits_impl(const stan::io::var_context& context__,
325:                                    VecI& params_i__, VecVar& vars__,
326:                                    std::ostream* pstream__ = nullptr) const {
327:     using local_scalar_t__ = double;
328:     vars__.clear();
329:     vars__.reserve(num_params_r__);
330:     
331:     try {
332:       int pos__;
333:       pos__ = std::numeric_limits<int>::min();
334:       
335:       pos__ = 1;
336:       double mu;
337:       mu = std::numeric_limits<double>::quiet_NaN();
338:       
339:       current_statement__ = 1;
340:       mu = context__.vals_r("mu")[(1 - 1)];
341:       double tau;
342:       tau = std::numeric_limits<double>::quiet_NaN();
343:       
344:       current_statement__ = 2;
345:       tau = context__.vals_r("tau")[(1 - 1)];
346:       double tau_free__;
347:       tau_free__ = std::numeric_limits<double>::quiet_NaN();
348:       
349:       current_statement__ = 2;
350:       tau_free__ = stan::math::lb_free(tau, 0);
351:       Eigen::Matrix<double, -1, 1> eta;
352:       eta = Eigen::Matrix<double, -1, 1>(J);
353:       stan::math::fill(eta, std::numeric_limits<double>::quiet_NaN());
354:       
355:       {
356:         std::vector<local_scalar_t__> eta_flat__;
357:         current_statement__ = 3;
358:         assign(eta_flat__, nil_index_list(), context__.vals_r("eta"),
359:           "assigning variable eta_flat__");
360:         current_statement__ = 3;
361:         pos__ = 1;
362:         current_statement__ = 3;
363:         for (int sym1__ = 1; sym1__ <= J; ++sym1__) {
364:           current_statement__ = 3;
365:           assign(eta, cons_list(index_uni(sym1__), nil_index_list()),
366:             eta_flat__[(pos__ - 1)], "assigning variable eta");
367:           current_statement__ = 3;
368:           pos__ = (pos__ + 1);}
369:       }
370:       vars__.emplace_back(mu);
371:       vars__.emplace_back(tau_free__);
372:       for (int sym1__ = 1; sym1__ <= J; ++sym1__) {
373:         vars__.emplace_back(eta[(sym1__ - 1)]);}
374:     } catch (const std::exception& e) {
375:       stan::lang::rethrow_located(e, locations_array__[current_statement__]);
376:       // Next line prevents compiler griping about no return
377:       throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); 
378:     }
379:     } // transform_inits_impl() 
380:     
381:   inline void get_param_names(std::vector<std::string>& names__) const {
382:     
383:     names__.clear();
384:     names__.emplace_back("mu");
385:     names__.emplace_back("tau");
386:     names__.emplace_back("eta");
387:     names__.emplace_back("theta");
388:     } // get_param_names() 
389:     
390:   inline void get_dims(std::vector<std::vector<size_t>>& dimss__) const {
391:     dimss__.clear();
392:     dimss__.emplace_back(std::vector<size_t>{});
393:     
394:     dimss__.emplace_back(std::vector<size_t>{});
395:     
396:     dimss__.emplace_back(std::vector<size_t>{static_cast<size_t>(J)});
397:     
398:     dimss__.emplace_back(std::vector<size_t>{static_cast<size_t>(J)});
399:     
400:     } // get_dims() 
401:     
402:   inline void constrained_param_names(
403:                                       std::vector<std::string>& param_names__,
404:                                       bool emit_transformed_parameters__ = true,
405:                                       bool emit_generated_quantities__ = true) const
406:     final {
407:     
408:     param_names__.emplace_back(std::string() + "mu");
409:     param_names__.emplace_back(std::string() + "tau");
410:     for (int sym1__ = 1; sym1__ <= J; ++sym1__) {
411:       {
412:         param_names__.emplace_back(std::string() + "eta" + '.' + std::to_string(sym1__));
413:       }}
414:     if (emit_transformed_parameters__) {
415:       for (int sym1__ = 1; sym1__ <= J; ++sym1__) {
416:         {
417:           param_names__.emplace_back(std::string() + "theta" + '.' + std::to_string(sym1__));
418:         }}
419:     }
420:     
421:     if (emit_generated_quantities__) {
422:       
423:     }
424:     
425:     } // constrained_param_names() 
426:     
427:   inline void unconstrained_param_names(
428:                                         std::vector<std::string>& param_names__,
429:                                         bool emit_transformed_parameters__ = true,
430:                                         bool emit_generated_quantities__ = true) const
431:     final {
432:     
433:     param_names__.emplace_back(std::string() + "mu");
434:     param_names__.emplace_back(std::string() + "tau");
435:     for (int sym1__ = 1; sym1__ <= J; ++sym1__) {
436:       {
437:         param_names__.emplace_back(std::string() + "eta" + '.' + std::to_string(sym1__));
438:       }}
439:     if (emit_transformed_parameters__) {
440:       for (int sym1__ = 1; sym1__ <= J; ++sym1__) {
441:         {
442:           param_names__.emplace_back(std::string() + "theta" + '.' + std::to_string(sym1__));
443:         }}
444:     }
445:     
446:     if (emit_generated_quantities__) {
447:       
448:     }
449:     
450:     } // unconstrained_param_names() 
451:     
452:   inline std::string get_constrained_sizedtypes() const {
453:     stringstream s__;
454:     s__ << "[{\"name\":\"mu\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"tau\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"eta\",\"type\":{\"name\":\"vector\",\"length\":" << J << "},\"block\":\"parameters\"},{\"name\":\"theta\",\"type\":{\"name\":\"vector\",\"length\":" << J << "},\"block\":\"transformed_parameters\"}]";
455:     return s__.str();
456:     } // get_constrained_sizedtypes() 
457:     
458:   inline std::string get_unconstrained_sizedtypes() const {
459:     stringstream s__;
460:     s__ << "[{\"name\":\"mu\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"tau\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"eta\",\"type\":{\"name\":\"vector\",\"length\":" << J << "},\"block\":\"parameters\"},{\"name\":\"theta\",\"type\":{\"name\":\"vector\",\"length\":" << J << "},\"block\":\"transformed_parameters\"}]";
461:     return s__.str();
462:     } // get_unconstrained_sizedtypes() 
463:     
464:   
465:     // Begin method overload boilerplate
466:     template <typename RNG>
467:     inline void write_array(RNG& base_rng,
468:                             Eigen::Matrix<double,Eigen::Dynamic,1>& params_r,
469:                             Eigen::Matrix<double,Eigen::Dynamic,1>& vars,
470:                             const bool emit_transformed_parameters = true,
471:                             const bool emit_generated_quantities = true,
472:                             std::ostream* pstream = nullptr) const {
473:       std::vector<double> vars_vec(vars.size());
474:       std::vector<int> params_i;
475:       write_array_impl(base_rng, params_r, params_i, vars_vec,
476:           emit_transformed_parameters, emit_generated_quantities, pstream);
477:       vars.resize(vars_vec.size());
478:       for (int i = 0; i < vars.size(); ++i) {
479:         vars.coeffRef(i) = vars_vec[i];
480:       }
481:     }
482: 
483:     template <typename RNG>
484:     inline void write_array(RNG& base_rng, std::vector<double>& params_r,
485:                             std::vector<int>& params_i,
486:                             std::vector<double>& vars,
487:                             bool emit_transformed_parameters = true,
488:                             bool emit_generated_quantities = true,
489:                             std::ostream* pstream = nullptr) const {
490:       write_array_impl(base_rng, params_r, params_i, vars, emit_transformed_parameters, emit_generated_quantities, pstream);
491:     }
492: 
493:     template <bool propto__, bool jacobian__, typename T_>
494:     inline T_ log_prob(Eigen::Matrix<T_,Eigen::Dynamic,1>& params_r,
495:                        std::ostream* pstream = nullptr) const {
496:       Eigen::Matrix<int, -1, 1> params_i;
497:       return log_prob_impl<propto__, jacobian__>(params_r, params_i, pstream);
498:     }
499: 
500:     template <bool propto__, bool jacobian__, typename T__>
501:     inline T__ log_prob(std::vector<T__>& params_r,
502:                         std::vector<int>& params_i,
503:                         std::ostream* pstream = nullptr) const {
504:       return log_prob_impl<propto__, jacobian__>(params_r, params_i, pstream);
505:     }
506:   
507: 
508:     inline void transform_inits(const stan::io::var_context& context,
509:                          Eigen::Matrix<double, Eigen::Dynamic, 1>& params_r,
510:                          std::ostream* pstream = nullptr) const final {
511:       std::vector<double> params_r_vec(params_r.size());
512:       std::vector<int> params_i;
513:       transform_inits_impl(context, params_i, params_r_vec, pstream);
514:       params_r.resize(params_r_vec.size());
515:       for (int i = 0; i < params_r.size(); ++i) {
516:         params_r.coeffRef(i) = params_r_vec[i];
517:       }
518:     }
519:     inline void transform_inits(const stan::io::var_context& context,
520:                                 std::vector<int>& params_i,
521:                                 std::vector<double>& vars,
522:                                 std::ostream* pstream = nullptr) const final {
523:       transform_inits_impl(context, params_i, vars, pstream);
524:     }        
525: 
526: };
527: }
528: using stan_model = model_logistic1_namespace::model_logistic1;
529: 
530: #ifndef USING_R
531: 
532: // Boilerplate
533: stan::model::model_base& new_model(
534:         stan::io::var_context& data_context,
535:         unsigned int seed,
536:         std::ostream* msg_stream) {
537:   stan_model* m = new stan_model(data_context, seed, msg_stream);
538:   return *m;
539: }
540: 
541: stan::math::profile_map& get_stan_profile_data() {
542:   return model_logistic1_namespace::profiles__;
543: }
544: 
545: #endif
546: 
547: 
548: 
549: #endif
550: 
551: RCPP_MODULE(stan_fit4model_logistic1_mod) {
552:   class_<rstan::stan_fit<stan_model, boost::random::ecuyer1988> >(
553:       "stan_fit4model_logistic1")
554: 
555:       .constructor<SEXP, SEXP, SEXP>()
556: 
557:       .method(
558:           "call_sampler",
559:           &rstan::stan_fit<stan_model, boost::random::ecuyer1988>::call_sampler)
560:       .method(
561:           "param_names",
562:           &rstan::stan_fit<stan_model, boost::random::ecuyer1988>::param_names)
563:       .method("param_names_oi",
564:               &rstan::stan_fit<stan_model,
565:                                boost::random::ecuyer1988>::param_names_oi)
566:       .method("param_fnames_oi",
567:               &rstan::stan_fit<stan_model,
568:                                boost::random::ecuyer1988>::param_fnames_oi)
569:       .method(
570:           "param_dims",
571:           &rstan::stan_fit<stan_model, boost::random::ecuyer1988>::param_dims)
572:       .method("param_dims_oi",
573:               &rstan::stan_fit<stan_model,
574:                                boost::random::ecuyer1988>::param_dims_oi)
575:       .method("update_param_oi",
576:               &rstan::stan_fit<stan_model,
577:                                boost::random::ecuyer1988>::update_param_oi)
578:       .method("param_oi_tidx",
579:               &rstan::stan_fit<stan_model,
580:                                boost::random::ecuyer1988>::param_oi_tidx)
581:       .method("grad_log_prob",
582:               &rstan::stan_fit<stan_model,
583:                                boost::random::ecuyer1988>::grad_log_prob)
584:       .method("log_prob",
585:               &rstan::stan_fit<stan_model, boost::random::ecuyer1988>::log_prob)
586:       .method("unconstrain_pars",
587:               &rstan::stan_fit<stan_model,
588:                                boost::random::ecuyer1988>::unconstrain_pars)
589:       .method("constrain_pars",
590:               &rstan::stan_fit<stan_model,
591:                                boost::random::ecuyer1988>::constrain_pars)
592:       .method(
593:           "num_pars_unconstrained",
594:           &rstan::stan_fit<stan_model,
595:                            boost::random::ecuyer1988>::num_pars_unconstrained)
596:       .method(
597:           "unconstrained_param_names",
598:           &rstan::stan_fit<
599:               stan_model, boost::random::ecuyer1988>::unconstrained_param_names)
600:       .method(
601:           "constrained_param_names",
602:           &rstan::stan_fit<stan_model,
603:                            boost::random::ecuyer1988>::constrained_param_names)
604:       .method("standalone_gqs",
605:               &rstan::stan_fit<stan_model,
606:                                boost::random::ecuyer1988>::standalone_gqs);
607: }
608: 
609: 
610: // declarations
611: extern "C" {
612: SEXP file100177576684( ) ;
613: }
614: 
615: // definition
616: SEXP file100177576684() {
617:  return Rcpp::wrap("logistic1");
618: }

Compilation ERROR, function(s)/method(s) not created!
Error in compileCode(f, code, language = language, verbose = verbose) : 
                   from /stornext/Home/data/allstaff/m/mangiola.s/R/library_for_cell_sig_with_new_rstan/rstudio/rstan/include/rstan/rstaninc.hpp:4,                 from file100177576684.cpp:12:/stornext/Home/data/allstaff/m/mangiola.s/R/library_for_cell_sig_with_new_rstan/rstudio/StanHeaders/include/tbb/tbb_stddef.h:333:5: note: declared private here  333 |     no_copy( const no_copy& );      |     ^~~~~~~make: *** [file100177576684.o] Error 1
> sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)

Matrix products: default
BLAS:   /stornext/System/data/apps/R/R-4.1.0/lib64/R/lib/libRblas.so
LAPACK: /stornext/System/data/apps/R/R-4.1.0/lib64/R/lib/libRlapack.so

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

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

other attached packages:
[1] rstan_2.26.4       StanHeaders_2.26.4

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.7         compiler_4.1.0     pillar_1.6.4       prettyunits_1.1.1  tools_4.1.0        pkgbuild_1.2.0    
 [7] jsonlite_1.7.2     lifecycle_1.0.1    tibble_3.1.6       gtable_0.3.0       pkgconfig_2.0.3    rlang_0.4.12      
[13] DBI_1.1.1          cli_3.1.0          parallel_4.1.0     curl_4.3.2         loo_2.4.1          gridExtra_2.3     
[19] dplyr_1.0.7        generics_0.1.1     vctrs_0.3.8        tidyselect_1.1.1   stats4_4.1.0       grid_4.1.0        
[25] glue_1.5.0         inline_0.3.19      R6_2.5.1           processx_3.5.2     fansi_0.5.0        purrr_0.3.4       
[31] ggplot2_3.3.5      callr_3.7.0        magrittr_2.0.1     codetools_0.2-18   matrixStats_0.61.0 scales_1.1.1      
[37] ps_1.6.0           ellipsis_0.3.2     assertthat_0.2.1   colorspace_2.0-2   V8_3.6.0           utf8_1.2.2        
[43] RcppParallel_5.1.4 munsell_0.5.0      crayon_1.4.2  

.Makevars


MAKEFLAGS = -j8

## C++ flags
CXX=g++
CXX11=g++
CXX14=g++
CXX17=g++

CXXFLAGS=-O3 -march=native -Wno-ignored-attributes
CXX11FLAGS=-O3 -march=native -Wno-ignored-attributes
CXX14FLAGS=-O3 -march=native -Wno-ignored-attributes
CXX17FLAGS=-O3 -march=native -Wno-ignored-attributes

CXXPICFLAGS=-fPIC
CXX11PICFLAGS=-fPIC
CXX14PICFLAGS=-fPIC
CXX17PICFLAGS=-fPIC

CXX11STD=-std=c++11
CXX14STD=-std=c++14
CXX17STD=-std=c++17

## C flags
CC=gcc
CFLAGS=-O3 -march=native

## Fortran flags
FC=gfortran
F77=gfortran
FFLAGS=-O3 -march=native
FCFLAGS=-O3 -march=native


Sorry for the delay in getting to this. Does the error persist if you reinstall RcppParallel, StanHeaders, and rstan? Can I also confirm that your g++ version is >= 4.9.3?

@hsbadr This might be related to the statically-linked TBB, since the error references something TBB-related:

...StanHeaders/include/tbb/tbb_stddef.h:333:5: note: declared private here  333 |     no_copy( const no_copy& );      |     ^~~~~~~make: *** [file100177576684.o] Error 1
1 Like

This looks like a need to apply a patch to TBB headers for R/Rcpp, not due to static linking. Can you try the following?

sed -i 's|no_copy( const no_copy& );|//no_copy( const no_copy& );|g' StanHeaders/include/tbb/tbb_stddef.h

This assumes that you’re at the R library directory. It basically comments out line #332 of tbb_stddef.h. If that fixes it, we could patch it in Math or StanHeaders. We might need a few similar patches, but let’s test this 1st.

Alternatively, we could statically build TBB source code from RcppParallel not Math.

CRAN will require more minor patches. So, I’m syncing TBB between StanHeaders and RcppParallel. I will update the packages ASAP.

Could you test v2.26.5?

remove.packages(c("rstan", "StanHeaders"))
install.packages("rstan", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))
1 Like

Thanks everybody, installing v2.26.5 worked, and reduce_sum rocks!

Having said that,

something very strange happens (with v2.26.5 and all).

The following model compiles no problem

> gmod <- stan_model(stanc_ret = stanc_builder('~/PostDoc/cellsig/dev/logistic1.stan'),auto_write = F,verbose = T)

functions {
  real partial_sum_lpmf(int[] slice_n_redcards,
                        int start, int end,
                        int[] n_games,
                        vector rating,
                        vector beta1,
                        vector beta2) {
    return binomial_logit_lupmf(slice_n_redcards |
                               n_games[start:end],
                               beta1[start:end] + beta2[start:end] .* rating[start:end]);
  }
}
data {
  int<lower=0> N;
  int<lower=0> n_redcards[N];
  int<lower=0> n_games[N];
  vector[N] rating;
  int<lower=1> grainsize;
}
parameters {
  vector[2] beta;
}
transformed parameters {
  vector[N] beta1;
  vector[N] beta2;
  
  for(n in 1:N) beta1[n] = beta[1];
  for(n in 1:N) beta2[n] = beta[2];
}
model {

  beta[1] ~ normal(0, 10);
  beta[2] ~ normal(0, 1);

  target += reduce_sum(partial_sum_lupmf, n_redcards, grainsize,
                       n_games, rating, beta1, beta2);
}

Then I try a model of mine

> mod <- stan_model(stanc_ret = stanc_builder('~/PostDoc/cellsig/dev/mixed_effect.stan'),auto_write = F,verbose = T)

functions {
    real partial_sum_lpmf(int[] slice_Y,
                        int start, int end,
                        vector mu,
                        vector shape) {
    return neg_binomial_2_log_lupmf(slice_Y | mu[start:end], 1.0 ./ exp(shape[start:end]) );
                               
  }
}
data {
  
  // OBSERVATION LEVEL
  int<lower=1> N;  // total number of observations samples * genes
  int<lower=1> grouping_gene_idx_N[N, 2];  // grouping and gene indicator per observation // first clumn is dataset second is gene
  int Y[N];  // response variable

  // dataset * gene level
  int<lower=1> G; // total genes
  int<lower=1> D; // total datasets, they are unique with genes, so D >> G
  int<lower=1> grouping_gene_idx_D[D, 2];  // grouping and gene indicator per observation // first clumn is dataset second is gene

  // data for group-level effects of ID 1
  //int<lower=1> num_dataset_times_gene;  // number of grouping levels datasets * genes
  //int<lower=1> num_coefficient;  // number of coefficients per level
  
  // Priors
  real assoc_intercept;
  real assoc_slope;
  real assoc_sd_sd;
  real assoc_sd_shape;
  real lambda_mu;
  real lambda_sigma;
  real lambda_skew;
  
  int<lower=1> grainsize;

}
transformed data {
}
parameters {
  vector[G] gene_mean;  // temporary gene_mean for centered predictors
  vector[G] shape;  // shape parameter
  vector<lower=0>[G] gene_sd;  // group-level standard deviations
  vector[D] z_group_level_effect;  // standardized group-level effects

}
transformed parameters {
  vector[D] group_level_effect = gene_sd[grouping_gene_idx_D[,2]] .* z_group_level_effect;
}
model {
  // likelihood including constants

    // initialize linear predictor term
    vector[N] mu = gene_mean[grouping_gene_idx_N[,2]] ;
    for (n in 1:N) {
      // add more terms to the linear predictor
      mu[n] += group_level_effect[grouping_gene_idx_N[n,1]];
    }
    
  // target += neg_binomial_2_log_lpmf(Y | mu, 1.0 ./ exp(shape[grouping_gene_idx_N[,2]]));

  target += reduce_sum(partial_sum_lupmf, Y, grainsize, mu, shape[grouping_gene_idx_N[,2]]);
                       
  // priors including constants
  //target += student_t_lpdf(gene_mean | 3, 3.3, 3);
  gene_mean ~ skew_normal(lambda_mu, exp(lambda_sigma), lambda_skew);
	
  target += student_t_lpdf(gene_sd | 8, 0, 3) - 1 * student_t_lccdf(0 | 8, 0, 3);
  target += std_normal_lpdf(z_group_level_effect);
  
  // prior association
  shape ~ normal(  gene_mean * assoc_slope + assoc_intercept, assoc_sd_shape);
  //target += normal_lpdf(shape |  0, 3);
  #shape ~  normal(  gene_mean * assoc_slope + assoc_intercept, assoc_sd_sd);
  
}


The compilation fails with

Error in stanc(model_code = model_code, model_name = model_name, verbose = verbose,  : 
  parser failed badly

Then I try to recompile the model that worked before, and the model fails now!

> gmod <- stan_model(stanc_ret = stanc_builder('~/PostDoc/cellsig/dev/logistic1.stan'),auto_write = F,verbose = T)
Error in stanc(model_code = model_code, model_name = model_name, verbose = verbose,  : 
  parser failed badly

If I reset R in Rstudio then this works again

 gmod <- stan_model(stanc_ret = stanc_builder('~/PostDoc/cellsig/dev/logistic1.stan'),auto_write = F,verbose = T)

The questions are two

  1. why my model fails “badly” without any specific error message
  2. why after the failure of my model, the model that was compiling before now fails “badly”
> sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)

Matrix products: default
BLAS:   /stornext/System/data/apps/R/R-4.1.0/lib64/R/lib/libRblas.so
LAPACK: /stornext/System/data/apps/R/R-4.1.0/lib64/R/lib/libRlapack.so

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

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

other attached packages:
[1] rstan_2.26.5       StanHeaders_2.26.5

loaded via a namespace (and not attached):
 [1] tidyselect_1.1.1     purrr_0.3.4          lattice_0.20-45      V8_3.6.0             colorspace_2.0-2     vctrs_0.3.8         
 [7] generics_0.1.1       stats4_4.1.0         loo_2.4.1            utf8_1.2.2           rlang_0.4.12         pkgbuild_1.2.0      
[13] pillar_1.6.4         glue_1.5.0           withr_2.4.2          DBI_1.1.1            distributional_0.2.2 matrixStats_0.61.0  
[19] lifecycle_1.0.1      posterior_1.1.0      munsell_0.5.0        gtable_0.3.0         codetools_0.2-18     coda_0.19-4         
[25] inline_0.3.19        callr_3.7.0          ps_1.6.0             curl_4.3.2           parallel_4.1.0       fansi_0.5.0         
[31] Rcpp_1.0.7           arrayhelpers_1.1-0   backports_1.3.0      checkmate_2.0.0      scales_1.1.1         RcppParallel_5.1.4  
[37] jsonlite_1.7.2       abind_1.4-5          farver_2.1.0         gridExtra_2.3        tensorA_0.36.2       tidybayes_3.0.1     
[43] ggplot2_3.3.5        svUnit_1.0.6         processx_3.5.2       dplyr_1.0.7          grid_4.1.0           ggdist_3.0.0        
[49] cli_3.1.0            tools_4.1.0          magrittr_2.0.1       tibble_3.1.6         tidyr_1.1.4          crayon_1.4.2        
[55] pkgconfig_2.0.3      ellipsis_0.3.2       prettyunits_1.1.1    lubridate_1.8.0      assertthat_0.2.1     rstudioapi_0.13     
[61] R6_2.5.1             compiler_4.1.0

Makevars

CXX14FLAGS += -O3
CXX14FLAGS += -DSTAN_THREADS
CXX14FLAGS += -pthread
CXX14FLAGS += -march=native -mtune=native -fPIC
CXX14FLAGS += -DUSE_STANC3
CXX14=g++

MAKEFLAGS = -j8

GCC

gcc (GCC) 11.1.0

Thanks

1 Like

“Failed badly” means that stanc3 java script can’t generate C++ code. Need to check why this happens: it could be an environment or dependency issue (e.g., V8). It seems that the same code works in a new session; right? Does it fail in R (without R Studio)? I’ll look into it.

  model_cppcode <- try(stanc_ctx$call("stanc", model_cppname, model_code, stanc_flags),
                       silent = TRUE)
  if (inherits(model_cppcode, "try-error")) {
    stop("parser failed badly")
  } else ...

Just to be clear, on a fresh R session in Rstudio, the model

> gmod <- stan_model(stanc_ret = stanc_builder('~/PostDoc/cellsig/dev/logistic1.stan'),auto_write = F,verbose = T)

Compiles successfully. So I would suppose I don’t have dependency issues.

logistic1.stan works in a new session

mixed_effect.stan never works and badly fails

Yes

Thanks for your time!

@stemangiola Can you test after reinstalling StanHeaders and rstan as follows:

  1. Set TBB_LIB and TBB_INC environment variables to RcppParallel:
    1.1 Sys.setenv(TBB_LIB = RcppParallel::tbbLibraryPath())
    1.2 Get the TBB headers directory from RcppParallel::CxxFlags() and similarly set TBB_INC.
  2. Install StanHeaders and rstan v2.26.4
remove.packages(c("rstan", "StanHeaders"))
install.packages("StanHeaders", version = "2.26.4", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))
install.packages("rstan", version = "2.26.4", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))

Also, what’s the version of StanHeaders on your system?

You may also test an older version (v2.26.3) that doesn’t build static TBB objects:

remove.packages(c("rstan", "StanHeaders"))
install.packages("StanHeaders", version = "2.26.3", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))
install.packages("rstan", version = "2.26.3", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))

I’m trying to check if this issue is related to static TBB. Thanks!

Before I proceed I want to make sure:

RcppParallel::CxxFlags()

Does not return anything

While

RcppParallel::tbbLibraryPath()
[1] "/stornext/Home/data/allstaff/m/mangiola.s/R/x86_64-pc-linux-gnu-library_interactive/rstudio/RcppParallel/lib"

Thanks @stemangiola! FYI. I’ve updated my reply above.

You can test v2.26.4 with:

Sys.setenv(TBB_LIB = system.file("lib", package = "RcppParallel"))
Sys.setenv(TBB_INC = system.file("include", package = "RcppParallel"))
remove.packages(c("rstan", "StanHeaders"))
install.packages("StanHeaders", version = "2.26.4", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))
install.packages("rstan", version = "2.26.4", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))

or test v2.26.3 in a new session. That means unset those env variables and reinstall v2.26.3:

Sys.unsetenv("TBB_LIB")
Sys.unsetenv("TBB_INC")
remove.packages(c("rstan", "StanHeaders"))
install.packages("StanHeaders", version = "2.26.3", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))
install.packages("rstan", version = "2.26.3", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))

It seems to force x.x.5 installation with your command

install.packages("StanHeaders", version = "2.26.4", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))
Installing package into ‘/stornext/Home/data/allstaff/m/mangiola.s/R/library_for_cell_sig_with_new_rstan/rstudio’
(as ‘lib’ is unspecified)
trying URL 'https://mc-stan.org/r-packages/src/contrib/StanHeaders_2.26.5.tar.gz'

[EDIT] I am installing packages manually downloaded

Thanks! I’m building v2.26.6 with the potential fixes (need to test as I can’t reproduce your errors in my environment, which uses external TBB library).

Unfortunately

library(rstan)
Loading required package: StanHeaders

rstan version 2.26.4 (Stan version 2.26.1)

For execution on a local, multicore CPU with excess RAM we recommend calling
options(mc.cores = parallel::detectCores()).
To avoid recompilation of unchanged Stan programs, we recommend calling
rstan_options(auto_write = TRUE)
For within-chain threading using `reduce_sum()` or `map_rect()` Stan functions,
change `threads_per_chain` option:
rstan_options(threads_per_chain = 1)

> rstan_options(threads_per_chain = 4)
> mod <- stan_model(stanc_ret = stanc_builder('~/PostDoc/cellsig/dev/mixed_effect.stan'),auto_write = F,verbose = T)
Error in stanc(model_code = model_code, model_name = model_name, verbose = verbose,  : 
  parser failed badly

What’s the output of the following?

packageVersion("RcppParallel")
RcppParallel::LdFlags()
RcppParallel::CxxFlags()

packageVersion("rstan")

packageVersion("StanHeaders")
system.file("include", "tbb", package = "StanHeaders")
> packageVersion("RcppParallel")
[1] ‘5.1.4’
> RcppParallel::LdFlags()
> RcppParallel::CxxFlags()
> 
> packageVersion("rstan")
[1] ‘2.26.4’
> 
> packageVersion("StanHeaders")
[1] ‘2.26.4’
> system.file("include", "tbb", package = "StanHeaders")
[1] "/stornext/Home/data/allstaff/m/mangiola.s/R/library_for_cell_sig_with_new_rstan/rstudio/StanHeaders/include/tbb"

Ok. I see two issues:

  1. RcppParallel's flags are empty - You may need to reinstall RcppParallel.
  2. You still have TBB headers within StanHeaders.

If you set the env variables correctly, there shouldn’t be any TBB headers in StanHeaders. I’m building v2.26.6, which will take care of the 2nd issue.

Thanks.

Please specify what versions (and how would be amazing so to get it right the first time) should I install of, RcppParallel, StanHeaders, and rstan