# Parallelizing a Nested Loop Concurrently

**URL:** <https://discourse.julialang.org/t/parallelizing-a-nested-loop-concurrently/75402>\
**Category:** Performance\
**Tags:** parallel, loops\
**Created:** [January 28, 2022, 11:56pm UTC](https://discourse.julialang.org/t/parallelizing-a-nested-loop-concurrently/75402 "2022-01-28T23:56:07Z")\
**Posts on this page:** 1\
**Showing post:** 17

<div class="post-metadata">

**Author:** ![jmcastro2109](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jmcastro2109/32/38427_2.png) [@jmcastro2109](https://discourse.julialang.org/u/jmcastro2109)\
**Post date:** [February 1, 2022, 1:58pm UTC](https://discourse.julialang.org/t/parallelizing-a-nested-loop-concurrently/75402/17 "2022-02-01T13:58:56Z")

</div>

Is there a way to use `pmap` in the inner loop and `@floops` in the outer loop?

Or to do this with `Distributed` instead of multithreading?

Providing a little bit of context, the current solution based on FLoops spends a lot of time in Garbage Collection and uses a lot of memory. In this post, @odow provides a version based on `Distributed` which has comparable speed but uses much less memory.

> [@Improve performance of a code with very large % of Garbage Collection](https://discourse.julialang.org/t/improve-performance-of-a-code-with-very-large-of-garbage-collection/75548):
>
> Hello, I am trying to squeeze performance of the following code as much as possible. When I benchmark it, I get a very large number for the garbage collection statistic (see below). Does anyone have any recommendation for addressing this issue? using JuMP, Ipopt, LinearAlgebra, Random, Distributions, BenchmarkTools, MosekTools, NLopt, Plots, FLoops Threads.nthreads() const N = 100 const Ι = 250 const J = 50 const σ = 5 const α = 0.15 const S= 100 Random.seed!(2109) zbar = rand(Ι) variance =…

---

_[View the full topic](https://discourse.julialang.org/t/parallelizing-a-nested-loop-concurrently/75402)._
