<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
  <channel>
    <title>MaplePrimes - comments on Post, Calling procedures from for loops makes calculation take longer???</title>
    <link>http://www.mapleprimes.com/posts/42825-Calling-Procedures-From-For-Loops-Makes</link>
    <language>en-us</language>
    <copyright>2026 Maplesoft, A Division of Waterloo Maple Inc.</copyright>
    <generator>Maplesoft Document System</generator>
    <lastBuildDate>Wed, 10 Jun 2026 17:15:15 GMT</lastBuildDate>
    <pubDate>Wed, 10 Jun 2026 17:15:15 GMT</pubDate>
    <itunes:subtitle />
    <itunes:summary />
    <description>The latest comments added to the Post, Calling procedures from for loops makes calculation take longer???</description>
    <image>
      <url>http://www.mapleprimes.com/images/mapleprimeswhite.jpg</url>
      <title>MaplePrimes - comments on Post, Calling procedures from for loops makes calculation take longer???</title>
      <link>http://www.mapleprimes.com/posts/42825-Calling-Procedures-From-For-Loops-Makes</link>
    </image>
    <item>
      <title>hardware and software floats</title>
      <link>http://www.mapleprimes.com/posts/42825-Calling-Procedures-From-For-Loops-Makes?ref=Feed:MaplePrimes:Calling procedures from for loops makes calculation take longer???:Comments#comment79839</link>
      <itunes:summary>You wrote of transmission0 and reflection0, that, "all they contain are simple floats."

As described, however, the code is generating a great many so-called software floats. Maple will dispose of those, once no longer needed, during garbage collection. But that extra garbage collection adds to the total overhead. If you really just need the Matrices to store floating-point numbers, and if hardware double-precision is sufficient, then consider placing an appropriate datatype on the Matrices.

For example,
&gt; transmission0:=Matrix(1200,2,datatype=float[8]):
and similarly for reflection0, re, and te.

You might also be able to fill the first column of both transmission0 and reflection0 more quickly, by pulling the assignments (into their first columns) out of the loop. Completely outside of the loop, create a Vector,
&gt; firstcol := Vector(1200,(j)-&gt;0.0416666666*j,datatype=float[8]):
and also do, outside the loop,
&gt; transmission0[1..1200,1] := firstcol:
&gt; reflection0[1..1200,1] := firstcol:

I hope I got that right.

There might be more efficient ways to initialize the second column too, but it's not possible to say without knowing how rcwa writes to te and re depending on M and how M changes with m.

Also, if you made rcwa accept re and te as parameters (it should still be able to update them efficiently, inplace, if they had float[8] datatype), while also making rcwa return M instead of writing to it as a global, then perhaps you could then run rcwa under the faster purely floating-point evalhf interpreter.  See the help-page ?evalhf for details.

acer</itunes:summary>
      <description>The latest comments added to the Post, Calling procedures from for loops makes calculation take longer???</description>
      <guid>79839</guid>
      <pubDate>Mon, 05 Jun 2006 16:06:31 Z</pubDate>
      <itunes:author>acer</itunes:author>
      <author>acer</author>
    </item>
    <item>
      <title>Thank you very much for your</title>
      <link>http://www.mapleprimes.com/posts/42825-Calling-Procedures-From-For-Loops-Makes?ref=Feed:MaplePrimes:Calling procedures from for loops makes calculation take longer???:Comments#comment86492</link>
      <itunes:summary>Thank you very much for your help. I have tried your datatype suggestions but this doesn't make any difference, and the other things in the for loop take up such a small fraction of the computation time that they cannot be causing the problem either. It is definitely a little weird as yesterday I ran it identically to before and the effect did not happen. But then I tried it this morning and it was there again. I have gone through all my processes and performance and there is nothing stealing memory or cpu time, as well as the fact that the first time round the loop always goes at the speed it should, but only subsequent times take ages and then they each stay about a constant time as opposed to going up and down. It really confuses me as I can't see what is causing it. Still it might give me an excuse to order a new computer at work as maybe I am just getting too close to my RAM limit (although task manager says that I am not, and anyway each time round the loop should use the same amount of memory so it should be a problem the first time too) and it still seems to happen when I use my own computer at home which has double the memory as well.

Thanks again.</itunes:summary>
      <description>The latest comments added to the Post, Calling procedures from for loops makes calculation take longer???</description>
      <guid>86492</guid>
      <pubDate>Tue, 06 Jun 2006 18:08:02 Z</pubDate>
      <itunes:author>py9mrg</itunes:author>
      <author>py9mrg</author>
    </item>
    <item>
      <title>what happens if you delay garbage collection?</title>
      <link>http://www.mapleprimes.com/posts/42825-Calling-Procedures-From-For-Loops-Makes?ref=Feed:MaplePrimes:Calling procedures from for loops makes calculation take longer???:Comments#comment90699</link>
      <itunes:summary>One way to experiment with whether the extra time may be due to garbage collection (gc), is to increase the limit that controls gc frequency.

For example, set,
&gt; kernelopts(gcfreq=10^8):
and then see what efect that has on the repeated loop timings.

acer</itunes:summary>
      <description>The latest comments added to the Post, Calling procedures from for loops makes calculation take longer???</description>
      <guid>90699</guid>
      <pubDate>Tue, 06 Jun 2006 19:04:44 Z</pubDate>
      <itunes:author>acer</itunes:author>
      <author>acer</author>
    </item>
    <item>
      <title>Wow, you've hit the nail on the head there!</title>
      <link>http://www.mapleprimes.com/posts/42825-Calling-Procedures-From-For-Loops-Makes?ref=Feed:MaplePrimes:Calling procedures from for loops makes calculation take longer???:Comments#comment90700</link>
      <itunes:summary>Thank you very very much! Not only does the effect not happen anymore, but also one single cycle of my loop is now much faster than it was so my code is now running faster than it ever has.

Sorry to be a pain, but.... I don't know what the subtleties of this garbage collection function are however, so I am wondering how far can I push this? I notice that when I use the command you kindly gave me the memory useage goes up quite alot. Which is fine by me considering my code is now much faster. As I understand it what you have done is to slow down the frequency that maple does it's garbage collection routine, which obviously increases the amount of memory it uses as there is more garbage lurking about? Does this mean that if I experiment with increasing it further my code will continue to get faster until I get to my RAM limit at which point I will be using my harddisk more and it will slow down again? In other words if I increase gcfreq until I am just inside my RAM limit then this will be the maximum possible speed I will be able to get my code to function by changing garbage collection?

Thank you again for all your help.</itunes:summary>
      <description>The latest comments added to the Post, Calling procedures from for loops makes calculation take longer???</description>
      <guid>90700</guid>
      <pubDate>Wed, 07 Jun 2006 01:45:49 Z</pubDate>
      <itunes:author>py9mrg</itunes:author>
      <author>py9mrg</author>
    </item>
  </channel>
</rss>