# Macro to turn on/off parallelisation

**URL:** <https://discourse.julialang.org/t/macro-to-turn-on-off-parallelisation/117808>\
**Category:** General Usage\
**Tags:** macros, parallel, multithreading\
**Created:** [August 4, 2024, 12:50pm UTC](https://discourse.julialang.org/t/macro-to-turn-on-off-parallelisation/117808 "2024-08-04T12:50:47Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![eldee](https://avatars.discourse-cdn.com/v4/letter/e/b5a626/32.png) [@eldee](https://discourse.julialang.org/u/eldee)\
**Post date:** [August 4, 2024, 2:28pm UTC](https://discourse.julialang.org/t/macro-to-turn-on-off-parallelisation/117808/6 "2024-08-04T14:28:56Z")

</div>

A somewhat similar approach is suggested [here](https://discourse.julialang.org/t/optionally-multi-threaded-for-loop/81902/8) by `oxinabox`: use `Base.foreach` for sequential and `ThreadsX.foreach` for parallel execution (and automatically switch based on the value of `PARALLEL`).

@jibe Check out the linked topic: it deals with the same question and has some more answers.

---

_[View the full topic](https://discourse.julialang.org/t/macro-to-turn-on-off-parallelisation/117808)._
