# Why use EnsembleProblems?

**URL:** <https://discourse.julialang.org/t/why-use-ensembleproblems/114315>\
**Category:** Modelling & Simulations\
**Tags:** question, multithreading, ode\
**Created:** [May 15, 2024, 5:57pm UTC](https://discourse.julialang.org/t/why-use-ensembleproblems/114315 "2024-05-15T17:57:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonathanfischer97](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jonathanfischer97/32/50242_2.png) [@jonathanfischer97](https://discourse.julialang.org/u/jonathanfischer97)\
**Post date:** [May 15, 2024, 5:57pm UTC](https://discourse.julialang.org/t/why-use-ensembleproblems/114315/1 "2024-05-15T17:57:23Z")

</div>

# What’s the main intended use case for using an `EnsembleProblem` in DifferentialEquations.jl?

- Does it offer better performance through batching compared to just writing an equivalent parallelized loop with `remake` and `solve`?

- Or is it just intended as a more user friendly abstraction?

Relatedly, are user supposed to directly mutate the `u0` and `p` fields of an `ODEProblem` within the `prob_func`? It’s confusing because the documentation shows this as the first example here [DifferentialEquations.jl](https://docs.sciml.ai/DiffEqDocs/stable/features/ensemble/#:~:text=function%20prob_func(prob%2C%20i%2C%20repeat)%0A%20%20%20%20%40.%20prob.u0%20%3D%20u0_arr%5Bi%5D%0A%20%20%20%20prob%0Aend):

```julia-auto
function prob_func(prob, i, repeat)
    @. prob.u0 = u0_arr[i]
    prob
end

```

even though `remake` is preferred to direct field mutation within SciML, from my experience. Is this dependent on whether `safetycopy = true` or `false`?

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [May 16, 2024, 8:07am UTC](https://discourse.julialang.org/t/why-use-ensembleproblems/114315/2 "2024-05-16T08:07:05Z")

</div>

> [@jonathanfischer97](#):
>
> Or is it just intended as a more user friendly abstraction?

This.

> [@jonathanfischer97](#):
>
> Relatedly, are user supposed to directly mutate the `u0` and `p` fields of an `ODEProblem` within the `prob_func`? It’s confusing because the documentation shows this as the first example here [DifferentialEquations.jl](https://docs.sciml.ai/DiffEqDocs/stable/features/ensemble/#:~:text=function%20prob_func(prob%2C%20i%2C%20repeat)%0A%20%20%20%20%40.%20prob.u0%20%3D%20u0_arr%5Bi%5D%0A%20%20%20%20prob%0Aend):

You can, though we should probably update that to use remake. That portion of the docs was written before remake existed.
