Running matlab in the background

后端 未结 6 659
北恋
北恋 2021-02-04 17:25

I am running matlab on 48 virtual machines and would like to automate it. I ssh into the machines then use matlab -r matlab_command > outfile.txt & to get t

相关标签:
6条回答
  • 2021-02-04 17:44

    I am using this workaround, which provides a dummy standard in:

    matlab -r matlab_command > outfile.txt < /dev/null &
    
    0 讨论(0)
  • 2021-02-04 17:50

    Use nohup command on UNIX to prevent MATLAB stop when you logout.

    nohup matlab -nodisplay -nosplash -r matlab_command > outfile.txt &
    

    And don't forget to include exit; at the end of matlab_command script.

    UPDATE:

    Try this solution: Is it possible to run MATLAB in the background under UNIX?

    There is an explanation here.

    0 讨论(0)
  • 2021-02-04 17:50

    If you are using file:

    nohup matlab -nodesktop -nodisplay < file.m > result.txt &

    You might need to press enter after you execute this.

    0 讨论(0)
  • 2021-02-04 17:52

    The real clean solution to your problem is to use GNU Screen. Then you will not loose your Matlab session and you can always get back into the Matlab prompt. Very helpful if somebody went wrong with your Matlab code and you need to debug a little.

    Just fire up 'screen' (after you have the package installed, included in all major distributions). You will have a typical prompt, but inside a persistent, virtual terminal. Start your matlab as usual, omit any backgrounding. Then press CTRL+A, D (first CTRL+A, then d). You will be out of screen. You can logout. If you want to get back to your screen session, run screen -r. If you want, you can also directly start screen matlab [...] in the first place. It will have the effect that your virtual session is also dropped when matlab quits.

    0 讨论(0)
  • 2021-02-04 17:52

    I had trouble with screen: matlab started but had no notion of what had been passed through stdin. It simply ignored it.

    But I succeeded with tmux. Here is the command line I used,

    local$ ssh -f me@remote 'tmux new-session -d -s matlab "matlab -nojvm -nodesktop -nodisplay -nosplash </path/to/myscript.m"'
    

    You can then ssh into the remote host (indicated here by the prefix remote$) and check things by issuing remote$ tmux a -t matlab. You detach out to your remote host by pressing Ctrl-b d. You list sessions with remote$ tmux ls (like screen). You kill the session from inside with Ctrl-b & and from outside with $remote tmux kill-session -t matlab.

    But I discovered that you can also attach to your tmux session from your local host directly:

    local$ ssh -t me@remote 'tmux a -t matlab'
    

    Notice I had to use -t here in place of -f.

    0 讨论(0)
  • 2021-02-04 17:56

    I found some useful link Tips for Running Large Computations and nohup

    nohup nice matlab -nodisplay -nosplash <matlab_command.m > outfile.txt > 2>dev/null &
    

    maybe this can fix your problem.

    0 讨论(0)
提交回复
热议问题