# Cmdstanpy reduce\_sum doesn't produce executable

**URL:** <https://discourse.mc-stan.org/t/cmdstanpy-reduce-sum-doesnt-produce-executable/33637>\
**Category:** Developers\
**Tags:** compiler\
**Created:** [December 20, 2023, 4:53pm UTC](https://discourse.mc-stan.org/t/cmdstanpy-reduce-sum-doesnt-produce-executable/33637 "2023-12-20T16:53:35Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![mathDR](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/mathdr/32/1997_2.png) [@mathDR](https://discourse.mc-stan.org/u/mathDR)\
**Post date:** [December 20, 2023, 4:53pm UTC](https://discourse.mc-stan.org/t/cmdstanpy-reduce-sum-doesnt-produce-executable/33637/1 "2023-12-20T16:53:35Z")

</div>

Hello all! I am running the `cmdstanpy` [example](https://cmdstanpy.readthedocs.io/en/v1.2.0/users-guide/examples/MCMC%20Sampling.html#Parallelization-via-multi-threaded-processing) for within chain parallelization using `reduce_sum`.

I am doing so as a base case to show the error I am getting for a bespoke model I am building.

In short:

If I run

```no-highlight
import cmdstanpy
import pprint

cmdstanpy.install_cmdstan()

from cmdstanpy import CmdStanModel

redcard_model = CmdStanModel(
    stan_file='redcard_reduce_sum.stan',
    # cpp_options={'STAN_THREADS': 'TRUE'},
    force_compile=True,
)
pprint.pprint(redcard_model.exe_info())

```

The output produced is:

```no-highlight
{'STAN_CPP_OPTIMS': 'false',
 'STAN_MPI': 'false',
 'STAN_NO_RANGE_CHECKS': 'false',
 'STAN_OPENCL': 'false',
 'STAN_THREADS': 'false',
 'stan_version_major': '2',
 'stan_version_minor': '33',
 'stan_version_patch': '0'}

```

which is expected. _However_, when I run

```no-highlight
redcard_model = CmdStanModel(
    stan_file='redcard_reduce_sum.stan',
    cpp_options={'STAN_THREADS': 'TRUE'},
    force_compile=True,
)
pprint.pprint(redcard_model.exe_info())

```

i.e. try to compile with `stan_threads=true`, I get:

```no-highlight
{}

```

as the output.

This manifests when I try to sample because, in the former case, I run 4 chains successfully, but in the latter case, I produce:

```no-highlight
(cmdstanpy) 11:50:04 ~/dev/eligere/eligere/models/stan main $ python compute_stan_rs.py
CmdStan install directory: /Users/daniel.marthaler/.cmdstan
CmdStan version 2.33.1 already installed
Test model compilation
11:50:08 - cmdstanpy - INFO - compiling stan file /Users/daniel.marthaler/dev/eligere/eligere/models/stan/redcard_reduce_sum.stan to exe file /Users/daniel.marthaler/dev/eligere/eligere/models/stan/redcard_reduce_sum
11:50:12 - cmdstanpy - INFO - compiled model executable: /Users/daniel.marthaler/dev/eligere/eligere/models/stan/redcard_reduce_sum
{}
11:50:13 - cmdstanpy - INFO - CmdStan start processing
chain 1 |████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 00:00 Sampling completed
chain 2 |████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 00:00 Sampling completed
chain 3 |████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 00:00 Sampling completed
chain 4 |████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 00:00 Sampling completed
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
11:50:13 - cmdstanpy - INFO - CmdStan done processing.
Traceback (most recent call last):
  File "/Users/daniel.marthaler/dev/eligere/eligere/models/stan/compute_stan_rs.py", line 34, in <module>
    redcard_fit = redcard_model.sample(data=stan_data, threads_per_chain=4)
  File "/Users/daniel.marthaler/.pyenv/versions/cmdstanpy/lib/python3.9/site-packages/cmdstanpy/model.py", line 1173, in sample
    raise RuntimeError(msg)
RuntimeError: Error during sampling:

Command and output files:
RunSet: chains=4, chain_ids=[1, 2, 3, 4], num_processes=4
 cmd (chain 1):
	['/Users/daniel.marthaler/dev/eligere/eligere/models/stan/redcard_reduce_sum', 'id=1', 'random', 'seed=59043', 'data', 'file=/var/folders/rk/49593z6j4xx_hxmgmkhxh50w0000gq/T/tmpot9pytf4/gmhbohve.json', 'output', 'file=/var/folders/rk/49593z6j4xx_hxmgmkhxh50w0000gq/T/tmpot9pytf4/redcard_reduce_sumdaeecrj7/redcard_reduce_sum-20231220115013_1.csv', 'method=sample', 'algorithm=hmc', 'adapt', 'engaged=1']
 retcodes=[-1, -1, -1, -1]
 per-chain output files (showing chain 1 only):
 csv_file:
	/var/folders/rk/49593z6j4xx_hxmgmkhxh50w0000gq/T/tmpot9pytf4/redcard_reduce_sumdaeecrj7/redcard_reduce_sum-20231220115013_1.csv
 console_msgs (if any):
	/var/folders/rk/49593z6j4xx_hxmgmkhxh50w0000gq/T/tmpot9pytf4/redcard_reduce_sumdaeecrj7/redcard_reduce_sum-20231220115013_0-stdout.txt
Consider re-running with show_console=True if the above output is unclear!
(cmdstanpy) 11:50:13 ~/dev/eligere/eligere/models/stan main

```

which seems to imply that no executable was produced (and none exists in the directory).

Any thoughts?

This is an Apple Macbook Pro running an M1 Max on Sonoma 14.1.2

---

<div class="post-metadata">

**Author:** ![WardBrian](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/wardbrian/32/12078_2.png) [@WardBrian](https://discourse.mc-stan.org/u/WardBrian)\
**Post date:** [December 20, 2023, 7:12pm UTC](https://discourse.mc-stan.org/t/cmdstanpy-reduce-sum-doesnt-produce-executable/33637/2 "2023-12-20T19:12:01Z")

</div>

Can you enable debug logging (see [the documentation](https://cmdstanpy.readthedocs.io/en/v1.2.0/users-guide/outputs.html#logging)) and report what the output is when running this code?

---

<div class="post-metadata">

**Author:** ![mathDR](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/mathdr/32/1997_2.png) [@mathDR](https://discourse.mc-stan.org/u/mathDR)\
**Post date:** [December 20, 2023, 7:23pm UTC](https://discourse.mc-stan.org/t/cmdstanpy-reduce-sum-doesnt-produce-executable/33637/3 "2023-12-20T19:23:03Z")

</div>

Here is the whole output in `all.log`:

```no-highlight
14:20:53 - cmdstanpy - INFO - compiling stan file /Users/daniel.marthaler/dev/eligere/eligere/models/stan/redcard_reduce_sum.stan to exe file /Users/daniel.marthaler/dev/eligere/eligere/models/stan/redcard_reduce_sum
14:20:53 - cmdstanpy - DEBUG - cmd: make STANCFLAGS+=--filename-in-msg=redcard_reduce_sum.stan STAN_THREADS=TRUE /Users/daniel.marthaler/dev/eligere/eligere/models/stan/redcard_reduce_sum
cwd: /Users/daniel.marthaler/.cmdstan/cmdstan-2.33.1
14:20:57 - cmdstanpy - DEBUG - Console output:

--- Translating Stan model to C++ code ---
bin/stanc --filename-in-msg=redcard_reduce_sum.stan --o=/Users/daniel.marthaler/dev/eligere/eligere/models/stan/redcard_reduce_sum.hpp /Users/daniel.marthaler/dev/eligere/eligere/models/stan/redcard_reduce_sum.stan

--- Compiling, linking C++ code ---
clang++ -std=c++1y -Wno-unknown-warning-option -Wno-tautological-compare -Wno-sign-compare -D_REENTRANT -Wno-ignored-attributes -DSTAN_THREADS -I stan/lib/stan_math/lib/tbb_2020.3/include -O3 -I src -I stan/src -I stan/lib/rapidjson_1.1.0/ -I lib/CLI11-1.9.1/ -I stan/lib/stan_math/ -I stan/lib/stan_math/lib/eigen_3.4.0 -I stan/lib/stan_math/lib/boost_1.78.0 -I stan/lib/stan_math/lib/sundials_6.1.1/include -I stan/lib/stan_math/lib/sundials_6.1.1/src/sundials -DBOOST_DISABLE_ASSERTS -c -include-pch stan/src/stan/model/model_header_threads_15_0.hpp.gch -x c++ -o /Users/daniel.marthaler/dev/eligere/eligere/models/stan/redcard_reduce_sum.o /Users/daniel.marthaler/dev/eligere/eligere/models/stan/redcard_reduce_sum.hpp
In file included from /Users/daniel.marthaler/dev/eligere/eligere/models/stan/redcard_reduce_sum.hpp:1:
In file included from /Users/daniel.marthaler/.cmdstan/cmdstan-2.33.1/stan/src/stan/model/model_header.hpp:4:
In file included from /Users/daniel.marthaler/.cmdstan/cmdstan-2.33.1/stan/lib/stan_math/stan/math.hpp:19:
In file included from /Users/daniel.marthaler/.cmdstan/cmdstan-2.33.1/stan/lib/stan_math/stan/math/rev.hpp:10:
In file included from /Users/daniel.marthaler/.cmdstan/cmdstan-2.33.1/stan/lib/stan_math/stan/math/rev/fun.hpp:200:
In file included from /Users/daniel.marthaler/.cmdstan/cmdstan-2.33.1/stan/lib/stan_math/stan/math/prim/functor.hpp:16:
In file included from /Users/daniel.marthaler/.cmdstan/cmdstan-2.33.1/stan/lib/stan_math/stan/math/prim/functor/integrate_ode_rk45.hpp:6:
In file included from /Users/daniel.marthaler/.cmdstan/cmdstan-2.33.1/stan/lib/stan_math/stan/math/prim/functor/ode_rk45.hpp:9:
In file included from /Users/daniel.marthaler/.cmdstan/cmdstan-2.33.1/stan/lib/stan_math/lib/boost_1.78.0/boost/numeric/odeint.hpp:76:
In file included from /Users/daniel.marthaler/.cmdstan/cmdstan-2.33.1/stan/lib/stan_math/lib/boost_1.78.0/boost/numeric/odeint/integrate/observer_collection.hpp:23:
In file included from /Users/daniel.marthaler/.cmdstan/cmdstan-2.33.1/stan/lib/stan_math/lib/boost_1.78.0/boost/function.hpp:30:
In file included from /Users/daniel.marthaler/.cmdstan/cmdstan-2.33.1/stan/lib/stan_math/lib/boost_1.78.0/boost/function/detail/prologue.hpp:17:
In file included from /Users/daniel.marthaler/.cmdstan/cmdstan-2.33.1/stan/lib/stan_math/lib/boost_1.78.0/boost/function/function_base.hpp:21:
In file included from /Users/daniel.marthaler/.cmdstan/cmdstan-2.33.1/stan/lib/stan_math/lib/boost_1.78.0/boost/type_index.hpp:29:
In file included from /Users/daniel.marthaler/.cmdstan/cmdstan-2.33.1/stan/lib/stan_math/lib/boost_1.78.0/boost/type_index/stl_type_index.hpp:47:
/Users/daniel.marthaler/.cmdstan/cmdstan-2.33.1/stan/lib/stan_math/lib/boost_1.78.0/boost/container_hash/hash.hpp:132:33: warning: 'unary_function<const std::error_category *, unsigned long>' is deprecated [-Wdeprecated-declarations]
        struct hash_base : std::unary_function<T, std::size_t> {};
                                ^
/Users/daniel.marthaler/.cmdstan/cmdstan-2.33.1/stan/lib/stan_math/lib/boost_1.78.0/boost/container_hash/hash.hpp:692:18: note: in instantiation of template class 'boost::hash_detail::hash_base<const std::error_category *>' requested here
        : public boost::hash_detail::hash_base<T*>
                 ^
/Users/daniel.marthaler/.cmdstan/cmdstan-2.33.1/stan/lib/stan_math/lib/boost_1.78.0/boost/container_hash/hash.hpp:420:24: note: in instantiation of template class 'boost::hash<const std::error_category *>' requested here
        boost::hash<T> hasher;
                       ^
/Users/daniel.marthaler/.cmdstan/cmdstan-2.33.1/stan/lib/stan_math/lib/boost_1.78.0/boost/container_hash/hash.hpp:551:9: note: in instantiation of function template specialization 'boost::hash_combine<const std::error_category *>' requested here
        hash_combine(seed, &v.category());
        ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__functional/unary_function.h:23:29: note: 'unary_function<const std::error_category *, unsigned long>' has been explicitly marked deprecated here
struct _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 unary_function
                            ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__config:850:41: note: expanded from macro '_LIBCPP_DEPRECATED_IN_CXX11'
# define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED
                                        ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__config:835:49: note: expanded from macro '_LIBCPP_DEPRECATED'
# define _LIBCPP_DEPRECATED __attribute__ ((deprecated))
                                                ^
1 warning generated.
clang++ -std=c++1y -Wno-unknown-warning-option -Wno-tautological-compare -Wno-sign-compare -D_REENTRANT -Wno-ignored-attributes -DSTAN_THREADS -I stan/lib/stan_math/lib/tbb_2020.3/include -O3 -I src -I stan/src -I stan/lib/rapidjson_1.1.0/ -I lib/CLI11-1.9.1/ -I stan/lib/stan_math/ -I stan/lib/stan_math/lib/eigen_3.4.0 -I stan/lib/stan_math/lib/boost_1.78.0 -I stan/lib/stan_math/lib/sundials_6.1.1/include -I stan/lib/stan_math/lib/sundials_6.1.1/src/sundials -DBOOST_DISABLE_ASSERTS -Wl,-L,"/Users/daniel.marthaler/.cmdstan/cmdstan-2.33.1/stan/lib/stan_math/lib/tbb" -Wl,-rpath,"/Users/daniel.marthaler/.cmdstan/cmdstan-2.33.1/stan/lib/stan_math/lib/tbb" /Users/daniel.marthaler/dev/eligere/eligere/models/stan/redcard_reduce_sum.o src/cmdstan/main_threads.o -Wl,-L,"/Users/daniel.marthaler/.cmdstan/cmdstan-2.33.1/stan/lib/stan_math/lib/tbb" -Wl,-rpath,"/Users/daniel.marthaler/.cmdstan/cmdstan-2.33.1/stan/lib/stan_math/lib/tbb" stan/lib/stan_math/lib/sundials_6.1.1/lib/libsundials_nvecserial.a stan/lib/stan_math/lib/sundials_6.1.1/lib/libsundials_cvodes.a stan/lib/stan_math/lib/sundials_6.1.1/lib/libsundials_idas.a stan/lib/stan_math/lib/sundials_6.1.1/lib/libsundials_kinsol.a stan/lib/stan_math/lib/tbb/libtbb.dylib stan/lib/stan_math/lib/tbb/libtbbmalloc.dylib stan/lib/stan_math/lib/tbb/libtbbmalloc_proxy.dylib -o /Users/daniel.marthaler/dev/eligere/eligere/models/stan/redcard_reduce_sum
ld: warning: duplicate -rpath '/Users/daniel.marthaler/.cmdstan/cmdstan-2.33.1/stan/lib/stan_math/lib/tbb' ignored
rm -f /Users/daniel.marthaler/dev/eligere/eligere/models/stan/redcard_reduce_sum.o

14:20:57 - cmdstanpy - INFO - compiled model executable: /Users/daniel.marthaler/dev/eligere/eligere/models/stan/redcard_reduce_sum
14:20:57 - cmdstanpy - DEBUG - cmd: /Users/daniel.marthaler/dev/eligere/eligere/models/stan/redcard_reduce_sum info
cwd: None
14:20:58 - cmdstanpy - DEBUG - Command ['/Users/daniel.marthaler/dev/eligere/eligere/models/stan/redcard_reduce_sum', 'info']
	terminated by signal 9 Unknown error: -9
14:20:58 - cmdstanpy - DEBUG - cmd: /Users/daniel.marthaler/dev/eligere/eligere/models/stan/redcard_reduce_sum info
cwd: None
14:20:58 - cmdstanpy - DEBUG - Command: ['/Users/daniel.marthaler/dev/eligere/eligere/models/stan/redcard_reduce_sum', 'info']
failed with error [Errno 2] No such file or directory: '/Users/daniel.marthaler/dev/eligere/eligere/models/stan/redcard_reduce_sum'

14:20:58 - cmdstanpy - DEBUG - input tempfile: /var/folders/rk/49593z6j4xx_hxmgmkhxh50w0000gq/T/tmpujy0cthj/5hwl96_q.json
14:20:58 - cmdstanpy - INFO - CmdStan start processing
14:20:58 - cmdstanpy - DEBUG - idx 0
14:20:58 - cmdstanpy - DEBUG - idx 1
14:20:58 - cmdstanpy - DEBUG - running CmdStan, num_threads: 4
14:20:58 - cmdstanpy - DEBUG - idx 2
14:20:58 - cmdstanpy - DEBUG - running CmdStan, num_threads: 4
14:20:58 - cmdstanpy - DEBUG - idx 3
14:20:58 - cmdstanpy - DEBUG - CmdStan args: ['/Users/daniel.marthaler/dev/eligere/eligere/models/stan/redcard_reduce_sum', 'id=1', 'random', 'seed=81543', 'data', 'file=/var/folders/rk/49593z6j4xx_hxmgmkhxh50w0000gq/T/tmpujy0cthj/5hwl96_q.json', 'output', 'file=/var/folders/rk/49593z6j4xx_hxmgmkhxh50w0000gq/T/tmpujy0cthj/redcard_reduce_sum1ltxuvpk/redcard_reduce_sum-20231220142058_1.csv', 'method=sample', 'algorithm=hmc', 'adapt', 'engaged=1']
14:20:58 - cmdstanpy - DEBUG - running CmdStan, num_threads: 4
14:20:58 - cmdstanpy - DEBUG - CmdStan args: ['/Users/daniel.marthaler/dev/eligere/eligere/models/stan/redcard_reduce_sum', 'id=2', 'random', 'seed=81543', 'data', 'file=/var/folders/rk/49593z6j4xx_hxmgmkhxh50w0000gq/T/tmpujy0cthj/5hwl96_q.json', 'output', 'file=/var/folders/rk/49593z6j4xx_hxmgmkhxh50w0000gq/T/tmpujy0cthj/redcard_reduce_sum1ltxuvpk/redcard_reduce_sum-20231220142058_2.csv', 'method=sample', 'algorithm=hmc', 'adapt', 'engaged=1']
14:20:58 - cmdstanpy - DEBUG - running CmdStan, num_threads: 4
14:20:58 - cmdstanpy - DEBUG - CmdStan args: ['/Users/daniel.marthaler/dev/eligere/eligere/models/stan/redcard_reduce_sum', 'id=3', 'random', 'seed=81543', 'data', 'file=/var/folders/rk/49593z6j4xx_hxmgmkhxh50w0000gq/T/tmpujy0cthj/5hwl96_q.json', 'output', 'file=/var/folders/rk/49593z6j4xx_hxmgmkhxh50w0000gq/T/tmpujy0cthj/redcard_reduce_sum1ltxuvpk/redcard_reduce_sum-20231220142058_3.csv', 'method=sample', 'algorithm=hmc', 'adapt', 'engaged=1']
14:20:58 - cmdstanpy - DEBUG - CmdStan args: ['/Users/daniel.marthaler/dev/eligere/eligere/models/stan/redcard_reduce_sum', 'id=4', 'random', 'seed=81543', 'data', 'file=/var/folders/rk/49593z6j4xx_hxmgmkhxh50w0000gq/T/tmpujy0cthj/5hwl96_q.json', 'output', 'file=/var/folders/rk/49593z6j4xx_hxmgmkhxh50w0000gq/T/tmpujy0cthj/redcard_reduce_sum1ltxuvpk/redcard_reduce_sum-20231220142058_4.csv', 'method=sample', 'algorithm=hmc', 'adapt', 'engaged=1']
14:20:58 - cmdstanpy - INFO - CmdStan done processing.
14:20:58 - cmdstanpy - DEBUG - runset
RunSet: chains=4, chain_ids=[1, 2, 3, 4], num_processes=4
 cmd (chain 1):
	['/Users/daniel.marthaler/dev/eligere/eligere/models/stan/redcard_reduce_sum', 'id=1', 'random', 'seed=81543', 'data', 'file=/var/folders/rk/49593z6j4xx_hxmgmkhxh50w0000gq/T/tmpujy0cthj/5hwl96_q.json', 'output', 'file=/var/folders/rk/49593z6j4xx_hxmgmkhxh50w0000gq/T/tmpujy0cthj/redcard_reduce_sum1ltxuvpk/redcard_reduce_sum-20231220142058_1.csv', 'method=sample', 'algorithm=hmc', 'adapt', 'engaged=1']
 retcodes=[-1, -1, -1, -1]
 per-chain output files (showing chain 1 only):
 csv_file:
	/var/folders/rk/49593z6j4xx_hxmgmkhxh50w0000gq/T/tmpujy0cthj/redcard_reduce_sum1ltxuvpk/redcard_reduce_sum-20231220142058_1.csv
 console_msgs (if any):
	/var/folders/rk/49593z6j4xx_hxmgmkhxh50w0000gq/T/tmpujy0cthj/redcard_reduce_sum1ltxuvpk/redcard_reduce_sum-20231220142058_0-stdout.txt
14:20:58 - cmdstanpy - DEBUG - Chain 1 console:

```

---

<div class="post-metadata">

**Author:** ![WardBrian](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/wardbrian/32/12078_2.png) [@WardBrian](https://discourse.mc-stan.org/u/WardBrian)\
**Post date:** [December 20, 2023, 7:34pm UTC](https://discourse.mc-stan.org/t/cmdstanpy-reduce-sum-doesnt-produce-executable/33637/4 "2023-12-20T19:34:12Z")

</div>

This output is helpful, thanks! I think it implies that an executable was created, but it seems like running it immediately causes some failure, even in simple methods like `info`

Can you navigate to the folder and 1) confirm that there is a `redcard_reduce_sum` executable there, and 2) run the following commands and share their outputs? `ldd redcard_reduce_sum` and `./recard_reduce_sum help`

---

<div class="post-metadata">

**Author:** ![mathDR](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/mathdr/32/1997_2.png) [@mathDR](https://discourse.mc-stan.org/u/mathDR)\
**Post date:** [December 20, 2023, 7:40pm UTC](https://discourse.mc-stan.org/t/cmdstanpy-reduce-sum-doesnt-produce-executable/33637/5 "2023-12-20T19:40:20Z")

</div>

There is _not_ an executable produced when I compile with the `stan_threads` option.

One thing I noticed was the warning produced

```no-highlight
ld: warning: duplicate -rpath '/Users/daniel.marthaler/.cmdstan/cmdstan-2.33.1/stan/lib/stan_math/lib/tbb' ignored

```

and some googling produced [this page](https://stackoverflow.com/questions/77164140/ld-warning-ignoring-duplicate-libraries-lgcc-after-the-recent-update-of-xc). which implies that there may be something fishy with xcode 15? (I only use the command line tools but still…)

I am currently trying to downgrade to xcode 14 and going to rerun (since I am _sure_ I could run this example a while ago…)

---

<div class="post-metadata">

**Author:** ![WardBrian](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/wardbrian/32/12078_2.png) [@WardBrian](https://discourse.mc-stan.org/u/WardBrian)\
**Post date:** [December 20, 2023, 7:54pm UTC](https://discourse.mc-stan.org/t/cmdstanpy-reduce-sum-doesnt-produce-executable/33637/6 "2023-12-20T19:54:58Z")

</div>

That warning is spurious and will not exist in future versions (see [Don't duplicate -rpath for TBB by WardBrian · Pull Request #2952 · stan-dev/math · GitHub](https://github.com/stan-dev/math/pull/2952))

Can you try moving the .stan file to `/Users/daniel.marthaler/.cmdstan/cmdstan-2.33.1` and then running `make STAN_THREADS=1 redcard_reduce_sum`?

---

<div class="post-metadata">

**Author:** ![mathDR](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/mathdr/32/1997_2.png) [@mathDR](https://discourse.mc-stan.org/u/mathDR)\
**Post date:** [December 20, 2023, 8:20pm UTC](https://discourse.mc-stan.org/t/cmdstanpy-reduce-sum-doesnt-produce-executable/33637/7 "2023-12-20T20:20:55Z")

</div>

```no-highlight
(cmdstanpy) 15:19:40 ~/.cmdstan/cmdstan-2.33.1 $ make STAN_THREADS=1 redcard_reduce_sum      

--- Translating Stan model to C++ code ---
bin/stanc --o=redcard_reduce_sum.hpp redcard_reduce_sum.stan

--- Compiling, linking C++ code ---
clang++ -std=c++1y -Wno-unknown-warning-option -Wno-tautological-compare -Wno-sign-compare -D_REENTRANT -Wno-ignored-attributes -DSTAN_THREADS -I stan/lib/stan_math/lib/tbb_2020.3/include -O3 -I src -I stan/src -I stan/lib/rapidjson_1.1.0/ -I lib/CLI11-1.9.1/ -I stan/lib/stan_math/ -I stan/lib/stan_math/lib/eigen_3.4.0 -I stan/lib/stan_math/lib/boost_1.78.0 -I stan/lib/stan_math/lib/sundials_6.1.1/include -I stan/lib/stan_math/lib/sundials_6.1.1/src/sundials -DBOOST_DISABLE_ASSERTS -c -include-pch stan/src/stan/model/model_header_threads_15_0.hpp.gch -x c++ -o redcard_reduce_sum.o redcard_reduce_sum.hpp
error: PCH file built from a different branch ((clang-1500.0.40.1)) than the compiler ((clang-1500.1.0.2.5))
1 error generated.
make: *** [redcard_reduce_sum] Error 1

```

I will rebuild cmdstan right now and retry

Note I did just do a software update (to try to “fix” the xcode thing so that may have also updated my compiler)

---

<div class="post-metadata">

**Author:** ![mathDR](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/mathdr/32/1997_2.png) [@mathDR](https://discourse.mc-stan.org/u/mathDR)\
**Post date:** [December 20, 2023, 8:27pm UTC](https://discourse.mc-stan.org/t/cmdstanpy-reduce-sum-doesnt-produce-executable/33637/8 "2023-12-20T20:27:45Z")

</div>

Okay, running `make STAN_THREADS=1 redcard_reduce_sum` in the `cmdstan-2.33.1` directory produced an executable.

---

<div class="post-metadata">

**Author:** ![mathDR](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/mathdr/32/1997_2.png) [@mathDR](https://discourse.mc-stan.org/u/mathDR)\
**Post date:** [December 20, 2023, 8:32pm UTC](https://discourse.mc-stan.org/t/cmdstanpy-reduce-sum-doesnt-produce-executable/33637/9 "2023-12-20T20:32:41Z")

</div>

Note `ldd` doesn’t exist on mac, but I ran (in the `cmdstan-2.33.1` directory)

```no-highlight
otool -L redcard_reduce_sum

```

and got

```no-highlight
redcard_reduce_sum:
	@rpath/libtbb.dylib (compatibility version 0.0.0, current version 0.0.0)
	@rpath/libtbbmalloc.dylib (compatibility version 0.0.0, current version 0.0.0)
	@rpath/libtbbmalloc_proxy.dylib (compatibility version 0.0.0, current version 0.0.0)
	/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1600.157.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1336.61.1)

```

---

<div class="post-metadata">

**Author:** ![mathDR](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/mathdr/32/1997_2.png) [@mathDR](https://discourse.mc-stan.org/u/mathDR)\
**Post date:** [December 20, 2023, 8:34pm UTC](https://discourse.mc-stan.org/t/cmdstanpy-reduce-sum-doesnt-produce-executable/33637/10 "2023-12-20T20:34:55Z")

</div>

Now:  
`file redcard_reduce_sum`  
returns

```no-highlight
redcard_reduce_sum: Mach-O 64-bit executable arm64

```

running

```no-highlight
./redcard_reduce_sum help

```

returns

```no-highlight
zsh: killed ./redcard_reduce_sum help

```

and now the executable is gone! Like, doesn’t exist anymore…

---

<div class="post-metadata">

**Author:** ![WardBrian](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/wardbrian/32/12078_2.png) [@WardBrian](https://discourse.mc-stan.org/u/WardBrian)\
**Post date:** [December 20, 2023, 8:39pm UTC](https://discourse.mc-stan.org/t/cmdstanpy-reduce-sum-doesnt-produce-executable/33637/11 "2023-12-20T20:39:54Z")

</div>

> [@mathDR](#):
>
> and now the executable is gone

Wow, that is impressive!

Are you running the native terminal or under Rosetta?

---

<div class="post-metadata">

**Author:** ![mathDR](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/mathdr/32/1997_2.png) [@mathDR](https://discourse.mc-stan.org/u/mathDR)\
**Post date:** [December 20, 2023, 8:41pm UTC](https://discourse.mc-stan.org/t/cmdstanpy-reduce-sum-doesnt-produce-executable/33637/12 "2023-12-20T20:41:22Z")

</div>

native terminal (but using zsh and not bash)

---

<div class="post-metadata">

**Author:** ![mathDR](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/mathdr/32/1997_2.png) [@mathDR](https://discourse.mc-stan.org/u/mathDR)\
**Post date:** [December 20, 2023, 8:42pm UTC](https://discourse.mc-stan.org/t/cmdstanpy-reduce-sum-doesnt-produce-executable/33637/13 "2023-12-20T20:42:17Z")

</div>

It is like, the executable gets made from the compiler, then Stan tries to run it and it disappears!

I have never heard of such a thing!

---

<div class="post-metadata">

**Author:** ![WardBrian](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/wardbrian/32/12078_2.png) [@WardBrian](https://discourse.mc-stan.org/u/WardBrian)\
**Post date:** [December 20, 2023, 9:10pm UTC](https://discourse.mc-stan.org/t/cmdstanpy-reduce-sum-doesnt-produce-executable/33637/14 "2023-12-20T21:10:55Z")

</div>

I found some similar-sounding issues which imply it might be a code signing issue?

> <https://github.com/golang/go/issues/42684>
>
> On the production Apple Silicon machines, Go binaries are killed at start. https…://github.com/golang/go/issues/38485#issuecomment-729301832
> 
> It looks like all binaries need to be codesigned now, and indeed running \`codesign -s -\` on them lets them run correctly.
> 
> This stops \`go test\` and \`go run\` from working, and requires an extra step after \`go build\` to get a functional binary.
> 
> This also affects the bootstrapped compiler itself.

> **[Dune built executable killed by zsh on macOS](https://discuss.ocaml.org/t/dune-built-executable-killed-by-zsh-on-macos/7113/10?u=wardbrian)**
>
> This is almost definitely a codesigning bug. The new ARM64 Macs have much stricter validation when it comes to codesigning, and the kernel will refuse to run unsigned code (and sends a SIGTERM). It is strange, though, how involving dune breaks...

I’m pinging some people who I believe have Apple Silicon macs to see if they’ve run into this at all @andrjohns @rok_cesnovar @spinkney

---

<div class="post-metadata">

**Author:** ![andrjohns](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/andrjohns/32/15297_2.png) [@andrjohns](https://discourse.mc-stan.org/u/andrjohns)\
**Post date:** [December 20, 2023, 11:26pm UTC](https://discourse.mc-stan.org/t/cmdstanpy-reduce-sum-doesnt-produce-executable/33637/15 "2023-12-20T23:26:01Z")

</div>

Can you rebuild the executable and then run:

```no-highlight
lldb ./redcard_reduce_sum help
run

```

And post the output?

---

<div class="post-metadata">

**Author:** ![mathDR](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/mathdr/32/1997_2.png) [@mathDR](https://discourse.mc-stan.org/u/mathDR)\
**Post date:** [December 21, 2023, 1:53am UTC](https://discourse.mc-stan.org/t/cmdstanpy-reduce-sum-doesnt-produce-executable/33637/16 "2023-12-21T01:53:05Z")

</div>

```no-highlight
(cmdstanpy) 20:52:17 ~/.cmdstan/cmdstan-2.33.1 $ lldb ./redcard_reduce_sum help

(lldb) target create "./redcard_reduce_sum"

Current executable set to '/Users/daniel.marthaler/.cmdstan/cmdstan-2.33.1/redcard_reduce_sum' (arm64).

(lldb) settings set -- target.run-args "help"

(lldb) run

**error:** process exited with status -1 (no such process.)

(lldb)

```

---

<div class="post-metadata">

**Author:** ![mathDR](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/mathdr/32/1997_2.png) [@mathDR](https://discourse.mc-stan.org/u/mathDR)\
**Post date:** [December 21, 2023, 3:01am UTC](https://discourse.mc-stan.org/t/cmdstanpy-reduce-sum-doesnt-produce-executable/33637/17 "2023-12-21T03:01:04Z")

</div>

[This page](https://developer.apple.com/forums/thread/737854) implies there may be a linker issue with Xcode 15?

If I could figure out how to downgrade xcode back to 14 I could pinpoint this. Alas, I am out for the Holiday but will revisit next week…

---

<div class="post-metadata">

**Author:** ![andrjohns](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/andrjohns/32/15297_2.png) [@andrjohns](https://discourse.mc-stan.org/u/andrjohns)\
**Post date:** [December 21, 2023, 7:47am UTC](https://discourse.mc-stan.org/t/cmdstanpy-reduce-sum-doesnt-produce-executable/33637/18 "2023-12-21T07:47:55Z")

</div>

Very bizarre, I can’t replicate this at all.

Are you running the terminal in a conda environment or similar?

Can you try the following dummy test to see if you can compile and execute anything?

```sh
echo "#include <iostream> \n int main() { std::cout << \"success\" << std::endl; }" > test.cpp
clang++ test.cpp -o test
./test

```

---

<div class="post-metadata">

**Author:** ![mathDR](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/mathdr/32/1997_2.png) [@mathDR](https://discourse.mc-stan.org/u/mathDR)\
**Post date:** [December 21, 2023, 12:04pm UTC](https://discourse.mc-stan.org/t/cmdstanpy-reduce-sum-doesnt-produce-executable/33637/19 "2023-12-21T12:04:35Z")

</div>

Oh it probably got lost in all the messages, but everything “works” (can compile and sample) if I do NOT compile with STAN THREADS.

---

<div class="post-metadata">

**Author:** ![mathDR](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/mathdr/32/1997_2.png) [@mathDR](https://discourse.mc-stan.org/u/mathDR)\
**Post date:** [December 21, 2023, 2:01pm UTC](https://discourse.mc-stan.org/t/cmdstanpy-reduce-sum-doesnt-produce-executable/33637/20 "2023-12-21T14:01:41Z")

</div>

also, i am using a fresh `pyenv` environment (python 3.9.10) and I

```no-highlight
pip install cmdstanpy

```

also:

```no-highlight
pip freeze

```

yields:

```no-highlight
aiohttp==3.9.1
aiosignal==1.3.1
algo-dis==0.1.4
astroid==2.11.7
async-timeout==4.0.3
attrs==23.1.0
black==24.1a1
boto3==1.34.4
botocore==1.34.4
certifi==2023.11.17
charset-normalizer==3.3.2
click==8.1.7
cmdstanpy==1.2.0
croniter==2.0.1
dill==0.3.7
exceptiongroup==1.2.0
fire==0.5.0
frozenlist==1.4.1
futura==1.30.6
idna==3.6
iniconfig==2.0.0
isort==5.13.2
Jinja2==3.1.2
jmespath==1.0.1
joblib==1.3.2
jsonref==1.1.0
jsonschema==4.7.0
lazy-object-proxy==1.10.0
MarkupSafe==2.1.3
mccabe==0.7.0
multidict==6.0.4
mypy-extensions==1.0.0
numpy==1.26.2
packaging==23.2
pandas==2.1.4
pathspec==0.12.1
platformdirs==4.1.0
pluggy==1.3.0
pylint==2.13.8
pyrsistent==0.20.0
pytest==7.4.3
python-dateutil==2.8.2
pytz==2023.3.post1
PyYAML==6.0.1
requests==2.31.0
ruamel.yaml==0.18.5
ruamel.yaml.clib==0.2.8
s3transfer==0.9.0
sf-boto==1.1.0
sf-request-headers==0.1.3
sh==2.0.6
six==1.16.0
stanio==0.3.0
tabulate==0.9.0
termcolor==2.4.0
tomli==2.0.1
tqdm==4.66.1
transdag==0.0.48
typing_extensions==4.9.0
tzdata==2023.3
urllib3==1.26.18
wrapt==1.16.0
yarl==1.9.4

```

[Next page](https://discourse.mc-stan.org/t/cmdstanpy-reduce-sum-doesnt-produce-executable/33637.md?page=2)
