Skip to content

Spice makes BSK simulations not thread safe #220

@bbercoviciUspace

Description

@bbercoviciUspace

Describe the bug
I ran a parallel simulation featuring multiple instances of SimulationBaseClass , each of them featuring a spiceInterface module. I was expecting all simulations to complete without hurdle, but ended up seeing the multiprocessing.imap holding the individual simulation executors come to a stall, with occasional error messages popping up in the terminal.

The data kernel de430.bsp even got corrupted in the process as its sha1sum turned out different as the one shipped with Basilisk.

To reproduce
Steps to reproduce the behavior:

  1. Add module 'spiceInterface' to a 'SimulationBaseClass' instance so that its Reset() method gets called
  2. Spawn multiple instances of the simulation through multiprocessing.imap or multiprocessing.pool
  3. Wait long enough for errors to show up

Expected behavior
Basilisk is advertised as capable of running MC simulations but I don't see how the current architecture overcomes Spice's advertised not-thread safe nature. I would expect parallelized simulation to complete without hurdle but the execution stall as well as the kernel data corruption goes to show there is a snag.

Screenshots
See #203

Desktop (please complete the following information):

  • OS: Linux 22.04 LTS
  • Python version 3.10

Additional context
The issue with Spice seems to be heavily tied to the library initialization where the data kernels are 'furnished'. It might just do the trick to spawn one instance of SimulationBaseClass outside of the parallel section and have a spiceInterface's Reset() function be called inside this specific instance, before the parallel processing takes place : if steps are taken to inhibit the spiceInterface's loadSpiceData() functions inside the parallel processing, I think the issue of the simultaneous 'furnishing' of the data kernels will be alleviated.

Maybe there's additional caution to be taken regarding the unloading of the data kernels

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingenhancementNew feature or request

Type

Projects

Status

✅ Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions