Possible Duplicate:
How to run mathlink external commands in parallel?
Abstract
I have a binary file compiled to work with MathLink. I can install the file and run the component functions from within Mathematica without any problems. But, when I try to use Mathematica's inbuilt parallelization with calls to my binary, I get an error that says
LinkObject::linkn: Argument LinkObject[/path/to/binary/file.binary,14,8] in
LinkWrite[LinkObject[/path/to/binary/file.binary,14,8],CallPacket[1,{1,2066455,5.,200000}]]
has an invalid LinkObject number; the link may be closed.
I understand this to mean that MathLink cannot set up links to my binary for some reason? How does one get this to work?
System Details
I am on a system with 8 cores running x86_64-redhat-linux-gnu.
Mathematica Code that Produces the Error
Assume SwitchTimes is a function defined inside my binary. It takes a number of inputs, but I want to loop over values for one particular input.
f[x_] := Module[{A, ma},
A = SwitchTimes[x, RandomInteger[10000000], 5.0, 200000];
ma = Mean[A];
ma
];
B = ParallelMap[f, Table[i, {i, 1, 100, 2}]];
Code that runs fine
f[x_] := Module[{A, ma},
A = SwitchTimes[x, RandomInteger[10000000], 5.0, 200000];
ma = Mean[A];
ma
];
B = Map[f, Table[i, {i, 1, 100, 2}]];
DistributeDefinitions[SwitchTimes]before use it? – Silvia Jul 26 '12 at 20:46link = Install[myPath<>"file.binary"]; LaunchKernels[]; DistributeDefinitions[SwitchTimes];And then use
– Y.P. Jul 26 '12 at 21:09ParallelMap. I still get the same errors.MathLink, maybe wait for others' investigation. – Silvia Jul 26 '12 at 21:39