4

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}]];
Y.P.
  • 143
  • 4
  • Maybe try DistributeDefinitions[SwitchTimes] before use it? – Silvia Jul 26 '12 at 20:46
  • Ok, so I add the following to the top of the mathematica notebook: link = Install[myPath<>"file.binary"]; LaunchKernels[]; DistributeDefinitions[SwitchTimes];

    And then use ParallelMap. I still get the same errors.

    – Y.P. Jul 26 '12 at 21:09
  • Sorry for my wrong guess.. I'm not familiar with MathLink, maybe wait for others' investigation. – Silvia Jul 26 '12 at 21:39
  • 2
    This may be related: http://mathematica.stackexchange.com/q/33/877 – jmlopez Jul 26 '12 at 22:37
  • 1
    I recommend you use LibraryLink instead of MathLink if you are planning to run parallel code. – Szabolcs Jul 27 '12 at 07:37
  • 1
    @jmlopez actually it seems like a duplicate., – Szabolcs Jul 27 '12 at 07:40

0 Answers0