cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Calculation time

SOLVED
Highlighted
Newbie

Calculation time

How can I improve the calculation time? Especially for the solve blocks.

Any files that I can read? Tips? The file Improving Mathcad Calculation Speed was recently removed from the site.

Thank you,

Mihai Moraru

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Re: Calculation time

OK, the second solve block calls a parameterized solve block. It's loop within a loop, and if one pass of the inner loop takes 0.25 seconds then that's going to be slow! If the first solve block has 6 parameters and 11 equations then it is also a minimization problem (as opposed to Find). Can you reformulate the problem to put everything in one solve block? Failing that, the only solution is to speed up the first solve block. Can you say any more about the equations in that solve block?

View solution in original post

12 REPLIES 12
Highlighted

Re: Calculation time

MihaiMoraru wrote:

How can I improve the calculation time? Especially for the solve blocks.

There is no general answer to this question - it depends on a lot of factors.

If you have a concrete problem you may post the sheet and see if someone comes up with a speed up.

Any files that I can read? Tips? The file Improving Mathcad Calculation Speed was recently removed from the site.

Usually files ond postings are not removed from this forum.

You don't state which Mathcad version you are working with, so I assume Mathcad 15.

Maybe you are talking about the quicksheet: Click "Help"/"Quicksheets"/"Mathcad Techniques"/"Improving Calculation Speed"

You may also search this forum for "calculation speed" or similar.

What we found out here a sghort time ago was that programs using stack() and augment() are much slower than programs with selfwritten routines - incomprehensible, but true.

Highlighted

Re: Calculation time

Werner Exinger wrote:

What we found out here a sghort time ago was that programs using stack() and augment() are much slower than programs with selfwritten routines - incomprehensible, but true.

Indeed, it is better to create your own routine instead of using stack(). The built-in routine was slower than my routine for arranging the solution of a SolveBlock.

Thank you Werner.

Highlighted

Re: Calculation time

MihaiMoraru wrote:

...The file Improving Mathcad Calculation Speed was recently removed from the site...

"Improving Mathcad Calculation Speed" article from PTC Express:

http://www.imakenews.com/ptcexpress/e_article001093581.cfm?x=bcG4481,b3jsqcsB,w

http://www.imakenews.com/eletra/gow.cfm?z=ptcexpress%2C262285%2Cb3jsqcsB%2C2340181%2CbcG4481

The worksheet for MC13 can be found in attachment.

Highlighted

Re: Calculation time

As Werner says, there's no simple answer to that question. Posting a worksheet would help a lot.

Here is one thread that expands (a lot) on what the quicksheet says about vectorization:

http://communities.ptc.com/message/154931#154931

Highlighted

Re: Calculation time

I would like to upload it... unfortunetly I cannot , and is not due to the 'advanced editor'.

But I can tell a bit more on the worksheet. Briefly:

- one parameterized (6 parameters) SolveBlock (11 equations)

- one objective function formed using the (partial) solution of the parameterized SolveBlock: an SSE = sum(exp(i)-calc(i))^2, i=1..7

- one SolveBlock for minimization of the SSE function (containing the 6 parameters)

So, how do I improve the calculation time when dealing particularly with SolveBlocks?

About two hours it takes to solve the optimization problem - MathcadPrime2.0.

I read the QuickSheets (Werner Exinger), the article (VladimirN.) and the thread (Richard Jackson) and is very helpful. Thank you all very much.

Mihai

Highlighted

Re: Calculation time

Really hard to say w/o the sheet (and probably hard with the sheet, too). Whats the problem with uploading? Technical problem (try later again; I sometimes have those probs with inserting pics in my posts) or because of proprietary confidential data in the sheet?

Don't be sure from your description if it could help (in fact I doubt it), but in Prime2 you can turn on multithreading which should speed up parallel calculations on multiprocessor machines.

Highlighted

Re: Calculation time

Werner Exinger wrote:

Whats the problem with uploading? Technical problem (try later again; I sometimes have those probs with inserting pics in my posts) or because of proprietary confidential data in the sheet?

Proprietary unfortunately.

Werner Exinger wrote:

Don't be sure from your description if it could help (in fact I doubt it), but in Prime2 you can turn on multithreading which should speed up parallel calculations on multiprocessor machines.

With and without multithreading the same number of CPUs are used and the same CPUs usage %. Interesting is that the later is about 20%... I was expecting to be 80 - 90% (independent of activated or not the multithreading option). I will give it a full try.

Thank you.

Highlighted

Re: Calculation time

I assume exp(i) means experimental. Calculate a vector of residuals rather than the SSE.

Resid(parameters):=exp(i)-calc(i)

Pass the vector of residuals to the solve block

Given

Resid(parameters)=0

Answer:=minerr(parameters)

That is faster in Mathcad 15. I've never tried it in Prime, but it may also be faster.

Having said that, with only 7 experimental values to fit it should usually converge in less than a second. Can you tell us more about the formula for calc(i)? Does it contain numeric integrals, derivatives? Does it take a long time to calculate one value? I suspect that's where the root of the problem lies.

Highlighted

Re: Calculation time

Richard Jackson wrote:

I assume exp(i) means experimental. Calculate a vector of residuals rather than the SSE.

Resid(parameters):=exp(i)-calc(i)

Pass the vector of residuals to the solve block

Given

Resid(parameters)=0

Answer:=minerr(parameters)

Yes, exp(i) means experimental. I calculated a vector of residuals (using only one parameter to solve for so I can have a quick insight) and used minerr instead of Minimize. And indeed, miner is faster but it saved only 1 min (from 20 to 19).

Using the residuals or SSE makes almost no difference (0.2 min - one parameter as before) - at least in my calculations.

Richard Jackson wrote:

Can you tell us more about the formula for calc(i)? Does it contain numeric integrals, derivatives?

The equations in the first SolveBlock contains nonlinear terms, but does not contains integrals or derivatives.

Richard Jackson wrote:

Does it take a long time to calculate one value? I suspect that's where the root of the problem lies.

The solution of the first SolveBlock takes about 0.25 sec, so at least we identified the (block) root of the problem.

I tried also different initial guesses, scaled the 6 parameters in the same order of magnitude... without any improvement. I will investigate more. Thank you very much for the help.

Mihai

Highlighted

Re: Calculation time

OK, the second solve block calls a parameterized solve block. It's loop within a loop, and if one pass of the inner loop takes 0.25 seconds then that's going to be slow! If the first solve block has 6 parameters and 11 equations then it is also a minimization problem (as opposed to Find). Can you reformulate the problem to put everything in one solve block? Failing that, the only solution is to speed up the first solve block. Can you say any more about the equations in that solve block?

View solution in original post

Highlighted

Re: Calculation time

Richard Jackson wrote:

Can you reformulate the problem to put everything in one solve block? Failing that, the only solution is to speed up the first solve block. Can you say any more about the equations in that solve block?

I could try to reformulate that in a single block, however I have some concerns that it will work. The solution calc(i) comes from the block in the form of calc(c1, c2... cN, p1,p1... p6), where c1... cN are vectors of 7 values each, since each experiment comes with a set of N constants. In the SolveBlock, I keep them as parameters - free - as shown... and after the block I insert the values. This leads me to the calc(p1, p2... p6) solution (of course, including any 6 values for the parameters, this solution is a 7 x 11 matrix). So, I do not think that inside the SolveBlock is allowed to write the equations in the form: x[i = z[i

However, I am not sure if I could use the vectorized form x = z (with the vectorization arrow above both, x and z).

And even if I succeed in doing everything in a SolveBlock and use minner, at a later stage I will have to include in the model the derivatives of the current equations. So, I would have to both integrate (most probably using Odesolve) and to make the optimization using minerr or minimize... and therefore, I would need again the two SolveBlocks.

So, what I can do is to reduce the calculation time for any individual operation/block that I have. Following this idea, I removed from the first SolveBlock the equations of the form f(unknown1, unknown2,...) and I included their actual axpressions (e.g. unknown1 + unknown2 * unknown3, etc). And this gave me an improvement.

But since I have to see if there are other minima (and there are) and see which is most satisfactory in terms of best fit (I always look at the SSE or reziduals), I have to start also from different guess values for the six parameters... and the calculation time is very sensitive to that.

I will keep looking for improvements. Thank you for your reply; they are very helpful.

Highlighted

Re: Calculation time

So, from what I learned, the calculation time can be reduced by:

- using a single SolveBlock instead of multiple, where possible

- writing the actual expressions in the SolveBlock, and not calling them (do not define them 'above' the SolveBlock and then use them in the block)

In calculation loops, reducing the limiting calculation sequence will reduce the overall calculation time.

Basically, it is about reducing the number of operations and function evaluations as much as possible.

At least, these gave some improvement in my calculations.

Announcements