# Multithreading Magboltz Gas File Generation

**URL:** <https://root-forum.cern.ch/t/multithreading-magboltz-gas-file-generation/63734>\
**Category:** Garfield++\
**Created:** [June 14, 2025, 7:55pm UTC](https://root-forum.cern.ch/t/multithreading-magboltz-gas-file-generation/63734 "2025-06-14T19:55:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![CLR\_123](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/clr_123/32/37383_2.png) [@CLR\_123](https://root-forum.cern.ch/u/CLR_123)\
**Post date:** [June 14, 2025, 7:55pm UTC](https://root-forum.cern.ch/t/multithreading-magboltz-gas-file-generation/63734/1 "2025-06-14T19:55:03Z")

</div>

Hello all, I’m trying to multithread the generation of gas files from Magboltz by splitting the field grid in different sections.

In my program, each `std::thread()` creates a `Garfield::MediumMagboltz` object that generates a table from a different interval of the [`E_min`,`E_max`] electric field grid (I’m not simulating magnetic fields), therefore splitting the total interval throughout the N threads running. However, I’m not sure if my approach works with Garfield, as I seem to get segmentation violations seemingly in a random part of the process. (Sometimes happens as soon as I begin the process, other times I can see the MT works by looking at per-core CPU usage but it crashes at some point).

It could be my own program’s fault, but I’m not sure why if it’s the case, as all I do after creating the threads is calling `thread.join()` to wait for them to finish.

I attached the output from the moment Garfield takes over, for a simple test generation of a 100.0% Argon mixture, using 4 threads (besides main thread). Any help is greatly appreciated!

[Output.txt](https://root-forum.cern.ch/uploads/short-url/swbFacn8EzCZERDlLtxC4O4q31J.txt) (40.1 KB)

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [June 15, 2025, 8:40am UTC](https://root-forum.cern.ch/t/multithreading-magboltz-gas-file-generation/63734/2 "2025-06-15T08:40:30Z")

</div>

Hello,

Adding @hschindl in the loop.

Cheers,  
D

---

<div class="post-metadata">

**Author:** ![hschindl](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/977dab/32.png) [@hschindl](https://root-forum.cern.ch/u/hschindl)\
**Post date:** [June 15, 2025, 11:36am UTC](https://root-forum.cern.ch/t/multithreading-magboltz-gas-file-generation/63734/3 "2025-06-15T11:36:24Z")

</div>

Hi,  
Magboltz is not thread-safe unfortunately. But what you can do is run separate jobs for different ranges of electric fields and then glue the gas files together using `MergeGasFile`.

> **[Examples/GasFile/merge.C · master · garfield / garfieldpp · GitLab](https://gitlab.cern.ch/garfield/garfieldpp/-/blob/master/Examples/GasFile/merge.C?ref_type=heads)**
>
> http://garfieldpp.web.cern.ch/garfieldpp/

---

<div class="post-metadata">

**Author:** ![CLR\_123](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/clr_123/32/37383_2.png) [@CLR\_123](https://root-forum.cern.ch/u/CLR_123)\
**Post date:** [June 19, 2025, 9:43pm UTC](https://root-forum.cern.ch/t/multithreading-magboltz-gas-file-generation/63734/4 "2025-06-19T21:43:11Z")

</div>

Hi, thanks for the reply! Used child processes with `fork()`, and it worked perfectly.

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [July 3, 2025, 9:43pm UTC](https://root-forum.cern.ch/t/multithreading-magboltz-gas-file-generation/63734/5 "2025-07-03T21:43:33Z")

</div>

Closed on July 3, 2025, 9:43pm UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
