<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Approximatrix Forums — Newunit problem(?)]]></title>
	<link rel="self" href="https://forums.approximatrix.com/extern.php?action=feed&amp;tid=900&amp;type=atom" />
	<updated>2023-06-26T14:46:24Z</updated>
	<generator>PunBB</generator>
	<id>https://forums.approximatrix.com/viewtopic.php?id=900</id>
		<entry>
			<title type="html"><![CDATA[Re: Newunit problem(?)]]></title>
			<link rel="alternate" href="https://forums.approximatrix.com/viewtopic.php?pid=4129#p4129" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[lklawrie]]></name>
				<uri>https://forums.approximatrix.com/profile.php?id=3396</uri>
			</author>
			<updated>2023-06-26T14:46:24Z</updated>
			<id>https://forums.approximatrix.com/viewtopic.php?pid=4129#p4129</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Newunit problem(?)]]></title>
			<link rel="alternate" href="https://forums.approximatrix.com/viewtopic.php?pid=4127#p4127" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[jeff]]></name>
				<uri>https://forums.approximatrix.com/profile.php?id=2</uri>
			</author>
			<updated>2023-06-26T12:38:23Z</updated>
			<id>https://forums.approximatrix.com/viewtopic.php?pid=4127#p4127</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Newunit problem(?)]]></title>
			<link rel="alternate" href="https://forums.approximatrix.com/viewtopic.php?pid=4124#p4124" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[lklawrie]]></name>
				<uri>https://forums.approximatrix.com/profile.php?id=3396</uri>
			</author>
			<updated>2023-06-16T12:57:05Z</updated>
			<id>https://forums.approximatrix.com/viewtopic.php?pid=4124#p4124</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Newunit problem(?)]]></title>
			<link rel="alternate" href="https://forums.approximatrix.com/viewtopic.php?pid=4123#p4123" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[jeff]]></name>
				<uri>https://forums.approximatrix.com/profile.php?id=2</uri>
			</author>
			<updated>2023-06-16T12:30:47Z</updated>
			<id>https://forums.approximatrix.com/viewtopic.php?pid=4123#p4123</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Newunit problem(?)]]></title>
			<link rel="alternate" href="https://forums.approximatrix.com/viewtopic.php?pid=4122#p4122" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[lklawrie]]></name>
				<uri>https://forums.approximatrix.com/profile.php?id=3396</uri>
			</author>
			<updated>2023-06-15T18:18:07Z</updated>
			<id>https://forums.approximatrix.com/viewtopic.php?pid=4122#p4122</id>
		</entry>
</feed>
