<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Approximatrix Forums — speed designs questions]]></title>
	<link rel="self" href="https://forums.approximatrix.com/extern.php?action=feed&amp;tid=999&amp;type=atom" />
	<updated>2025-12-06T09:06:07Z</updated>
	<generator>PunBB</generator>
	<id>https://forums.approximatrix.com/viewtopic.php?id=999</id>
		<entry>
			<title type="html"><![CDATA[Re: speed designs questions]]></title>
			<link rel="alternate" href="https://forums.approximatrix.com/viewtopic.php?pid=4532#p4532" />
			<content type="html"><![CDATA[<p>I want to add that I&#039;ve never heard/used PURE/ELEMENT procedures. But I&#039;ve checked 2003&nbsp; (N1601.pdf) and 95 (N1191.pdf) standards and, to my surprise, they are there.</p>]]></content>
			<author>
				<name><![CDATA[GrzegorzW]]></name>
				<uri>https://forums.approximatrix.com/profile.php?id=4153</uri>
			</author>
			<updated>2025-12-06T09:06:07Z</updated>
			<id>https://forums.approximatrix.com/viewtopic.php?pid=4532#p4532</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: speed designs questions]]></title>
			<link rel="alternate" href="https://forums.approximatrix.com/viewtopic.php?pid=4530#p4530" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>designer wrote:</cite><blockquote><p>So a PURE example would start: pure function double_it(x)</p></blockquote></div><p>Correct!</p>]]></content>
			<author>
				<name><![CDATA[jeff]]></name>
				<uri>https://forums.approximatrix.com/profile.php?id=2</uri>
			</author>
			<updated>2025-12-05T18:32:19Z</updated>
			<id>https://forums.approximatrix.com/viewtopic.php?pid=4530#p4530</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: speed designs questions]]></title>
			<link rel="alternate" href="https://forums.approximatrix.com/viewtopic.php?pid=4529#p4529" />
			<content type="html"><![CDATA[<p>So you use the word &quot;pure&quot; in front of the function definition?<br />You elemental example started: elemental function double_it(x)<br />So a PURE example would start: pure function double_it(x)<br />??</p>]]></content>
			<author>
				<name><![CDATA[designer]]></name>
				<uri>https://forums.approximatrix.com/profile.php?id=3903</uri>
			</author>
			<updated>2025-12-05T17:43:17Z</updated>
			<id>https://forums.approximatrix.com/viewtopic.php?pid=4529#p4529</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: speed designs questions]]></title>
			<link rel="alternate" href="https://forums.approximatrix.com/viewtopic.php?pid=4527#p4527" />
			<content type="html"><![CDATA[<p>The <em>PURE</em> attribute is similar to the <em>ELEMENTAL</em> attribute in that it signifies that the function or subroutine has no side effects like changing data that wasn&#039;t passed in or generating file/screen output.&nbsp; The difference is that <em>PURE</em> does not imply it can be used automatically on each element of an array.&nbsp; Basically, an <em>ELEMENTAL</em> subroutine or function is also <em>PURE</em> but the reverse is not true.&nbsp; A <em>PURE</em> function, for example, could accept an array as an input.</p>]]></content>
			<author>
				<name><![CDATA[jeff]]></name>
				<uri>https://forums.approximatrix.com/profile.php?id=2</uri>
			</author>
			<updated>2025-12-05T13:24:39Z</updated>
			<id>https://forums.approximatrix.com/viewtopic.php?pid=4527#p4527</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: speed designs questions]]></title>
			<link rel="alternate" href="https://forums.approximatrix.com/viewtopic.php?pid=4526#p4526" />
			<content type="html"><![CDATA[<p>Jeff, I looked for a description of the PURE modifier by substituting that for elemental in the URL you provided. It was an invalide URL (with pure). I then searched for pure in the Wiki and it gave a list of topics but I didn&#039;t see anything specific about &quot;PURE&quot; itself.</p><p>I&#039;m excited to try this elemental feature. Could be handy. Thank you.</p>]]></content>
			<author>
				<name><![CDATA[designer]]></name>
				<uri>https://forums.approximatrix.com/profile.php?id=3903</uri>
			</author>
			<updated>2025-12-03T18:03:13Z</updated>
			<id>https://forums.approximatrix.com/viewtopic.php?pid=4526#p4526</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: speed designs questions]]></title>
			<link rel="alternate" href="https://forums.approximatrix.com/viewtopic.php?pid=4519#p4519" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>designer wrote:</cite><blockquote><p>I&#039;ll look for the PURE and ELEMENTAL designations but if you have the time, could you please point me in the direction to look for them.</p></blockquote></div><p>There&#039;s a simple writeup of <a href="https://fortranwiki.org/fortran/show/elemental">elemental functions here</a>.&nbsp; Essentially, the function accepts and returns a scalar value, but, since it is marked <em>elemental</em>, you can just pass an array to the function, and the function will be called on each element of said array, returning another array where every value is the return value from the function for its corresponding input element.&nbsp; </p><p>For example, we can write a trivial elemental function that doubles a number:</p><div class="codebox"><pre><code>elemental function double_it(x)
implicit none

    real::double_it
    real, intent(in)::x
    
    double_it = 2.0*x
    
end function double_it</code></pre></div><p>Now, in our calling routine, we could have this:</p><div class="codebox"><pre><code>    real, dimension(4)::x
    real, dimension(4)::doubled_x
    
    x = (/ 1.0, 2.0, 3.0, 4.0 /)
    
    doubled_x = double_it(x)
    
    print *, doubled_x</code></pre></div><p>The output would be:</p><div class="codebox"><pre><code>   2.00000000       4.00000000       6.00000000       8.00000000</code></pre></div><p>Even though my function only accepts a scalar, the <em>elemental</em> modifier means that it will call it for each and every array element if I pass it an array.</p><div class="quotebox"><cite>designer wrote:</cite><blockquote><p>Before this last update, for another problem, you had me change a compiler setting from Native to Generic.&nbsp; I don&#039;t see that compiler setting (Native vs Generic) in the latest Apple Silcone release (Version 3.41, Build 4440).</p></blockquote></div><p>We removed the option entirely since Apple decided to change how it reports the name of their chips, which wasn&#039;t compatible with our compiler at this time.&nbsp; You shouldn&#039;t need to access that option any longer.&nbsp; I believe the latest build also disables the option when creating the makefile as a safety precaution.</p>]]></content>
			<author>
				<name><![CDATA[jeff]]></name>
				<uri>https://forums.approximatrix.com/profile.php?id=2</uri>
			</author>
			<updated>2025-12-02T19:16:23Z</updated>
			<id>https://forums.approximatrix.com/viewtopic.php?pid=4519#p4519</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: speed designs questions]]></title>
			<link rel="alternate" href="https://forums.approximatrix.com/viewtopic.php?pid=4515#p4515" />
			<content type="html"><![CDATA[<p>Thank you Jeff. This code solves problems I need to change a little bit each time. So keeping the parts that don&#039;t change (base conversion) from those that do, helps prevent mistakes. It can take a while to find a missing parenthesis, with the error message &quot;Missing EndIF&quot;.</p><p>I&#039;ll look for the PURE and ELEMENTAL designations but if you have the time, could you please point me in the direction to look for them. Before this last update, for another problem, you had me change a compiler setting from Native to Generic.</p><p>I don&#039;t see that compiler setting (Native vs Generic) in the latest Apple Silcone release (Version 3.41, Build 4440).</p>]]></content>
			<author>
				<name><![CDATA[designer]]></name>
				<uri>https://forums.approximatrix.com/profile.php?id=3903</uri>
			</author>
			<updated>2025-12-01T18:04:57Z</updated>
			<id>https://forums.approximatrix.com/viewtopic.php?pid=4515#p4515</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: speed designs questions]]></title>
			<link rel="alternate" href="https://forums.approximatrix.com/viewtopic.php?pid=4513#p4513" />
			<content type="html"><![CDATA[<p>I almost always err on the side of cleaner code.&nbsp; The time spent &quot;jumping&quot; to a function one million times is going to be negligible on modern hardware, especially if you&#039;re passing in a single argument.&nbsp; By &quot;negligible,&quot; I mean that the jump, even occurring one million times, might not consume a measurable amount of time in total.&nbsp; If you have optimizations on, there&#039;s even a chance that the compiler might decide to &quot;inline&quot; your function call itself, effectively removing the jump operation entirely and performing the operation right where the call was to be made.</p><p>Fortran doesn&#039;t have a general way to force a function to be inlined, though.&nbsp; However, if you mark your function as <strong>PURE</strong> in Fortran, it can improve the optimizations that the compiler can perform.&nbsp; The <strong>PURE</strong> modifier basically tells the compiler that your function takes exactly the inputs provided and outputs exactly one value without any side effects (like printing or changing an input).</p><p>If you have an array of values to convert, you can even mark your function as <strong>ELEMENTAL</strong> and pass the entire array at once, allowing the compiler to further optimize the procedure and calling it however it would like.</p><p>Basically, though, I would keep the conversion in a function.&nbsp; The cost of one call, even one million times, just isn&#039;t measurable.</p>]]></content>
			<author>
				<name><![CDATA[jeff]]></name>
				<uri>https://forums.approximatrix.com/profile.php?id=2</uri>
			</author>
			<updated>2025-12-01T01:10:33Z</updated>
			<id>https://forums.approximatrix.com/viewtopic.php?pid=4513#p4513</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[speed designs questions]]></title>
			<link rel="alternate" href="https://forums.approximatrix.com/viewtopic.php?pid=4512#p4512" />
			<content type="html"><![CDATA[<p>I might come up with more questions in this category, but for now ...<br />If I have a loop that runs a million times, and within that loop I am converting 5 and 6 digit long numbers (sometimes shorter, sometimes a bit longer) from one base to another, is it faster to keep the math conversion statements in the main code or to create a function that does the calculations (with the number as a parameter) and passes back the answer?</p><p>I don&#039;t know what the compiler does with that. By calling the function, I&#039;m adding overhead. But making the functional &quot;tool&quot; makes the program more tidy.&nbsp; If we are talking about and execution difference in seconds or a minute for the whole loop to process the function call, I can live with that and a &quot;cleaner&quot; program. But if it adds 10 minutes, I&#039;d leave the code in the main area.</p>]]></content>
			<author>
				<name><![CDATA[designer]]></name>
				<uri>https://forums.approximatrix.com/profile.php?id=3903</uri>
			</author>
			<updated>2025-12-01T00:47:28Z</updated>
			<id>https://forums.approximatrix.com/viewtopic.php?pid=4512#p4512</id>
		</entry>
</feed>
