# Parallelize[Mapindexed[]], level={-1}? Sal Mangano's 《Cookbook》

It is easy to Parallelize[] Map[] & MapIndexed[], as having been shown in MMA9 Help for ParallelMap[] and Parallelize[].

For MapIndexed[], the default levelspec is {1}. However there are many cases when we need mapping to deeper levels such as {-1}, for example with image data (2D array). I have tried Parallelize[] and found it FAILED and switched to sequential evaluation whenever levelspec is explicitly specified, actually even when levelspec={1} !

In page 652 of Sal Mangano's Mathematica Cookbook, he seems to have written functions which

1. use Parallelize[] on MapIndexed[]
2. able to specify levelSpec

I don't know how he achieved that, and his example was not detailed enough to see the intended effect. I actually suspect that: with the default levelspec={1}, Parallelize[] could conveniently distribute the elements on the first level of the list across different kernels (like breadth-first search on level 1, using a queue in C); however if we need to go deeper with MapIndexed[]'s depth-first (see help) search, then the parallel implementation would be very difficult.

So is it true that Parallelize[Mapindexed[]] only works with default/implicit levelSpec={1}, not others?

Is Mr. Sal Mangano on this forum? Could he also comment?

• Sal Mangano is in this forum. – halirutan Jan 29 '14 at 17:14
• @halirutan But he hasn't been visiting us for a while – Dr. belisarius Jan 29 '14 at 17:15
• @halirutan Is is possible to send forum message (like private message/mail) on other forums? Or can I find his email in the profile (didn't succeed)? – JimmyLin Jan 29 '14 at 18:57
• No, you cannot send any message. As you can see from his profile, he was not on SE since March 2012. Se even if you could send some kind of forum message, he wouldn't receive it because it is very unlikely that he has email notification turned on. I'm not sure how inappropriate it would be if you mail him directly, point him to the question and ask him for his opinion. But maybe the question will be answered by other users and you won't even need him personally. – halirutan Jan 29 '14 at 21:01
• @JimmyLin You can find information on his website, for example he is active on Twitter. I don't know how he feels about being contacted about this though. – C. E. Jan 29 '14 at 21:02

According to the book that implementation is meant for users who use Mathematica v. 7 and don't have access to ParallelMap. It would be very odd if a function meant to substitute another does not accept the same arguments. I would say that this is the reason that levelspec is included. I also note that in the documentation for ParallelMap, the function it is meant to replace, it says:

Parallelize[Map[f,expr]] is equivalent to ParallelMap[f,expr].

it also says

ParallelMap uses the same level specifications as Map. Not all level specifications can be parallelized.

So really, the function as implemented in the book does exactly what it is supposed to. It is the best you can do for v. 7 and might even be as good as ParallelMap in version 9.

(My answer to your question is not to confirm or deny what levelspecs it works for, but it doesn't work for all and it doesn't for more levelspecs than ParallelMap.)

• I believe so, "Not all level specifications can be parallelized." – JimmyLin Jan 30 '14 at 11:37