# Running multiple instances of an already parallel external program in parallel

**URL:** <https://discourse.julialang.org/t/running-multiple-instances-of-an-already-parallel-external-program-in-parallel/116436>\
**Category:** General Usage\
**Tags:** parallel, run, external-process\
**Created:** [June 30, 2024, 6:26pm UTC](https://discourse.julialang.org/t/running-multiple-instances-of-an-already-parallel-external-program-in-parallel/116436 "2024-06-30T18:26:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tetrakai](https://avatars.discourse-cdn.com/v4/letter/t/4da419/32.png) [@Tetrakai](https://discourse.julialang.org/u/Tetrakai)\
**Post date:** [June 30, 2024, 6:26pm UTC](https://discourse.julialang.org/t/running-multiple-instances-of-an-already-parallel-external-program-in-parallel/116436/1 "2024-06-30T18:26:07Z")

</div>

I have a situation like below:

Julia

```julia
nrep = 3
Threads.@threads for i in 1:nrep
    run(`bash -c """cd $path && ./external_program"""`)
end

```

external\_program.cpp

```julia
#pragma omp parallel for num_threads(10)
for (int i = 0; i < 10; i++){
     // do stuff
}

```

Also, my cpu has 32 cores (64 threads). Julia is running with 32 threads.

Everything works fine, but I get way more overhead if nrep\*num\_threads \> 32 than when running nested parallel loops all from julia.

I’m not sure what exactly is going on in the background, but I’m guessing the latter case is composable while my problem is not.

Is that understanding correct? Is there a way to address this?

---

<div class="post-metadata">

**Author:** ![abraemer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraemer/32/51403_2.png) [@abraemer](https://discourse.julialang.org/u/abraemer)\
**Post date:** [June 30, 2024, 6:42pm UTC](https://discourse.julialang.org/t/running-multiple-instances-of-an-already-parallel-external-program-in-parallel/116436/2 "2024-06-30T18:42:40Z")

</div>

Yes Julia has composable multithreading

> **[Announcing composable multi-threaded parallelism in Julia](https://julialang.org/blog/2019/07/multithreading/)**
>
> Announcing composable multi-threaded parallelism in Julia | Software performance depends more and more on exploiting multiple processor cores....

To fix this you either need to control the number of threads used by your external programs and how many you start to avoid oversubscription or just use Julia and don’t waste brain cycles on the thread logistics 😉
