Skip to content

Commit 6eade46

Browse files
committed
updated docs for parallelization
1 parent 79c1df6 commit 6eade46

2 files changed

Lines changed: 41 additions & 18 deletions

File tree

docsrc/hello_world.rst

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ The function :func:`~cmdstan_path` returns the value of this environment variabl
6161
# inspect model object
6262
print(model)
6363
64+
# inspect compiled model
65+
print(model.exe_info)
6466
6567
Data inputs
6668
^^^^^^^^^^^
@@ -184,6 +186,31 @@ to a specified directory.
184186
fit.save_csvfiles(dir='some/path')
185187
186188
189+
Parallelization
190+
^^^^^^^^^^^^^^^
191+
192+
The Stan language
193+
`reduce_sum <https://mc-stan.org/docs/stan-users-guide/reduce-sum.html>`__
194+
function provides within-chain parallelization.
195+
For models which require computing the sum of a number of independent function evaluations,
196+
e.g., when evaluating a number of conditionally independent terms in a log-likelihood,
197+
the ``reduce_sum`` function is used to parallelize this computation.
198+
199+
As of version CmdStan 2.28, it is possible to run the
200+
NUTS-HMC sampler on
201+
multiple chains from within a single executable using threads.
202+
This has the potential to speed up sampling. It also
203+
reduces the overall memory footprint required for sampling as
204+
all chains share the same copy of data.the input data.
205+
When using within-chain parallelization all chains started within a single executable can share all the available threads and once a chain finishes the threads will be reused.
206+
207+
Both within-chain and cross-chain parallelization use the
208+
Intel Threading Building Blocks (TBB) library.
209+
In order to do either, the Stan model must be compiled with
210+
C++ compiler flag ``STAN_THREADS``. While any value can be used,
211+
we recommend the value ``TRUE``.
212+
213+
187214
Progress bar
188215
^^^^^^^^^^^^
189216

@@ -201,9 +228,8 @@ To suppress the progress bar, specify argument ``show_progress=False``.
201228
202229
fit = model.sample(data=data_file, show_progress=False)
203230
204-
To see the CmdStan console outputs instead, specify ``show_console=True``.
231+
To see the CmdStan console outputs instead of progress bars, specify ``show_console=True``.
205232

206-
207233
.. ipython:: python
208234
:verbatim:
209235

docsrc/workflow.rst

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -87,25 +87,22 @@ specify options for each compilation step.
8787
Options are specified as a Python dictionary mapping
8888
compiler option names to appropriate values.
8989

90-
To use Stan's
91-
`parallelization <https://mc-stan.org/docs/cmdstan-guide/parallelization.html>`__
92-
features, Stan programs must be compiled with the appropriate C++ compiler flags.
93-
If you are running GPU hardware and wish to use the OpenCL framework to speed up matrix operations,
94-
you must set the C++ compiler flag **STAN_OPENCL**.
95-
For high-level within-chain parallelization using the Stan language `reduce_sum` function,
96-
it's necessary to set the C++ compiler flag **STAN_THREADS**. While any value can be used,
97-
we recommend the value ``True``.
98-
99-
For example, given Stan program named 'proc_parallel.stan', you can take
100-
advantage of both kinds of parallelization by specifying the compiler options when instantiating
101-
the model:
90+
In order parallelize within-chain computations using the
91+
Stan language ``reduce_sum`` function, or to parallelize
92+
running the NUTS-HMC sampler across chains,
93+
the Stan model must be compiled with
94+
C++ compiler flag **STAN_THREADS**.
95+
While any value can be used,
96+
we recommend the value ``True``, e.g.:
97+
10298

10399
.. code-block:: python
104100
105-
proc_parallel_model = CmdStanModel(
106-
stan_file='proc_parallel.stan',
107-
cpp_options={"STAN_THREADS": True, "STAN_OPENCL": True},
108-
)
101+
import os
102+
from cmdstanpy import CmdStanModel
103+
104+
my_stanfile = os.path.join('.', 'my_model.stan')
105+
my_model = CmdStanModel(stan_file=my_stanfile, cpp_options={'STAN_THREADS':'true'})
109106
110107
111108
Assemble input and initialization data

0 commit comments

Comments
 (0)