Skip to content

Use of thread-local variables in AbstractMCMC #128

@astrozot

Description

@astrozot

I need to sample a distribution for which the calculation of the log-likelihood is particularly time consuming. To speed-up calculations, it is beneficial to pass to the likelihood mutable data that (1) partially contain pre-computed values and (2) can be modified by the log-likelihood depending on the specific set of parameters passed to each call.

It would be relatively easy to implement this on a sequential (non-parallel) execution of a sampling, since I could attach the mutable data to the object representing the distribution. Problems arise however for parallel processing: in this case I would need to have n copies of the mutable data, one for each task.

One way could be to store n-copies of the data and access them in each log-likelihood call using the threadid(), but as clarified here this is no longer correct.

Another possibility would be to use a lock, but this would cancel much of the benefits of going parallel, as the mutable data are used during all the loglikelihood computation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions