# Cmdstan installation error

**URL:** <https://discourse.mc-stan.org/t/cmdstan-installation-error/32900>\
**Category:** CmdStan\
**Tags:** installation, cmdstanr\
**Created:** [September 26, 2023, 4:59pm UTC](https://discourse.mc-stan.org/t/cmdstan-installation-error/32900 "2023-09-26T16:59:24Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![cjsrussell](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/cjsrussell/32/17165_2.png) [@cjsrussell](https://discourse.mc-stan.org/u/cjsrussell)\
**Post date:** [September 26, 2023, 4:59pm UTC](https://discourse.mc-stan.org/t/cmdstan-installation-error/32900/1 "2023-09-26T16:59:24Z")

</div>

I am trying to install cmdstand to then use with cmdstanr but the installation fails whenever I try. I was following the install guide here:

[Getting started with CmdStanR • cmdstanr (mc-stan.org)](https://mc-stan.org/cmdstanr/articles/cmdstanr.html)

I am using windows 11.

This is the error message:

```plaintext
> install_cmdstan(cores = 2)
The C++ toolchain required for CmdStan is setup properly!
trying URL 'https://api.github.com/repos/stan-dev/cmdstan/releases/latest'
Content type 'application/json; charset=utf-8' length 14650 bytes (14 KB)
downloaded 14 KB

* Latest CmdStan release is v2.33.1
* Installing CmdStan v2.33.1 in C:/Users/conna/Documents/.cmdstan/cmdstan-2.33.1
* Downloading cmdstan-2.33.1.tar.gz from GitHub...
trying URL 'https://github.com/stan-dev/cmdstan/releases/download/v2.33.1/cmdstan-2.33.1.tar.gz'
Content type 'application/octet-stream' length 51051295 bytes (48.7 MB)
downloaded 48.7 MB

* Download complete
* Unpacking archive...
Error in file(file, ifelse(append, "a", "w")) : 
  cannot open the connection
In addition: Warning message:
In file(file, ifelse(append, "a", "w")) :
  cannot open file 'C:/Users/conna/Documents/.cmdstan/cmdstan-2.33.1/make/local': No such file or directory

```

Any advice would be appreciated!

---

<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:** [September 26, 2023, 5:23pm UTC](https://discourse.mc-stan.org/t/cmdstan-installation-error/32900/2 "2023-09-26T17:23:14Z")

</div>

It looks like there are some file read issues, let’s try manually downloading and untar-ing the `cmdstan` release, then call `cmdstanr` to build and install.

Can you try:

```r
# Delete existing folder (if present)
unlink("C:/Users/conna/Documents/.cmdstan/cmdstan-2.33.1", recursive = TRUE)

download.file(url = "https://github.com/stan-dev/cmdstan/releases/download/v2.33.1/cmdstan-2.33.1.tar.gz",
              destfile = "C:/Users/conna/.cmdstan/cmdstan-2.33.1.tar.gz")

utils::untar(
  "C:/Users/conna/.cmdstan/cmdstan-2.33.1.tar.gz",
  exdir = "C:/Users/conna/.cmdstan/cmdstan-2.33.1",
  extras = "--strip-components 1"
)

cmdstanr::set_cmdstan_path("C:/Users/conna/.cmdstan/cmdstan-2.33.1")
cmdstanr::rebuild_cmdstan(cores = 2)

```

---

<div class="post-metadata">

**Author:** ![cjsrussell](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/cjsrussell/32/17165_2.png) [@cjsrussell](https://discourse.mc-stan.org/u/cjsrussell)\
**Post date:** [September 26, 2023, 5:40pm UTC](https://discourse.mc-stan.org/t/cmdstan-installation-error/32900/3 "2023-09-26T17:40:14Z")

</div>

So that didn’t work either. But It did let me know something was seriously up. This is a clean windows install but somehow my documents directory had become read only…

Fixed the permissions and all good. Thanks!

---

<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:** [September 26, 2023, 5:41pm UTC](https://discourse.mc-stan.org/t/cmdstan-installation-error/32900/4 "2023-09-26T17:41:22Z")

</div>

Yep, that’ll do it! Glad to hear it all worked out

---

<div class="post-metadata">

**Author:** ![cjsrussell](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/cjsrussell/32/17165_2.png) [@cjsrussell](https://discourse.mc-stan.org/u/cjsrussell)\
**Post date:** [September 26, 2023, 8:48pm UTC](https://discourse.mc-stan.org/t/cmdstan-installation-error/32900/5 "2023-09-26T20:48:45Z")

</div>

So I did a clean install, and everything seemed to work fine. But now I get the following error when compiling a model with the cmdstanr backend and opencl.

Can’t find an example of a similar error anywhere else.

```plaintext
C:/rtools43/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe
: cannot find -lOpenCL: No such file or directory

collect2.exe: error: ld returned 1 exit status

mingw32-make: *** [make/program:59: C:\Users\conna\AppData\Local\Temp\RtmpoFS74o\model-39a83157ae8.exe] Error 1

```

---

<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:** [September 26, 2023, 8:52pm UTC](https://discourse.mc-stan.org/t/cmdstan-installation-error/32900/6 "2023-09-26T20:52:50Z")

</div>

Have you completed the setup steps for OpenCL from the manual: [18 Parallelization | CmdStan User’s Guide](https://mc-stan.org/docs/cmdstan-guide/parallelization.html#opencl)

---

<div class="post-metadata">

**Author:** ![cjsrussell](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/cjsrussell/32/17165_2.png) [@cjsrussell](https://discourse.mc-stan.org/u/cjsrussell)\
**Post date:** [September 26, 2023, 9:24pm UTC](https://discourse.mc-stan.org/t/cmdstan-installation-error/32900/7 "2023-09-26T21:24:17Z")

</div>

Yep! No issues arose there.

I’m testing it with this relatively simple model in brms:

```plaintext
testmod <- brm(belief ~ rebel_troll + rebel_act + rebel_all + choice_norms + indiv_collectivism,
                  data = dat1,
                  family = cumulative(link ="probit"), 
                  iter = 4000,
                  warmup = 1000, 
                  chains = 3,
                  cores = 2,
                  opencl = opencl(c(0, 0)),
                  seed = 2023, 
                  backend = "cmdstanr")

```

The model works when specified without opencl

---

<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:** [September 26, 2023, 9:27pm UTC](https://discourse.mc-stan.org/t/cmdstan-installation-error/32900/8 "2023-09-26T21:27:24Z")

</div>

What was the output that you got from the `clinfo` command?

---

<div class="post-metadata">

**Author:** ![cjsrussell](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/cjsrussell/32/17165_2.png) [@cjsrussell](https://discourse.mc-stan.org/u/cjsrussell)\
**Post date:** [September 26, 2023, 9:31pm UTC](https://discourse.mc-stan.org/t/cmdstan-installation-error/32900/9 "2023-09-26T21:31:16Z")

</div>

It has all the info for my AMD GPU, including the OpenCl version 2.0, if that is relevant.

That is the only device listed as my cpu (also AMD) doesn’t have official opencl support

---

<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:** [September 26, 2023, 9:49pm UTC](https://discourse.mc-stan.org/t/cmdstan-installation-error/32900/10 "2023-09-26T21:49:30Z")

</div>

Looks like you’ll need to update your compilation flags to correctly find the installed library. Can you run:

```r
cpp_options <- list(
    "LDLIBS_OPENCL" = "-L'C:/Program Files (x86)/OCL_SDK_Light/lib/x86_64' -lOpenCl"
)
cmdstan_make_local(cpp_options = cpp_options,append = TRUE)

```

And then try the model again?

---

<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:** [September 27, 2023, 10:07am UTC](https://discourse.mc-stan.org/t/cmdstan-installation-error/32900/11 "2023-09-27T10:07:36Z")

</div>

Also as an FYI we’ll add a setup/config step to `cmdstanr` ([GH issue](https://github.com/stan-dev/cmdstanr/issues/858)) to automatically handle OpenCL setup in the future, so make sure to let me know if there have been any other steps that you’ve had to complete that weren’t in the manual

---

<div class="post-metadata">

**Author:** ![cjsrussell](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/cjsrussell/32/17165_2.png) [@cjsrussell](https://discourse.mc-stan.org/u/cjsrussell)\
**Post date:** [September 27, 2023, 10:17am UTC](https://discourse.mc-stan.org/t/cmdstan-installation-error/32900/12 "2023-09-27T10:17:28Z")

</div>

Oh cool, that will be useful I imagine. I didn’t need to do any other steps than mentioned here. The first issue In the thread was was obviously a file permissions bug on my end, and the second one was solved with your above fix (updating compilation flags).

In the end the model using opencl is actually quite a bit slower :'), but this is probably just a function of the test models I am running.
