Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

The answer to an earlier question,

Computers running Wolfram Lightweight Grid Manager won't fall asleep,

left me with a new problem. To review, I have a computing environment comprised of:

  • 27" iMac with dual cores running Mac OS X 10.6.8 and
  • 2 XServes each with 2 quad cores running Max OS X Server 10.6.8
  • All networking by ethernet to a Time capsule.

As this question has more general application than the earlier question, I thought it merited its own post.


I need to launch and shut down a service (in my case Wolfram Lightweight Grid Manager but this really applies to any service, program, or application) which needs to run on a server (or more generally, any other machine) attached to my network (or again more generally, any network to which one has authorized access).

So, ideally I'd like to do the following:

  • Access and log on to (a) remote computer(s) on a local network directly from Mathematica;

  • Launch a script on the remote computer that will in turn launch Wolfram Lightweight Grid Manager;

  • Launch available kernels;

  • Run parallel processing code;

  • Close remote kernels; and

  • Launch a script on the remote computer to close Wolfram Lightweight Grid Manager.

Can I do all of this from within Mathematica?


Run[] enables one to run a command line program:

Run[] example

But how do I get to a remote machine, especially as it does not likely have a fixed IP address? ;-(

I would appear to need a way to identify machines on the network (I do have machine names and log on credentials).

I've very rarely done this sort of thing.

Could a script launched locally by the Run[] function access the remote machines and launch a script on them?

That would make it easy.

References or examples welcome.

My Unix script never amounted to much, so any guidance welcome.

It also, occurs to me that one could do this via JLink, but as the little I knew of Java has generally drifted out of my memory a more direct solution would do me better.

share|improve this question
Not having a fixed IP is a problem. If the machine did have one, you could log in with ssh an execute commands. To execute command x on machine y, logging in as user z, you need to execute ssh z@y x from a command shell. Normally this prompts for a password, but if you use public key authentication, entering a password can be avoided, and you can automate everything completely. –  Szabolcs Jul 5 '12 at 18:44
Anyway to do the SSH using the server's names on the network? –  Jagra Jul 5 '12 at 18:50
Could I programmatically ping the XServes' names and get back the current IP addresses. Maybe not reliable. Just trying to think this through. –  Jagra Jul 5 '12 at 19:01
@Jagra If the names are associated with the current IP address, i.e. you can ping them, then you don't need the IP address. You could run a local nameserver to lookup the IP addresses, or set all the machines to fixed IPs. –  image_doctor Jul 5 '12 at 19:09
@image_doctor - Thanks for the suggestion. I also discovered that one can set up a "DHCP reservation" on the TimeCapsule using an Airport Utility. Then say, using a client ID one can easily change things if one ever replaces a server. Also suggested to me, typing the MAC address could work. Still lots to figure out to get this to work. –  Jagra Jul 5 '12 at 20:32
show 2 more comments

1 Answer

up vote 3 down vote accepted

Once setup you should be able to do all of what you want from Mathematica without resorting to shell scripts.

This isn't Apple specific, but hopefully this will get you most of the way and uses the Remote Kernel method rather than the lightweight grid manager:

  1. Create an ssh key if you haven't already, using ssh-keygen

  2. Copy that key to all the remote hosts you want to use using ssh-copy-id hostname Check you can login without supplying a password to each host with ssh hostname

  3. Define the remote machines to be used and the number of kernels using menu item: Evaluation->ParallelKernelConfiguration: [TAB] Parallel [TAB] Remote Kernels

which requires a hostname and possibly a custom launch command. I needed to specify the fullpath the Mathematica kernel, which in my case was /usr/local/bin/math giving:

    ssh -x -f -l `3` `1` /usr/local/bin/math -mathlink -linkmode Connect `4` -linkname '`2`' -subkernel -noinit
  1. The kernels you have defined using this method, as well as your local kernels, are then held in $ConfiguredKernels. They can all be launched using LaunchKernels[]

  2. The control of code execution can then be done with the usual Mathematica parallel evaluation functions and the kernels can be closed jointly or separately using CloseKernels[]. The current running kernels can be listed by Kernels[].

share|improve this answer
I tried to fix the command line formatting problem, but I don't know if I got it right. Please check it. –  Mr.Wizard Jul 9 '12 at 14:45
@Mr.Wizard Thanks, it looks correct to me, that was beyond my formatting capabilities :) –  image_doctor Jul 9 '12 at 14:56
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.