Jump to content

Assigning resources to Matlab


alogos
 Share

Recommended Posts

Hello.

 

This is my first post. My english might be a little bit rusty, but i'll do my best to express what is troubling me.

As I write this words, my computer is running a Matlab routine searching for the solution to n x n sistem of equations. This routine is supossed to deliver a solution vector which I need in order to go on with my Final Project so as to receive my degree in Material Engineering.

However, Matlab ain't using all the resources the machine can give. For instance, out of the 24 threads, only one is being full solicitated. The same goes on for the RAM memory, only a 17% is being used.

So the question is, is there a way to boost Matlab? How can I assig more resources to Matlab?

Actually, the routine I´m running uses the concept of error function and tries to minimize its value regarding a collection of data sets. The whole process has lots of iterations and symbolic calculus which I´ve test with a simpler problem taken from a textbook example. I know the routine is 0K, and no, it cannot be simpler than already is.

 

Thank you very much for giving me the opportunity to express myself.

 

I won´t have any problems in shearing the code for the routine if any of you want/need it.

Link to comment
Share on other sites

Is the process even parallelizable? If there's no way to split the task up into separate simultaneous units, there's no way to use all 24 possible cores. Adding more memory won't help either, unless there's something that needs to be put in it -- and if so, Matlab would gladly use more memory.

Link to comment
Share on other sites

  • 3 weeks later...

If you seek to make MATLAB increase its performance by utilizing multiple processors: StackOverflow

 

But, if you seek to give MATLAB more processing allowance of your CPU .. then there are two major things:

 

1. Ask your OS to give priority to MATLAB, since OS use Priority-based Round-robin Processing Queue management

.. on Linux, you can use command "nice"

 

2. Here is a different approach to achieve higher performance: Maximize MATLAB Perofrmance

 

.. good luck

Edited by khaled
Link to comment
Share on other sites

First of all, thank you guys for the answers. I´ve been busy with this same work, that is why i haven´t checked your replies to this post before. Sorry I didn't come earlier.

 

With respect to Cap'n Refsmmat question, I guess not. The routine I wrote goes step by step because, in every step, it generates the data that the next step will require. That is why I can't make use of parallelization I suppose. But I still don't see why can't Matlab use more memory. Ain't the next statement true?: "more memory I get, faster the calculation proccess will be".

 

Answer to ecoli: I'm not sure. I was studing that idea when for other reasons i have to make some changes to part of the algorithm. Remember what I say before about the routine: "it cannot be simpler than already is". Well, to my surprise, yes it can. Reading the Matlab help files, I found out that there were some functions that came along with the program which does most of the work I wrote by my own. So for the sake of simplicity, I replace the vast majority of the routine by a few lines. There's always room for improvement.

 

To khaled: I've tried n°1, doesn't seem to make a difference. With respect to n°2, I'm on my way to studying it along with StackOverflow thing. Thank you for the info.

 

 

After I simplify the code, it starts coming to a solution really fast. My guess is that the previous routine uses so many variables that were define at the moment of being use that it slows the whole chain of calculations. Most likely, the implicitly define functions that come with the Matlab code make a better use of the memory assignation to the program variables.

 

Thanks again for the comments and the information.

Link to comment
Share on other sites

It's not always true that using more memory makes a program faster. If Matlab has all the data in memory that it needs, it may not have anything to put in the extra space.

 

Imagine being asked to sort through a pile of papers and find an answer to some particular question. You'd want some desk space to spread the papers out, but beyond a point, having a football field of space doesn't help you any -- you have nothing to put in the space.

Link to comment
Share on other sites

Cap'n Refmmat is right, more memory doesn't always mean faster

 

By the way, If you are using MATLAB on your personal computer or laptop .. then it shouldn't exceed 33% of CPU

 

If you really need higher performance for MATLAB, you can dedicate Clusters for MATLAB .. Clusters of Processing & Memory Units

Edited by khaled
Link to comment
Share on other sites

You seem to have realised at least some of the following, but I shall state it for the record.

Matlab is an interpreted language. I think modern versions have a JIT compiler and some kind of bytecode, but the importance of accuracy means they don't tend to get too tricky.

Some things that may allow you to utilize more of your computer's resources:

Use builtin, library and vectorised operations wherever you can, these tend to be written in C/java/fortran and are highly optimized:

A.*B

is far faster than doing it with a for loop.

Unroll tight loops (any with <10 instructions) if you can -- manually make it do several operations before looping, even eliminate the loop entirely if it's a set small number of instructions. The JIT may take care of this, but it helped on the last version of matlab I was using. You may be able to refactor or vectorize your equations somewhat so that more calculations can be done before you need to use them, sometimes even adding steps/temporary variables can help if it makes it more parallelizable (and memory bandwidth isn't the issue at hand).

Pre-allocate memory where you can.It can be hard to tell with a language like matlab when you are allocating memory, but if you know ahead of time how big a vector/matrix is going to be, pre-set it to a zero array of that size before using it. Whatever you do, avoid incrementally increasing its size in a loop. (again, the jit can sometimes fix this for you, but don't rely on it).

Factorise out and pre-calculate invariants. Explicitly set performance intensive loops to certain lengths if you know what they will be rather than calculating as you go or using a while loop. If there is a number you are calculating repeatedly that is the same or periodic in some way, see if you can pre-calculate it.

 

The most important part is probably the first (built in functions and vectorization) which will tend to overwhelm the effect of the others. Also your algorithmic efficiency will in turn overwhelm effects from this. There is almost always a way of making an algorithm (asymptotically) faster, or making a tradeoff between time and space which is in your favour. The only question is whether the amount of effort required on your part is worth it.

Link to comment
Share on other sites

0k. Now i'm beginning to understand a little bit more about how to write algorithms in Matlab, but i still gonna need more reading.

Schröedinger's hat, what do you mean by saying "Matlab is an interpreted lenguage"? I was familiar with some fortran programming back in the university days, so i understand what the compiler does but, what is a JIT compiler?

 

 

Link to comment
Share on other sites

0k. Now i'm beginning to understand a little bit more about how to write algorithms in Matlab, but i still gonna need more reading.

Schröedinger's hat, what do you mean by saying "Matlab is an interpreted lenguage"? I was familiar with some fortran programming back in the university days, so i understand what the compiler does but, what is a JIT compiler?

 

An interpreted language at its simplest just runs through the instructions that you give it one by one, in the order that you've written them and executes them. There's usually a 1:1 or 1:many relation between things you write and actual machine code, and the order is preserved.

 

This tends to be quite slow. If your program isn't looking ahead and finding out what bits of data it needs where, you can spend a lot of time waiting on memory or something on the hard drive.

One improvement is to look ahead a few instructions and bring stuff into memory or a cache on the CPU, but dynamic languages often don't know what they need ahead of time as the meaning of references can change or arrays can grow etc etc so the benefit of this is limited.

It also passes up opportunities to switch out what you wrote for harder to read/understand stuff that is equivalent and faster.

 

A JIT or just in time compiler presents itself as a simple interpreter, but actually does some compilation on your program before running it. Often this is to another interpreted, but easy for the machine to read (and hard for a human to read) language called a bytecode. Sometimes it is to actual machine code.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.