Run MATLAB in Linux background

Source: Internet
Author: User

How to run the MATLAB script file in the background: nohup

Functions:
1. Run MATLAB in a character environment.
2. Run the MATLAB script file in the character environment,
The script file has no image screen output.

3.The script file needs to run for a long time and the running result is output to the file. The MATLAB standard redirects to another file.

4.After the client exits and logs on, Matlab keeps running.
The MATLAB program does not exit until the script program ends or the error exits.

Implementation Method:
Use the nohup command.


Specific implementation process:

Run the following command:
Nohup/usr/Matlab/bin/MATLAB <fill. m> Fill. Out &
You can, fill. M indicates your file name.Fill. Out indicates that your output is transferred to the fill. Out file. For example, in the MATLAB command sin (), the result should be output to the Command window, but now it is transferred to the fill. Out file.

For example, I have a test2.m file in the/home/jsh/yangting/folder.

When Matlab is enabled in the/home/jsh/yangting/folder,

Command is

Nohup MATLAB <test2.m> Fill. Out &

Note: After the nohup operation is successful, you cannot directly click the close button. Instead, you should press any key to restore to the input state, and then press the exit command to exit.

Run the following command:
Nohup
MATLAB-nojvm-nodisplay-nosplash
-Nodesktop
<MATLAB script. M 1> running. log 2> running. Err &


Or
Nohup Matlab-nojvm-nodisplay-nosplash <MATLAB script. M 1> running. log 2> running. Err &


Or:
Nohup Matlab-nojvm-nodisplay <MATLAB script. M 1> running. log 2> running. Err &

Where:
MATLAB script. m is the script file to be run and exists on the server;
Running. log is the redirection file output from the MATLAB standard screen and will be built on the server;
Running. Err is an error redirection file during MATLAB runtime, which will be created on the server.

==========================================
In addition:
(1) If you want to interrupt the running MATLAB, use
Kill-9 process no.


Or FG % N

; Ctrl + c

(2) If you want to run the script in the MATLAB of the character environment, use
Run script file name (excluding. m extension)

(3) If you want to use SSH to run the X-interface MATLAB, use
SSH host name-l user name-x

Running MATLAB remotely (under Linux)

Usually,
It is most valid tive and convenient to run MATLAB locally, in
Particle for interactive work, but there are a number of reasons why
You might want to run MATLAB remotely processing ss a network. For instance,
Your local machine may not have MATLAB installed at all, or your local
Machine may not have sufficient memory for your task. In these cases,
You can consider accessing another computer by remote login and running
MATLAB there. This concept only makes sense under Unix/Linux on
Remote machine; windows or Macintosh do not allow for remote access (
Far as I know). Hence, for any new windows to be opened, also your local
System needs to be Unix/Linux. However, the performance of such remote
Windows may be so slow that you will want to avoid them anyway and
Rather run MATLAB purely inside your login shell; naturally, this
Precludes any graphical output and restricts this use to numerical tasks
Only.

So,
We want to start MATLAB (I) without its desktop and (ii) without any
Graphics (including the splash screen); this can be accomplished
Saying Matlab-nodisplay
. You coshould also use MATLAB-nodisplay-nojvm
,
Which additionally does not start the JVM. In both cases, attempts
Open plot and similar windows might be simply ignored or attempts
Open the documentation windows might result in various error messages.

The above is the most restrictive way in which to start MATLAB. If in fact your local machine is Linux, you cocould use MATLAB-nodesktop-nosplash
,
Which (I) does not start the desktop and (ii) suppresses the splash
Screen (the small window with MATLAB's logo and version number that
Usually pops up briefly). But this way of starting MATLAB does start
JVM and you have access to the helpbrowser as well as to plot windows,
If you later so desire (and are willing to wait for those to open, which
Might take a while depending on your network connection ).

Running MATLAB in the background (under Linux)

The
Idea of running a job in the background means that a software runs
Without any user interaction and additionally does not block your login
Shell. As remote access, this makes only sense under Unix/Linux. it
Applies both on your local machine, but might be special useful on
Remote Login; as in the previous section, this will be most useful
Purely numerical (I. e., non-graphical) jobs.

nohup /matlab -nojvm -nodisplay < driver.m >& driver.log &

Here, the backslash in/MATLAB
Circumvents any possible alias you might have for Matlab (just to be on the safe side) and the options-nojvm-nodisplay
Suppress the starting of the JVM (and the startup of the desktop) and
The opening of any windows. The final ampersand ("&") actually puts
The command into the background, I. e., gives you the command-line prompt
In your shell back. Aside from entering any usual commands now, you
Cocould in participates log out, without hanging or killing your job,
Because of the standard Unix/Linux Command nohup
Before the call to MATLAB. The file driver. m
That must be present in the current directory is a MATLAB script file
(Not: function file) that lists the commands to be executed by your job;
If your job is actually med by a function, this script file can
Simply be a single line that callyour function.

For
The remaining elements in the command-line above, I am assuming you are
Using the CSH or tcsh shell; in other shells, the redirections may be
Slightly different. The "<
"Redirects stdin (namely from file driver. m
) Into MATLAB. For the background run not to hang, there must not be any screen output, so the "> &
"Redirects both stdout and stderr to the file driver. Log
;
This file must not exist initially. Again, the redirection commands may
Be different in other shells and slight variations are possible (such
As overwriting an existing log file ).

For Linux UNIX, you can use nohup sh 'full command line' to start the program and run the program in the background, independent of the terminal.

Since there is no graphical interface when nohup is started, if it is matlab, it is recommended that you do not use graphical interface options to execute any commands in advance written in the M file, such:

Nohup sh 'matlab-nodesktop </data/user/mycommand. M'

Here<Indicates that the input is switched because nohup ignores the input of the terminal.


Note that if it is on SSH, do not close the window directly, but use the exit command to unlink the host.


"&" Is not important in Linux. In Linux, there are simpler methods. There is also a graphical interface

1) You can use the screen command, which is generally supported by kernels later than 2.6.12.
Screen MATLAB &
At this time, you can continue to use MATLAB and exit the terminal with exit.
If not &. You can go to the terminal and press Ctrl-a to suspend. Run the command BG to switch MATLAB to the background. Note that you should not forget the most important step at this time. Press one key or press one more carriage return, use Exit. Otherwise, once you finish sreen, Matlab will end.

2) kernel 2.6.18 or later
At first, I had been using this, so I had no worries. We thought that Linux could run on an independent terminal. I have read it and found that it is a new feature after 2.6.16, Which is improved after 2.6.18. It is the VM mechanism. Of course, multi-core computers are required.
I
Terminals will try to run your program with VM in short time. SSH
After name @ server, you can directly open MATLAB on the Linux host, and then you can see the graphical interface. You can finish your work and wait. On the terminal, press
CTRL-Z: Return to the terminal command line and place the BG command in the background. Then, exit the terminal with exit. At this time, you will find that MATLAB is still running on your computer. However, this is only the graphic world.
. And has no substantial effect. It is just a VM interface of X winserver on your computer.

In addition, your tty output will be stored in your directory on the host. The screen output of MATLAB is invisible. Therefore, you must use standard output to write the results to files.

3) MATLAB
Server.
This is highly targeted. You need to install the Toolbox related to the MATLAB server support on your computer, and then you can have other computers on the server complete your computation for you. Server features
The special command set is defined in the toolbox, and the general operation is no different from the local operation. If you are interested in the question about server, I 'd like to discuss it again.

 

 

Example:

 

/Usr/bin/nohup/usr/local/Matlab/bin/Matlab-C/root/maid/crack/lic_standalone.dat-nodisplay </usr/local/Matlab/work/music_recommend_code_ver4.0/ test. M 1> running. log 2> running. err &

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.