Message Boards Message Boards

0
|
5359 Views
|
4 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Numerical calcuations slow down unexpectedly

Posted 8 years ago

I am doing numerical calculations with a For loop of 2000 cycles. In each cycle, there are hundreds of floating point calculations. If I set the number of cycles to 100, it takes about 4 sec to finish. However, when the number of cycles is 2000, the code goes fast for the first about 400 cycles but then slows down badly. The total calculation takes about 12 min = 720 sec. But the expected time is about 4 x 20 = 80 sec. I have never seen this before. Can anyone give me some hints? Thanks.

H.H.

POSTED BY: H. H.
4 Replies
Posted 8 years ago

Thanks to everyone. Problem solved but do not know why. My previous code had many expressions of "f[array]" with f a function, and arithmetic operations on those arrays and "f[array]". All those were in the For loop. Now I changed the code in a way that function calculations are outside of the For loop and in the loop, only simple list manipulations. With everything calculated, 4000 cycles only costs 9 sec. I even reinstalled Mathematica and it turned out it was not system problem. I guess over/underflow could be a reason. Thanks again.

H.H.

POSTED BY: H. H.

Hard to say without actual code. Maybe machine over/underflow, causing arithmetic to go to software rather than hardware.

POSTED BY: Daniel Lichtblau

My guess: Use Table instead of For and AppendTo.

POSTED BY: Michael Rogers

It would be better if you attached your code. Without that, it is hard to guess what might be happening.

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

Group Abstract Group Abstract