From https://turing.phas.ubc.ca/mediawiki/index.php/Matlab
Using multiple processors
All the documentation seems to suggest that matlab will automatically use as many processors as it cat, however this does not appear to be the case in practice. The number of processors to use must be configured on a a per-user basis. This is actually probably a good thing, because it will get you to think about the most efficient way to use computational resources to execute your jobs. There are two ways to instruct matlab to use multiple processors. You can do so from the command line using the maxNumCompThreads (case sensitive) function which takes as an arument the number of threads to use and returns the number that was previously in use. For example, to use a maximum of 4 threads, you would use
>> maxNumCompThreads(4)
The number of processors set in this way does not remain fixed between matlab sessions. The other way to configure the number of processors used is through the preferences GUI. Changes made to the number of computational threads using the GUI will persist between matlab sessions. This GUI however requires java virtual machine, so you must either be running the full matlab GUI, or using the -nodesktop option as described above. If one of these is the case, then you should be able to type preferences on the command line and get the preferences tree. Navigate to General->Multithreading. Make sure that enable multithreaded computation is checked and select the manual radio button. You can then enter the number of threads to use in the adjacent field. Note that increasing the number of threads to greater than the number of processors will likely result in poorer performance, though there may be some rare cases where it is beneficial. You might want to try playing around with setting the processor affinity of matlab based on the number of threads you tell matlab to use.
Running batch matlab jobs If you want to start matlab from a shell script without requiring user interaction, you are, first of all probably in the target audience for running long jobs. You will also definitely want to use the -nojvm option since there is no need for a user interface when there is no user interaction. Finally, in order to give matlab something to do without a user there to tell it, you must give it the -roption, where "" is usually the name of a pre-prepared Matlab script or function, but can be any valid matlab command line. It is however generally a good idea to enclose in quotes so it is not evaluated by the shell. For example, the most basic command you might use to invert a large random matrix is matlab -nojvm -r 'a=rand(2^13);inv(a);save rand_inv;exit' [edit]nohup Of course, this isn't terribly useful by itself, because your terminal will just sit there until the job is done and the job would be lost if you closed that terminal or logged out. You will likely want to use nohup. You will however need to add "< /dev/null" to the end of the full nohup command. This explicitly tells matlab not to expect any user input from the terminal which you want to detach it from. Your command would look something like this: nohup matlab -nojvm -nosplash -r 'inv(rand(2^13))' < /dev/null > inv.out & This seems to be important because when matlab backs out to its command line it will FREAK OUT if something's not attached to the controlling terminal. By redirecting /dev/null (literally nothing) to standard input, matlab will just quit once it's done rather than waiting for user input that will never come.
Using multiple processors
All the documentation seems to suggest that matlab will automatically use as many processors as it cat, however this does not appear to be the case in practice. The number of processors to use must be configured on a a per-user basis. This is actually probably a good thing, because it will get you to think about the most efficient way to use computational resources to execute your jobs. There are two ways to instruct matlab to use multiple processors. You can do so from the command line using the maxNumCompThreads (case sensitive) function which takes as an arument the number of threads to use and returns the number that was previously in use. For example, to use a maximum of 4 threads, you would use
>> maxNumCompThreads(4)
The number of processors set in this way does not remain fixed between matlab sessions. The other way to configure the number of processors used is through the preferences GUI. Changes made to the number of computational threads using the GUI will persist between matlab sessions. This GUI however requires java virtual machine, so you must either be running the full matlab GUI, or using the -nodesktop option as described above. If one of these is the case, then you should be able to type preferences on the command line and get the preferences tree. Navigate to General->Multithreading. Make sure that enable multithreaded computation is checked and select the manual radio button. You can then enter the number of threads to use in the adjacent field. Note that increasing the number of threads to greater than the number of processors will likely result in poorer performance, though there may be some rare cases where it is beneficial. You might want to try playing around with setting the processor affinity of matlab based on the number of threads you tell matlab to use.
Running batch matlab jobs If you want to start matlab from a shell script without requiring user interaction, you are, first of all probably in the target audience for running long jobs. You will also definitely want to use the -nojvm option since there is no need for a user interface when there is no user interaction. Finally, in order to give matlab something to do without a user there to tell it, you must give it the -r

