Is it possible to run Julia / Turing sampling with multicores without using the command line or the env file

Might be a silly question, but I am wondering if it is possible to run MCMC sampling from a Turing model using the multiple cores of the CPU without having to start Julia in a particular way / setting environment variables.

The reason is that I would like my script to be as reproducible as possible and not depend on other (env) files or starting parameters.

In R with rstanarm/brms, one can “seamlessly” use multiple cores just by setting cores=4 in the sampling functionb, but in Turing, when using:

sample(mymod, NUTS(), MCMCThreads(), 1000, 4)

It says Warning: Only a single thread available: MCMC chains are not sampled in parallel

After investigation, it seems like the amount of threads must be set from the start (multithreading official docs) using $ julia --threads 4

But is there a way to do that from the Julia REPL itself?

Well you can’t really add threads to a currently running Julia session (yet) without using some C-level hacking.
The simplest thing I can think to achieve what you want is using Distributed.jl to create a new child Julia process with the desired number threads and run the computation in there. Afterwards you can kill of the process or keep it around for reuse in future computations.