# Parallelize Slow on Interpolated Functions

So I have an FEA solution from COMSOL and I import the mesh and values at the vertices to create an interpolation function.

{coords, data, tets} = (* Expression to extract the mesh and solution from COMSOL file *)
mesh = ToElementMesh["Coordinates" -> coords, "MeshElements" -> {TetrahedronElement[tets]}]
HzPort = ElementMeshInterpolation[{mesh}, data, InterpolationOrder -> 2]


Now I want to evaluate the interpolated function in a bunch of places (actually I want to solve further differential equations using the interpolated function, but this seems like a reasonable simplification) so I go and Table over some points, say:

Table[HzPort[0, 0, z], {z,-fieldHeight/2, fieldHeight/2, 0.0001}]


This works fine and completes in about a tenth of a second. However, if I try using ParallelTable:

ParallelTable[HzPort[0, 0, z], {z,-fieldHeight/2, fieldHeight/2, 0.0001}]


It takes more than 30 seconds to complete.

I've tried things like DistributeDefinition[HzPort] and even:

Parallelize[HzPort = ElementMeshInterpolation[{mesh}, data, InterpolationOrder -> 2];
Table[Hz[0, 0, z], {z, -fieldHeight/2, fieldHeight/2, 0.0001}]]


Which give me performance which is just as bad or worse.

One thing to mention, the mesh and data are largish, and I'd like to do this with meshes which are much larger.

In[42]:= Print[N[ByteCount[{mesh, data}] 2^-20], " Mb"]
Out[42]= 20.7121 Mb

• Use vectorization. InterpolatingFunction objects can apply directly to many data points at once if passed in the appropriate way (I.e. they thread over their arguments). That’s likely the fastest approach. – b3m2a1 Jul 15 '18 at 18:42
• I'm trying to use the interpolated function as part of a DE I want to time evolve with NDSolve. Because the values of the interpolated function I need are independent of the DE solution I suppose I could switch to a solver that used fixed steps and precompute all the points I need... That does not seem like the "correct" solution though. – alessandro Jul 16 '18 at 0:04