Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Offline hrwang  
#1 Posted : 29 April 2021 12:13:23(UTC)
hrwang

Rank: Newbie

Groups: Registered
Joined: 29/04/2021(UTC)
Posts: 8
United States

Calculation appears simple, but takes forever. Some of the parameters have units, but I did the dimensionless in the for loop. I suspect the variables stored the expression instead of results, which could take too much memory? I don't know.

When I interrupt the calculation, it stopped at 2nd for loop, i=50 and j=9. Some of the variables has expression, for example, vs(i,j), some of the value was the initial value of -1, but calculated values has units that wasn't canceled. vs is supposed to be dimensionless.

Any trick to solve this?

Thanks!

Example.sm (40kb) downloaded 21 time(s).
Offline Razonar  
#2 Posted : 29 April 2021 15:12:28(UTC)
Razonar


Rank: Advanced Member

Groups: Registered
Joined: 28/08/2014(UTC)
Posts: 713
Uruguay

Was thanked: 368 time(s) in 244 post(s)
Hi. Two issues. First, you use two percent symbols, but forgot to put them as units: try to add them as '%, and they goes in blue color.

Clipboard02.jpg

For the second, your observation now it's correct:

Originally Posted by: hrwang Go to Quoted Post
I suspect the variables stored the expression instead of results, which could take too much memory?


and can speed up a little the calculation using eval for each line:

Clipboard01.jpg

Best regards
Alvaro.
Offline Jean Giraud  
#3 Posted : 29 April 2021 15:46:01(UTC)
Jean Giraud


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 5,310
Canada

Was thanked: 840 time(s) in 670 post(s)
Originally Posted by: hrwang Go to Quoted Post
Any trick to solve this ?

The two red matrices complain

Example.sm (52kb) downloaded 7 time(s).

Offline hrwang  
#4 Posted : 30 April 2021 08:34:56(UTC)
hrwang

Rank: Newbie

Groups: Registered
Joined: 29/04/2021(UTC)
Posts: 8
United States

Originally Posted by: Jean Giraud Go to Quoted Post
Originally Posted by: hrwang Go to Quoted Post
Any trick to solve this ?

The two red matrices complain

Example.sm (52kb) downloaded 7 time(s).



Thanks!
Offline hrwang  
#5 Posted : 30 April 2021 08:39:38(UTC)
hrwang

Rank: Newbie

Groups: Registered
Joined: 29/04/2021(UTC)
Posts: 8
United States

Originally Posted by: Razonar Go to Quoted Post
Hi. Two issues. First, you use two percent symbols, but forgot to put them as units: try to add them as '%, and they goes in blue color.

Clipboard02.jpg

For the second, your observation now it's correct:

Originally Posted by: hrwang Go to Quoted Post
I suspect the variables stored the expression instead of results, which could take too much memory?


and can speed up a little the calculation using eval for each line:

Clipboard01.jpg

Best regards
Alvaro.


Thanks a lot. It appears, eval is a very important function. I tried to eval every dimensionless variables and functions, such as OsP, dr before the loop. And it took some time finished the calculation. Still, takes ages long comparing to mathcad.

I hope the developer can improve this part soon. After all, the calculation load in my program is not heavy. I am really afraid if I introduce some iterations.

Thanks again

hrwang

Offline Jean Giraud  
#6 Posted : 30 April 2021 15:30:22(UTC)
Jean Giraud


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 5,310
Canada

Was thanked: 840 time(s) in 670 post(s)
Originally Posted by: hrwang Go to Quoted Post
Still, takes ages long comparing to Mathcad.

Mathcad is a semi-compiled CAS.
In separate mode my 1.66 GHz Win 7 calculates the 4 matrices in 18 seconds.
Offline hrwang  
#7 Posted : 03 May 2021 11:25:39(UTC)
hrwang

Rank: Newbie

Groups: Registered
Joined: 29/04/2021(UTC)
Posts: 8
United States

Originally Posted by: Jean Giraud Go to Quoted Post
Originally Posted by: hrwang Go to Quoted Post
Still, takes ages long comparing to Mathcad.

Mathcad is a semi-compiled CAS.
In separate mode my 1.66 GHz Win 7 calculates the 4 matrices in 18 seconds.


I have nz and nr both 200. It took about 10minutes in Smath to finish the whole program.

It appears the for loop takes a lot of time. If you can replace for loop with a matrix operator, such as SUM operator, it calculates faster. Personal experience, I don't know why.

Offline Jean Giraud  
#8 Posted : 03 May 2021 15:08:30(UTC)
Jean Giraud


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 5,310
Canada

Was thanked: 840 time(s) in 670 post(s)
Originally Posted by: hrwang Go to Quoted Post
I have nz and nr both 200. It took about 10minutes in Smath to finish the whole program.
It appears the for loop takes a lot of time. If you can replace for loop with a matrix operator, such as SUM operator, it calculates faster. Personal experience, I don't know why.

Leave them in separate modules, then collapse, it might reduce timing by ½.
Can you show an example of your matrix operator ... Unknown to me.

Timing.PNG
Offline hrwang  
#9 Posted : 04 May 2021 13:52:02(UTC)
hrwang

Rank: Newbie

Groups: Registered
Joined: 29/04/2021(UTC)
Posts: 8
United States

Originally Posted by: Jean Giraud Go to Quoted Post
Originally Posted by: hrwang Go to Quoted Post
I have nz and nr both 200. It took about 10minutes in Smath to finish the whole program.
It appears the for loop takes a lot of time. If you can replace for loop with a matrix operator, such as SUM operator, it calculates faster. Personal experience, I don't know why.

Leave them in separate modules, then collapse, it might reduce timing by ½.
Can you show an example of your matrix operator ... Unknown to me.

Timing.PNG


I don't understand how to do it in separate modules? The matrix operator are listed in the program, such as SUM operator(sigma), multiple operator(pi). They are the special cases. For example, you can find the sum of an array either use for loop, or SUM operator.
Offline Jean Giraud  
#10 Posted : 04 May 2021 15:46:25(UTC)
Jean Giraud


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 5,310
Canada

Was thanked: 840 time(s) in 670 post(s)
Originally Posted by: hrwang Go to Quoted Post
I don't understand how to do it in separate modules ? The matrix operator are listed in the program, such as SUM operator(sigma), multiple operator(pi). They are the special cases. For example, you can find the sum of an array either use for loop, or SUM operator.

1. Separate modules in the attached... Two complain, but produce.
2. Try matrix operator matrix(3,4) to see if it can help you wrt the project.
3. I know no other way to construct your 4 matrices.
4. From the matrices, your can select any col/row
... you can sub-range any part ... you can unwrap in single vector.
Cheers ... Jean.

Example.sm (69kb) downloaded 4 time(s).
Offline hrwang  
#11 Posted : 05 May 2021 13:06:03(UTC)
hrwang

Rank: Newbie

Groups: Registered
Joined: 29/04/2021(UTC)
Posts: 8
United States

Originally Posted by: Jean Giraud Go to Quoted Post
Originally Posted by: hrwang Go to Quoted Post
I don't understand how to do it in separate modules ? The matrix operator are listed in the program, such as SUM operator(sigma), multiple operator(pi). They are the special cases. For example, you can find the sum of an array either use for loop, or SUM operator.

1. Separate modules in the attached... Two complain, but produce.
2. Try matrix operator matrix(3,4) to see if it can help you wrt the project.
3. I know no other way to construct your 4 matrices.
4. From the matrices, your can select any col/row
... you can sub-range any part ... you can unwrap in single vector.
Cheers ... Jean.

Example.sm (69kb) downloaded 4 time(s).


Thanks!
Users browsing this topic
Similar Topics
Sometimes VERY slow calculation time in program loops (Questions)
by themzlab 15/02/2017 17:52:49(UTC)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.