Slow calculation

Slow calculation - Сообщения

#1 Опубликовано: 19.12.2023 23:55:54
Fikret Atalay

Fikret Atalay

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

Группа: User

Hi all, I am putting together a quick worksheet to calculate factor of safety against soil liquefaction triggering. As I have been going step-by-step and defining the various variables, I noticed that all the calculations take place more or less instantaneously, whereas the last variable I defined (N1_60cs) seems to take a relatively long time to calculate (approximately 12 seconds on my machine). The worksheet I have so far is attached.

Any thoughts as to what is causing this? Thanks in advance!

Seismic Site Class & Liquefaction Potential.sm (124 КиБ) скачан 30 раз(а).
#2 Опубликовано: 20.12.2023 00:50:59
Davide Carpi

Davide Carpi

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

Группа: Moderator

Hi,

select all > optimization > numeric

AND EITHER

z:z

z def z.png

OR

z:+line(...)

z plus.png


This is because z:line() is a procedure (something like a function, but for variables); it doesn't evaluates in place on definition, hence is completely calculated from scratch every time you need z, z[j], etc....
Using a + between the definition operator and the line() function, you don't have anymore a procedure; using z:z, it evaluates once from that point onwards.


Seismic Site Class & Liquefaction Potential_num.sm (124 КиБ) скачан 33 раз(а).
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
#3 Опубликовано: 20.12.2023 01:01:15
Fikret Atalay

Fikret Atalay

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

Группа: User

Perfect, that works!

Much appreciated as always!
#4 Опубликовано: 20.12.2023 01:23:18
Davide Carpi

Davide Carpi

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

Группа: Moderator

You're welcome!
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
#5 Опубликовано: 20.12.2023 01:30:22
Jean Giraud

Jean Giraud

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

Группа: User

Your last for/loop, as given, takes 32 s
isolate the three components
a:=eval(a) , b:=eval(b) ...
timing drops 4 s
#6 Опубликовано: 20.12.2023 02:07:23
Alvaro Diaz Falconi

Alvaro Diaz Falconi

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

Группа: User

Hi. This is another option, without numeric optimizations. You don't need to use line in your calculations. As Davide says, that makes the calculations faster to SMath.

Seismic Site Class & Liquefaction Potential.sm (122 КиБ) скачан 34 раз(а).


Bes regards.
Alvaro.
#7 Опубликовано: 20.12.2023 03:15:47
Fikret Atalay

Fikret Atalay

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

Группа: User

Thank you, Alvaro! I like having the lines because it makes it clearer as to which parameter I am defining. I just didn't realize it was slowing it down so much (although putting + in front of the lines makes the problem go away - sort of a win-win!).

Thanks again.

Wrote

Hi. This is another option, without numeric optimizations. You don't need to use line in your calculations. As Davide says, that makes the calculations faster to SMath.

Seismic Site Class & Liquefaction Potential.sm (122 КиБ) скачан 34 раз(а).


Bes regards.
Alvaro.



#8 Опубликовано: 20.12.2023 03:16:36
overlord

overlord

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

Группа: Moderator

Wrote

Hi. This is another option, without numeric optimizations. You don't need to use line in your calculations.


Another issue is, all calculation can be done under one for() loop.
If data matrices is much longer and not 10, this would benefit too.
However, the way it is written look much nicer and cleaner.
#9 Опубликовано: 20.12.2023 12:07:29
Alvaro Diaz Falconi

Alvaro Diaz Falconi

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

Группа: User

Wrote

I like having the lines because it makes it clearer as to which parameter I am defining.



Hi. You can eliminate all the for loops using the SMath index vectorization, which work more or less like the same concept in matlab, with cases() for having some visual separation

Clipboard01.png

Seismic Site Class & Liquefaction Potential v2.sm (119 КиБ) скачан 34 раз(а).

Best regards.
Alvaro.
  • Новые сообщения Новые сообщения
  • Нет новых сообщений Нет новых сообщений