<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Approximatrix Forums — Newunit problem(?)]]></title>
		<link>https://forums.approximatrix.com/viewtopic.php?id=900</link>
		<atom:link href="https://forums.approximatrix.com/extern.php?action=feed&amp;tid=900&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Newunit problem(?).]]></description>
		<lastBuildDate>Mon, 26 Jun 2023 14:46:24 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Newunit problem(?)]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=4129#p4129</link>
			<description><![CDATA[<p>Thanks for looking into it.&nbsp; Figures that it would be a Windows problem.&nbsp; </p><p>I&#039;ve got my work around (which is just a straightforward old way of opening files) for now. But will take your advice under consideration for future.</p><p>Linda</p>]]></description>
			<author><![CDATA[null@example.com (lklawrie)]]></author>
			<pubDate>Mon, 26 Jun 2023 14:46:24 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=4129#p4129</guid>
		</item>
		<item>
			<title><![CDATA[Re: Newunit problem(?)]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=4127#p4127</link>
			<description><![CDATA[<p>Linda,</p><p>I&#039;ve looked into the issue, and I think the error isn&#039;t as simple as I originally thought.&nbsp; There is no situation in the runtime library where the library would a) run out of unit numbers less than 2**32 possibilities or thereabouts or b) produce the error message you&#039;ve reported.&nbsp; It looks like the actual error is being generated by the operating system.&nbsp; </p><p>We had another user reporting an issue privately where rapid file open/close operations would intermittently fail.&nbsp; I believe this behavior was because, after a file is closed, Windows doesn&#039;t necessarily immediately release a handle to the file.&nbsp; It might take a fraction of a second.&nbsp; In your case, I think something very similar is occurring.&nbsp; When you close a file, Windows is taking its time (a fraction of a second) to release the handle.&nbsp; When you&#039;re opening a large number of files quickly, you could end up hitting the max file limit even though you&#039;re closing them.</p><p>There are two &quot;not great&quot; solutions.&nbsp; First, you could sleep in your program every so often to allow Windows to take care of some bookkeeping.&nbsp; I don&#039;t particularly love this solution, but it should work.&nbsp; </p><p>Second, you could increase the Windows runtime library&#039;s allowed number of open files.&nbsp; There is a low-level call, <a href="https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/setmaxstdio?view=msvc-160">_setmaxstdio</a>, that can increase the number of files allowed to be open by a process, and I think you&#039;re hitting that limit.&nbsp; In Fortran you would need to wrap it:</p><div class="codebox"><pre><code>interface
    function setmaxstdio(x) bind(c, name=&quot;_setmaxstdio&quot;)
    use iso_c_binding, only: c_int
    integer(kind=c_int), value::x ! The limit to set, probably want it to be 1024 or higher
    integer(kind=c_int)::setmaxstdio ! Returns the new setting
    end function setmaxstdio
end interace</code></pre></div><p>Stream I/O, which I think the Fortran runtime is using, limits the open files to 512.&nbsp; If the files aren&#039;t closing in a timely manner, calling the above at the beginning of your program and setting a much higher limit might fix the issue.</p>]]></description>
			<author><![CDATA[null@example.com (jeff)]]></author>
			<pubDate>Mon, 26 Jun 2023 12:38:23 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=4127#p4127</guid>
		</item>
		<item>
			<title><![CDATA[Re: Newunit problem(?)]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=4124#p4124</link>
			<description><![CDATA[<div class="quotebox"><cite>jeff wrote:</cite><blockquote><p>That seems like a surprisingly odd bug.&nbsp; Thank you for reporting it!&nbsp; I&#039;ll have a look at the runtime library to see why it&#039;s failing.</p></blockquote></div><p>I thought so as well -- seems like from a pool of &quot;available unit numbers&quot; it&#039;s not releasing when closed.</p><p>If it helps, the list it failed on had 3253 items in it, it failed on #2398 or #2397 in the list.</p><p>Linda</p>]]></description>
			<author><![CDATA[null@example.com (lklawrie)]]></author>
			<pubDate>Fri, 16 Jun 2023 12:57:05 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=4124#p4124</guid>
		</item>
		<item>
			<title><![CDATA[Re: Newunit problem(?)]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=4123#p4123</link>
			<description><![CDATA[<p>Linda,</p><p>That seems like a surprisingly odd bug.&nbsp; Thank you for reporting it!&nbsp; I&#039;ll have a look at the runtime library to see why it&#039;s failing.</p>]]></description>
			<author><![CDATA[null@example.com (jeff)]]></author>
			<pubDate>Fri, 16 Jun 2023 12:30:47 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=4123#p4123</guid>
		</item>
		<item>
			<title><![CDATA[Newunit problem(?)]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=4122#p4122</link>
			<description><![CDATA[<p>I use the newer method of opening files -- Open(newunit=lfn, etc)</p><p>I have a program where I did this but after a certain number of opening files, I got the fatal error &quot;too many open files&quot; even though I closed out each one after processing them.</p><p>I fixed it by using assignments for the fiiles:<br />file1=20&nbsp; - Open(Unit=file1, etc)</p><p>These are processing fine on even longer lists of files.</p><p>Linda</p>]]></description>
			<author><![CDATA[null@example.com (lklawrie)]]></author>
			<pubDate>Thu, 15 Jun 2023 18:18:07 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=4122#p4122</guid>
		</item>
	</channel>
</rss>
