# Slow ParallelDo

**URL:** <https://community.wolfram.com/t/slow-paralleldo/17662>\
**Category:** Questions\
**Tags:** high-performance-computing\
**Created:** [February 19, 2021, 3:48pm UTC](https://community.wolfram.com/t/slow-paralleldo/17662 "2021-02-19T15:48:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![erdiata](https://avatars.discourse-cdn.com/v4/letter/e/6a8cbe/32.png) [@erdiata](https://community.wolfram.com/u/erdiata)\
**Post date:** [February 19, 2021, 3:48pm UTC](https://community.wolfram.com/t/slow-paralleldo/17662/1 "2021-02-19T15:48:13Z")

</div>

Hello,  
I am trying to speed up my code with ParallelDo, but I ended up with a super slow case. Here is an artificial example of the case:

```
inits = RandomReal[{0, 5}, 10000];
sols = Table[
   NDSolve[{f'[t] == Sin[t], f[0] == inits[[j]]}, f[t], {t, 0, 10}],
   {j, 1, Length[inits]}];

```

Now, the parallel part

```
ParallelDo[
  qsol = sols[[1]];
  f[t] /. qsol /. t -> 4
  , {i, 1, 50}
  ] // AbsoluteTiming

```

this took {15.5051, Null}

```
qsol = sols[[1]];
ParallelDo[
  f[t] /. qsol /. t -> 4
  , {i, 1, 50}
  ] // AbsoluteTiming

```

this took {0.01021, Null}

The situation gets worse as the number of sols increases. What is the problem here?

I am guessing that inside the parallel block, sols is copied to each kernel and this copying slows down as the number of elements increases in sols. So, I tried

```
SetSharedVariable[sols[[1]]];
ParallelDo[
      qsol = sols[[1]];
      f[t] /. qsol /. t -> 4
      , {i, 1, 50}
      ] // AbsoluteTiming

```

This took {2.07197, Null} which is an improvement.

But when I tried

```
SetSharedVariable[sols];
ParallelDo[
  qsol = sols[[1]];
  f[t] /. qsol /. t -> 4
  , {i, 1, 50}
  ] // AbsoluteTiming

```

This took {125.364, Null}. This is ridiculusly long.
