MathGroup Archive 2003

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Calling Mathematica via MathLink multiple times

  • To: mathgroup at smc.vnet.net
  • Subject: [mg44747] Re: Calling Mathematica via MathLink multiple times
  • From: Peter Meulbroek <meulbro at caltech.edu>
  • Date: Mon, 24 Nov 2003 00:05:33 -0500 (EST)
  • Organization: California Institute of Technology
  • References: <bpkqfk$cjr$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Julius:
I would put a stub program around your mathlink call (a listener), and
have that program act more-or-less as a daemon.  Then, have your caller
c code call the stub, rather than mathematica directly.  The stub gives
you persistence, and more control over sockets than mathlink (which is
also over sockets, of course).  You can use raw sockets to communicate
with the stub, or get fancy with RPC, whatever your druthers.

--Peter

p.s.:  you could even have a perl script as your daemon;  I seem to
remember some attempt to wrap mathlink for perl (like Math::Matica, or
something similar).  If that is not possible, we can swig it...

Julius Su wrote:
> Hello,
> 
>   I would to call Mathematica from within a C program to evaluate a
> lengthy function.  (the reverse of the usual situation!)
> 
>   To do this I am using MathLink, and I have written a test program
> that successfully establishes a link with the kernel, calls the
> function, and returns the answer.  When the program exits though, the
> link to the kernel dies and the kernel quits.
> 
>   Is there any way to keep the kernel alive between MathLink
> connections? This would be useful for storing persistent information,
> and for avoiding reinitializing certain routines before each function
> call.
> 
> Possible (indirect) solutions:
> 1.  I have used <<JLink` and the ShareKernel[] command to allow the
> kernel to switch between multiple links, but I would then need a way
> to (1) detect when connections are broken and create a new link and
> (2) tell my C program which port to connect under.
> 2.  I could set up a program that connects once to the Mathematica
> kernel, then write another program that contacts the first via a
> message queue and semaphores.  There must be a simpler way though!
> 
> Thanks,
> 
> Julius
> 




  • Prev by Date: Re: Conversion Function -> List
  • Next by Date: Re: Calling Mathematica via MathLink multiple times
  • Previous by thread: Re: Calling Mathematica via MathLink multiple times
  • Next by thread: Re: Calling Mathematica via MathLink multiple times