PatternTest vs Parallelization

Bug introduced in 10.0 or earlier and fixed in 11.2

Consider the following function

slowNorm[x_?(Length[#] == 3 && VectorQ[#, IntegerQ] &)] :=
(Pause[1]; Norm[x])


An equivalent implementation is

latticePoint3DQ = (Length[#] == 3 && VectorQ[#, IntegerQ] &);
slowNormAlt[x_?latticePoint3DQ] := (Pause[1]; Norm[x])


However, only the first function can be parallelized efficiently (in both cases all subkernels are already running):

In[1]:= ParallelTable[
slowNorm[{i, 0, 0}], {i, 1, 5}] // AbsoluteTiming

Out[1]= {2.01148, {1, 2, 3, 4, 5}}

In[2]:= ParallelTable[
slowNormAlt[{i, 0, 0}], {i, 1, 5}] // AbsoluteTiming

Out[2]= {5.00941, {1, 2, 3, 4, 5}}


Using Condition instead of PatternTest does result in the same behavior.

Is there a way to check arguments using latticePoint3DQ without losing the ability to parallelize?

Edit: I am using Version 11.1.1.0 of MMA and the Platform is Linux x86 (64-bit)

• I am not able to reproduce this. Can you specify your M version and give even mores pecific, step by step instructions? (E.g. the above does not show when the parallel kernels are launched, which takes a considerable time.) – Szabolcs Apr 9 '19 at 12:04
• @Szabolcs Thanks, I've edited the post, I don't know if I can add anymore step by step instrucitons. – kalix Apr 9 '19 at 12:10
• I asked for step by step because I wanted to make sure that you were not timing the subkernel startup. It's irrelevant now because I can easily reproduce this in 11.1. – Szabolcs Apr 9 '19 at 12:15

I can reproduce this in 11.1.1 but not in 11.2 or later. I believe that the problem is that the definitions of latticePoint3DQ are not automatically distributed (probably because symbols in PatternTest and Condition are not being considered), thus slowNormAlt effectively ends up being evaluated on the main kernel.
DistributeDefinitions[latticePoint3DQ]

Update: This is very likely a problem with LanguageExtendedFullDefinition, discussed in this QA:
• If DistributeDefinitions uses ExtendedFullDefinition then this is it: mathematica.stackexchange.com/questions/148207/… – Kuba Apr 9 '19 at 12:18
• No need to: PrintDefinitions @ ParallelProtectedDistDefs` – Kuba Apr 9 '19 at 12:21