In order to make my computations faster I have developed a C/C++ application calling Mathematica kernel and performing many operations using Mathematica functions for equation solving.
Now I want to use multithreading and in particular I plan on taking advantage of the Posix library in order to do so (pthread). But how does the link behaves when many threads insist on it?
I guess that being a buffered/packet approach, if two threads try to send stuff to the same link without a mutex in guard (of the link), everything is a mess.
SO I should create as many links as many threads I create. So here my questions:
- Is there a limit to the number of links I can create to MathLink?
- Is there a way to perform parallel activities on the Mathematica kernel in an automated way? I know about the parallel core of Mathematica, but what happens when I am interfacing to Mathematica through MathLink from C/C++?
Nmathematica kernels and link to them. – Ajasja May 14 '13 at 20:32$MaxLicenseProcessesvariable). But as I said before, it looks like you are making things much too complicated and difficult for yourself. Since your C program seems to heavily rely on Mathematica anyway, why don't you drive it from Mathematica instead driving Mma from C? You can easily parallelize from Mma then and use$MaxLicenseSubprocessesthreads. – Szabolcs May 14 '13 at 22:00MathLink`AddSharingLink, as I described here. (Anecdote: this is undocumented, so I did a Web search for it, to see if anything useful came up. The first result was my own post, which I'd already forgotten I had written. Another relevant instance here.) – Oleksandr R. May 15 '13 at 14:49