Group Abstract Group Abstract

Message Boards Message Boards

0
|
12K Views
|
12 Replies
|
1 Total Like
View groups...
Share
Share this post:

Speed up evaluation time of a code

Posted 5 years ago

Hello , I hope everyone is ok at Corona virus times. I would like to speed up my attached code.
For large K's and the small values of T/M, my code runs slowly.
Please do not hesitate to ask me anything.

Attachments:
POSTED BY: Vedat Erturk
12 Replies

Vedat Erturk I'll try to help: give you some ideas to try. Using an array for: α1=1;α2=1;α3=1;α4=1;α5=1; α={1,1,1,1,1} and referencing as: α[[I]] could help. Maybe better as a[i_].Other variables could also be assigned to an array/ given a number instead of a variable name. In most model Intel based machines :ParallelTable[] and ParallelSum[] speed up calculations by the number of processes your machine allows. Integrations might be better as NIntegrate for time saving. Do Loops have ever been slow in Mathematica. Replacing the loops with Block[] might help as sometimes used in fractal programs. Compiling the Do loop section might also speed up the calculation process. I know the Parallel idea works for at least 10 places in your program. In all: buy yourself the fastest computer you can get (with as many processors as you can) with the most built in memory (16 gb or more): then the slowness of Mathematica will fade, LOL. Good luck in your real world programming. Roger Lee Bagula

POSTED BY: Roger L. Bagula
Posted 5 years ago

Hello again Roger L. Bagula ; Could you help me speed my code up for large M, for example M=20?Attached.

Attachments:
POSTED BY: Vedat Erturk
Posted 5 years ago
POSTED BY: Bill Nelson
Posted 5 years ago

Hello Bill again.No problem.Please do all things in your mind and then send me your code.I will do error analysis myself.

POSTED BY: Vedat Erturk
Posted 5 years ago
POSTED BY: Bill Nelson

Hi Vedat, To speed up your code, use decimal number everywhere possible (like for the alpha terms could be 1.0 instead of 1, for example). Mathematica won't try to compute exact values using floating point numbers.

Try storing values of functions in memory. The function will reuse a result instead of calculating it again.

Slow fib

sfib[0] := 1 
sfib[1] := 1 
sfib[x_] := sfib[x - 1] + sfib[x - 2]
sfib[20] // AbsoluteTiming
?sfib

Fast fib

fib[0] := 1 
fib[1] := 1 
fib[x_] := fib[x] = fib[x - 1] + fib[x - 2]
fib[20] // AbsoluteTiming
?fib

These two techniques have significantly improved the speed of my code. There are other techniques to improve code speed and these can be found in the following resources. 10 Tips for Writing Fast Mathematica Code Tips for Writing Fast Code Sincerely, Jay Morreale

POSTED BY: Jay Morreale
Posted 5 years ago

I should be able to get the K at least 10.

POSTED BY: Vedat Erturk
POSTED BY: Roger L. Bagula
Posted 5 years ago
POSTED BY: Vedat Erturk
Posted 5 years ago
Attachments:
POSTED BY: Vedat Erturk
Posted 5 years ago

For anyone to consider taking their time to study your program and suggest how to speed it up I expect they are almost certainly going to want to quickly and easily understand exactly which of all your many subscripts are connected to which of all your many variables.

Consider the first example

x[t_]:=10;
  0,0

Is it the x that is double subscripted? Or the t double subscripted, or do x and t each have one subscript? Hopefully it is not the 10 that is subscripted.

Your displayed program is filled with vast numbers of examples exactly like this. Even clicking on "Make your own copy" gives exactly the same subscript issue. And downloading the pdf file gives exactly the same subscript issue.

Is there any way that you might be able to display your entire program in InputForm ? That would remove all the two-dimensional formatting and all the positioning of all your subscripts. That might make it more feasible for someone to understand exactly what your program is doing and even be able to paste that directly into their Mathematica notebook and perform small experiments to see if a change results in a substantial increase in speed.

You write "For large K's and the small values of T/M, my code runs slowly." Can you give us some idea what "large K" is? 10^3? 10^6? 10^12? And exactly the same question for M. Are you doing thousands or millions of Simplify and thousands or millions or even billions of Integrate? Approximately how many of each of those, potentially complicated and slow, operations are you doing?

Thank you

POSTED BY: Bill Nelson
Posted 5 years ago

Hello Roger,Thank you for suggestions. I shall try to do the suggestions you told. one by one. Let us start with " Using an array for: α1=1;α2=1;α3=1;α4=1;α5=1; α={1,1,1,1,1} and referencing as: α[[I]] could help. ".Can you please give a simple example as a code?

POSTED BY: Vedat Erturk
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard