# Multi-threading on a 2 CPU system

**URL:** <https://discourse.julialang.org/t/multi-threading-on-a-2-cpu-system/93785>\
**Category:** New to Julia\
**Tags:** multithreading\
**Created:** [January 30, 2023, 5:52pm UTC](https://discourse.julialang.org/t/multi-threading-on-a-2-cpu-system/93785 "2023-01-30T17:52:48Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![fft](https://avatars.discourse-cdn.com/v4/letter/f/e8c25b/32.png) [@fft](https://discourse.julialang.org/u/fft)\
**Post date:** [February 1, 2023, 2:37am UTC](https://discourse.julialang.org/t/multi-threading-on-a-2-cpu-system/93785/4 "2023-02-01T02:37:58Z")

</div>

The way you have your loops structured might be problematic.

> [@Multithreading for nested loops](https://discourse.julialang.org/t/multithreading-for-nested-loops/36002/25):
>
> Indeed, lines like RM[i1,i1] += -GEself[1,1]/8π indicate that your code have data races. We can’t expect a deterministic behavior. FYI, there are a couple of examples in FLoops documentation for writing reduction of mutable objects without data races. See: [In-place mutation](https://juliafolds.github.io/FLoops.jl/dev/howto/parallel/#In-place-mutation) and [Initialization with @reduce(acc = op(init, x)) syntax](https://juliafolds.github.io/FLoops.jl/dev/tutorials/parallel/#Initialization-with-@reduce(acc-op(init,-x))-syntax). There’s also [private variables support](https://juliafolds.github.io/FLoops.jl/dev/howto/parallel/#private-variables).

```julia
@threads for ..
    @threads for..

```

Nested @threads loops is probably a little hard to reason about what happens. If you restructured your code to have one top level parallel loop you would likely get better performance and more intuitive understanding of the parallel execution.

---

_[View the full topic](https://discourse.julialang.org/t/multi-threading-on-a-2-cpu-system/93785)._
