1
$\begingroup$

Is it possible for a C program to communicate (via WSTP) with both a Mathematica kernel running on its machine, and a remote one?

For context: I use a local Mathematica kernel which talks to a remote C process (via WSTP) which runs all the heavy computation. These computations involve modifying big data sets which live entirely in the memory of the remote C process. I now need to perform some calculations in Mathematica on these data sets; sending the data back and forth between the remote C process and my local Mathematica kernel is untenably slow. It would be much better if instead, I could send the Mathematica expressions themselves to the remote C process, which would evaluate them on its data by passing the data and expression to a local Mathematica kernel.

This way, the big data sets don't need to be shared across a network; they would only be passed between the C program and the local (to it) kernel. The (small) result of the analysis would then be sent back to my (remote) kernel.

Is that at all possible using WSTP? It's not obvious to me how the C code can communicate with multiple kernels of any kind, since there's only one MathLink instance in the global namespace (as stdlink).

$\endgroup$
15
  • $\begingroup$ Yes, it's possible, but you need to do it from scratch using the MathLink API. You can't use the simplified method with mprep and template files, where argument translation and return is handled mostly automatically for you. $\endgroup$
    – Szabolcs
    Commented May 31, 2019 at 17:22
  • 1
    $\begingroup$ I think you're going about this the wrong way. I'd simply use a remote kernel to connect to this executable. $\endgroup$
    – Szabolcs
    Commented May 31, 2019 at 17:23
  • $\begingroup$ @Szabolcs thanks for the heads-up about MathLink, I'll check it out! Your second comment doesn't make much sense to me; I can't use only a remote kernel because that would involve sending remotely the huge data sets, as is the premise of the question $\endgroup$
    – Anti Earth
    Commented Jun 2, 2019 at 12:10
  • $\begingroup$ I don't think you understood my comment. Run everything on the same computer, both Mathematica and the C program. Either both on your computer or both on the remote computer. $\endgroup$
    – Szabolcs
    Commented Jun 2, 2019 at 12:15
  • 1
    $\begingroup$ This would also be a good reading for you: meta.stackexchange.com/questions/66377/what-is-the-xy-problem Never questioning the premise is not what is usually the most helpful for the OP. You did not give any justification for wanting to split the computation between remote and local, either in the original post or the comments. $\endgroup$
    – Szabolcs
    Commented Jun 3, 2019 at 13:23

0