Very slow calculation

Very slow calculation - Сообщения

#1 Опубликовано: 29.04.2021 06:13:23
hrwang

hrwang

0 сообщений из 8 понравились пользователям.

Группа: User

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 (39 КиБ) скачан 43 раз(а).
#2 Опубликовано: 29.04.2021 09:12:28
Alvaro Diaz Falconi

Alvaro Diaz Falconi

992 сообщений из 1674 понравились пользователям.

Группа: User

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:

Wrote

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.
#3 Опубликовано: 29.04.2021 09:46:01
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: User

Wrote

Any trick to solve this ?


The two red matrices complain

Example.sm (51 КиБ) скачан 31 раз(а).

#4 Опубликовано: 30.04.2021 02:34:56
hrwang

hrwang

0 сообщений из 8 понравились пользователям.

Группа: User

Wrote

Wrote

Any trick to solve this ?


The two red matrices complain

Example.sm (51 КиБ) скачан 31 раз(а).



Thanks!
#5 Опубликовано: 30.04.2021 02:39:38
hrwang

hrwang

0 сообщений из 8 понравились пользователям.

Группа: User

Wrote

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:

Wrote

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

#6 Опубликовано: 30.04.2021 09:30:22
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: User

Wrote

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.
#7 Опубликовано: 03.05.2021 05:25:39
hrwang

hrwang

0 сообщений из 8 понравились пользователям.

Группа: User

Wrote

Wrote

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.

#8 Опубликовано: 03.05.2021 09:08:30
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: User

Wrote

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
#9 Опубликовано: 04.05.2021 07:52:02
hrwang

hrwang

0 сообщений из 8 понравились пользователям.

Группа: User

Wrote

Wrote

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.
#10 Опубликовано: 04.05.2021 09:46:25
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: User

Wrote

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 (68 КиБ) скачан 30 раз(а).
#11 Опубликовано: 05.05.2021 07:06:03
hrwang

hrwang

0 сообщений из 8 понравились пользователям.

Группа: User

Wrote

Wrote

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 (68 КиБ) скачан 30 раз(а).



Thanks!
  • Новые сообщения Новые сообщения
  • Нет новых сообщений Нет новых сообщений