# What is the correct way to create an animation in parallel using NDSolve?

**URL:** <https://community.wolfram.com/t/what-is-the-correct-way-to-create-an-animation-in-parallel-using-ndsolve/21272>\
**Category:** Questions\
**Tags:** calculus, equation-solving, graphics-and-visualization, high-performance-computing, numerical-computation\
**Created:** [December 27, 2022, 5:18am UTC](https://community.wolfram.com/t/what-is-the-correct-way-to-create-an-animation-in-parallel-using-ndsolve/21272 "2022-12-27T05:18:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaumann](https://avatars.discourse-cdn.com/v4/letter/j/779978/32.png) [@jaumann](https://community.wolfram.com/u/jaumann)\
**Post date:** [December 27, 2022, 5:18am UTC](https://community.wolfram.com/t/what-is-the-correct-way-to-create-an-animation-in-parallel-using-ndsolve/21272/1 "2022-12-27T05:18:58Z")

</div>

As the title says. For example, in the following code `ParallelTable` takes 23 minutes:

```auto
R = 
 Annulus[{-0.9`, -1.95`}, {1.6`, 6.5`}];
soln = NDSolveValue[
     {I*D[u[t, x, y], t] + Laplacian[u[t, x, y], {x, y}] == 
         NeumannValue[0, True], u[0, x, y] == 
         Exp[-((x - 2/3)^2 + (y - Pi/2)^2)]/Pi}, u, 
     {t, 0., 20.}, Element[{x, y}, R]]
imgs = ParallelTable[
  Plot3D[Abs[soln[t, x, y]], {x, y} \[Element] R, 
   PlotRange -> {0, 1/3}, PlotPoints -> 100], {t, 0, 15}];
ListAnimate[imgs]

```

while `Table` takes about 20 seconds. In a real situation, the animation must have many more frames, with `dt = 0.1`, for example. This question is duplicated [here](https://mathematica.stackexchange.com/questions/277706/what-is-the-correct-way-to-create-an-animation-in-parallel-using-the-result-of-n).

---

<div class="post-metadata">

**Author:** ![rolandfranzius](https://avatars.discourse-cdn.com/v4/letter/r/5f8ce5/32.png) [@rolandfranzius](https://community.wolfram.com/u/rolandfranzius)\
**Post date:** [March 13, 2023, 10:41am UTC](https://community.wolfram.com/t/what-is-the-correct-way-to-create-an-animation-in-parallel-using-ndsolve/21272/2 "2023-03-13T10:41:47Z")

</div>

Hi Jonathan,

the correct way is

```
R = 
 Annulus[{-0.9`, -1.95`}, {1.6`, 6.5`}];
soln = NDSolveValue[
     {I*D[u[t, x, y], t] + Laplacian[u[t, x, y], {x, y}] == 
         NeumannValue[0, True], u[0, x, y] == 
         Exp[-((x - 2/3)^2 + (y - Pi/2)^2)]/Pi}, u, 
     {t, 0., 20.}, Element[{x, y}, R]]

In[50]:= Timing[
 img = Array[(Plot3D[
       Evaluate[Abs[soln[#, x, y]]], {x, y} \[Element] R] &), {16}, 
    0] ;]

Out[50]= {4.78125, Null}

```

Regards Roland

---

<div class="post-metadata">

**Author:** ![horwitz](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/horwitz/32/20325_2.png) [@horwitz](https://community.wolfram.com/u/horwitz)\
**Post date:** [March 14, 2023, 12:55am UTC](https://community.wolfram.com/t/what-is-the-correct-way-to-create-an-animation-in-parallel-using-ndsolve/21272/3 "2023-03-14T00:55:17Z")

</div>

You would think using ParallelTable would save time by distributing the computations over several kernels. I think Roland’s method was faster because he used Evaluate[] around Abs[soln[#,x,y].  
If you retry yours with Evaluate[Abs[soln[t,x,y]], I bet it will execute in less time than 4.78125 seconds. Using Evaluate[] often helps when a computation takes a very long time.

---

<div class="post-metadata">

**Author:** ![jaumann](https://avatars.discourse-cdn.com/v4/letter/j/779978/32.png) [@jaumann](https://community.wolfram.com/u/jaumann)\
**Post date:** [March 14, 2023, 4:26pm UTC](https://community.wolfram.com/t/what-is-the-correct-way-to-create-an-animation-in-parallel-using-ndsolve/21272/4 "2023-03-14T16:26:00Z")

</div>

Thanks for trying, but the issue remains unsolved. `Evaluate` has no effect in this case because the time-consuming function, `NDSolve`, is not being delayed until plotting, and replacing `Array` with `ParallelArray` multiplies the evaluation time by at least 6.  
This takes 4.67 seconds:

`AbsoluteTiming[img = Array[(Plot3D[ Evaluate[Abs[soln[#, x, y]]], {x, y} \[Element] R] &), {16}, 0];]`

While this takes 27.6 seconds:

`AbsoluteTiming[img = ParallelArray[(Plot3D[ Evaluate[Abs[soln[#, x, y]]], {x, y} \[Element] R] &), {16}, 0];]`

For serial, my evaluation times as a function of the number of plots is: `{{10, 12.2379}, {15, 18.5765}, {20, 24.7349}, {25, 31.6992}, {30, 41.3019}, {35, 45.4878}, {40, 51.805}, {45, 57.9418}, {50, 65.3213}}`

While for parallel, it is: `{{10, 293.046}, {15, 458.709}, {20, 611.03}, {25, 725.197}, {30, 873.236}, {35, 1027.61}, {40, 1116.4}, {45, 1244.97}, {50, 1397.45}}`

The problem appears to be with the implementation of `Parallel*`
