Cmdstan 2.30.1 shows warning when compiling with 'reduce_sum'

Hi,

I am using 'Cmdstan ‘2.30.1’ (cmdstanr version ‘0.5.2’) as backend with brms (version ‘2.17.3’). During compilation, following warnings are shown but model compiles successfully and samples as expected.

&, const double&>::recursive_reducer::args_tuple_' [-Wreorder]
     std::tuple<Args...> args_tuple_;
                         ^~~~~~~~~~~
stan/lib/stan_math/stan/math/rev/functor/reduce_sum.hpp:78:5: warning:   when initialized here [-Wreorder]
     recursive_reducer(recursive_reducer& other, tbb::split)
     ^~~~~~~~~~~~~~~~~

I guess these warnings are harmless but still I want to resolve the issue. I would really appreciate your help.

Thanks

I understand the concern, but can assure you this warning is harmless.

The reorder warnings (i.e., -Wreorder) occur when the declaration of member variables is in a different order than their initialization. The reason it’s a warning is that the calls are executed in order or declaration, not in the order they’re written in a C++ constructor.

The problematic source file is https://github.com/stan-dev/math/blob/develop/stan/math/rev/functor/reduce_sum.hpp. The issue is that the member variables are declared as:

    const size_t num_vars_per_term_;
    const size_t num_vars_shared_terms_;  // Number of vars in shared arguments
    double* sliced_partials_;  // Points to adjoints of the partial calculations
    Vec vmapped_;
    std::stringstream msgs_;
    std::tuple<Args...> args_tuple_;
    scoped_args_tuple local_args_tuple_scope_;
    double sum_{0.0};
    Eigen::VectorXd args_adjoints_{0};

but the constructor throwing the error initializes this way:

          num_vars_per_term_(other.num_vars_per_term_),
          num_vars_shared_terms_(other.num_vars_shared_terms_),
          sliced_partials_(other.sliced_partials_),
          vmapped_(other.vmapped_),
          local_args_tuple_scope_(),
          args_tuple_(other.args_tuple_)

The last two are out of order—args_tuple_ should’ve come before local_args_tuple_scope_. Given there’s no dependent computation, this won’t cause a problem.

I opened an issue in Stan math to rearrange the initializers, which will not change behavior, but will get rid of the warning:

2 Likes

Thank you for looking into the matter and opening an issue.

The fix is done and will be in the next release. Here’s the GitHub pull request with the patch.

Thanks for the update.

Regards