-
-
Notifications
You must be signed in to change notification settings - Fork 74
Open
Description
I've run into a somewhat odd (and likely edge-case) situation where CmdStanModel.sample
behaves unexpectedly after a call to os.fork
. I'm providing pseudocode now in the hopes that there is a fairly simple explanation, but happy to make a minimum working example if need be.
Say I run something structured like the following:
import os
from cmdstanpy import CmdStanModel
def run_job():
# Compile the model
mod = CmdStanModel(stanfile, cpp_options={"STAN_THREADS": True})
# Run sampling on a detached child process
pid = os.fork()
if pid == 0:
os.setsid()
mod.sample(data = data, chains=4)
os._exit()
else:
return pid
Even though my CPU has 32 cores, this will only run two chains at once--specifically, Chains 1 and 3 run, then Chains 2 and 4 run. If, however, I remove the cpp_options={"STAN_THREADS": True}
kwarg, then everything behaves as expected: all chains sample in parallel.
Is there any immediate explanation for this discrepancy in behavior?
Metadata
Metadata
Assignees
Labels
No labels