I have a function programed in C which I load in MMA with
Needs["NETLink`"] MYlTNC = DefineDLLFunction["ltnc", path, "double", {"double", "double", "double", "double", "double"}] It works nicely except when I want to use it within a ParallelTable command. It is as if its definition does not get sent to the kernels. Here is a short example:
t2 = MYlTNC[0.025, 10, 1.1, 1.1 + 5, 1.1]; Export["try.dat", t2] FilePrint["try.dat"] outputs the following string correctly
3.09128 but
ParallelTable[ t2 = MYlTNC[0.025, 10, 1.1, 6.1, 1.1]; Export["try.dat", t2], {10}]; FilePrint["try.dat"] outputs the string
If[NETLink`DLL`Private`checkArgCount["ltnc", {0.025, 10, 1.1, 6.1, 1.1}, 5], Wolfram`NETLink`DynamicDLLNamespace`DLLWrapper5`ltnc[0.025, 10, 1.1, 1.1 + 5, 1.1], $Failed] If I replace ParallelTable with Table, it works fine again.
Is there a way to incorporate within the kernels the definition of the attached DLL?
ParallelEvaluate[ MYlTNC = DefineDLLFunction["ltnc", path, "double", {"double", "double", "double", "double", "double"}] ]before theParallelTable? $\endgroup$ParallelNeeds["NETLink`"]before that. $\endgroup$Wolfram`NETLink`DynamicDLLNamespace`DLLWrapper5`ltnc[0.025, 10, 1.1, 6.1, 1.1]. $\endgroup$LaunchKernels[]ParallelNeeds["NETLink`"]DistributeDefinitions[path, MYlTNC]ParallelEvaluate[ MYlTNC = DefineDLLFunction["ltnc", path, "double", {"double", "double", "double", "double", "double"}]]does it. Any reason for that? $\endgroup$ParallelNeeds["NETLink`"], they do not know the framework behindDefineDLLFunction.ParallelTablecan auto-distribute symbols that appear in its body. But apparently, the symbols must be explicit. MoreoverParallelEvaluatemakes sure that the DLL is loaded into each subkernel. Otherwise, each subkernel might request the main kernel to evaluate this function each time ot appears which would defeat the purpose of parallelization. $\endgroup$