12

I'm working with a huge amount of data, so I'm avoiding using AppendTo. I used to use the Reap and Sow command, in parallel, as follows:

SetSharedFunction[ParallelSow];
ParallelSow[expr_] := Sow[expr]

list = Reap[ParallelDo[psa= Eigenvalues[Adj$A, -1]; psaData = {N[Abs@psa, Prec][[1]]}; ParallelSow[psaData], {s, lists}]][[2,1]]

Everything worked fine until I updated Mathematica to version 14.0.0. Now, all my attempts give me

{Null, {}}

If, however, I use just Do and Sow (or ParallelSow as defined above), the code works fine!

What changed? Can anyone help me regain the old functionality?

xzczd
  • 65,995
  • 9
  • 163
  • 468
Pedro Croti
  • 121
  • 2
  • 1
    Looks like a bug to me, the document page Incompatible Changes since Mathematica Version 1 doesn't mention anything about this. (BTW, a simpler example is the one in Neat Examples section of document of SetSharedFunction. It simply doesn't work now. ) Have you reported this to WRI? – xzczd Mar 25 '24 at 07:33
  • Frankly, I'm kinda shocked that Sow even works though parallel functions. I don't think it's documented anywhere that it should work? As a workaround, you can always use an Association to AppendTo. It's much faster than appending to a list. – Sjoerd Smit Mar 25 '24 at 10:13
  • @SjoerdSmit As mentioned above, it's documented in Neat Examples section of document of SetSharedFunction. See also https://mathematica.stackexchange.com/q/313/1871 – xzczd Mar 25 '24 at 11:21
  • Ah, I missed that. Sorry. In that case it's definitely a bug. I'll report it. – Sjoerd Smit Mar 25 '24 at 14:04
  • 1
    Yes, it's a bug. I reported it to support and they responded saying that "It appears that Reap/Sow is not behaving correctly with Parallel kernels in Mathematica 14".

    Thanks, @Sjoerd Smit, I'll try to use Association.

    – Pedro Croti Mar 26 '24 at 11:06
  • I also heard that it should be fixed in the next version, so that's good news. – Sjoerd Smit Mar 26 '24 at 11:36

0 Answers0