<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>
	Comments on: Explicit multi-threading in Matlab part 4	</title>
	<atom:link href="https://undocumentedmatlab.com/articles/explicit-multi-threading-in-matlab-part4/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com/articles/explicit-multi-threading-in-matlab-part4?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=explicit-multi-threading-in-matlab-part4</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Sat, 21 Oct 2017 16:45:44 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.3</generator>
	<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/explicit-multi-threading-in-matlab-part4#comment-415306</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Sat, 21 Oct 2017 16:45:44 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4688#comment-415306</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/explicit-multi-threading-in-matlab-part4#comment-415200&quot;&gt;sharavan&lt;/a&gt;.

@Sharavan - yes, as long as you place the code in a &lt;a href=&quot;https://www.mathworks.com/help/simulink/matlab-s-functions-1.html&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Matlab s-function&lt;/a&gt;. The syntax should be the same as that shown on this blog.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/explicit-multi-threading-in-matlab-part4#comment-415200">sharavan</a>.</p>
<p>@Sharavan &#8211; yes, as long as you place the code in a <a href="https://www.mathworks.com/help/simulink/matlab-s-functions-1.html" target="_blank" rel="nofollow">Matlab s-function</a>. The syntax should be the same as that shown on this blog.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: sharavan		</title>
		<link>https://undocumentedmatlab.com/articles/explicit-multi-threading-in-matlab-part4#comment-415200</link>

		<dc:creator><![CDATA[sharavan]]></dc:creator>
		<pubDate>Thu, 19 Oct 2017 14:58:34 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4688#comment-415200</guid>

					<description><![CDATA[Hello Yair,
               Thanks for the brilliant article. Will I be able to call Java extensions from S Functions from Simulink. A very small example would help a lot.

Best Regards
Sharavan]]></description>
			<content:encoded><![CDATA[<p>Hello Yair,<br />
               Thanks for the brilliant article. Will I be able to call Java extensions from S Functions from Simulink. A very small example would help a lot.</p>
<p>Best Regards<br />
Sharavan</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Matlab: Asynchronous Program Flow &#124; Notes		</title>
		<link>https://undocumentedmatlab.com/articles/explicit-multi-threading-in-matlab-part4#comment-382889</link>

		<dc:creator><![CDATA[Matlab: Asynchronous Program Flow &#124; Notes]]></dc:creator>
		<pubDate>Wed, 13 Jul 2016 10:52:31 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4688#comment-382889</guid>

					<description><![CDATA[[&#8230;] Yair Altman posted a trick on Undocumented Matlab. He uses a timer to call another function asynchronously. [&#8230;]]]></description>
			<content:encoded><![CDATA[<p>[&#8230;] Yair Altman posted a trick on Undocumented Matlab. He uses a timer to call another function asynchronously. [&#8230;]</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Knut A Meyer		</title>
		<link>https://undocumentedmatlab.com/articles/explicit-multi-threading-in-matlab-part4#comment-381715</link>

		<dc:creator><![CDATA[Knut A Meyer]]></dc:creator>
		<pubDate>Wed, 29 Jun 2016 14:41:05 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4688#comment-381715</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/explicit-multi-threading-in-matlab-part4#comment-381617&quot;&gt;Knut A Meyer&lt;/a&gt;.

Thanks for the quick reply Yair! 
I didn&#039;t get how you identify the process ID of the called process though...? Perhaps something very easy I&#039;m missing?
But, I found a solution in the spirit of your last code example, which seems to be working:
&lt;pre lang=&quot;matlab&quot;&gt;
function [out, tlimexceeded] = runscript(script, settings)
out = 0;
tlimexceeded = 0;
runtime = java.lang.Runtime.getRuntime();
process = runtime.exec(script);
process_start = tic;

while(1) %Check for completion
    pause(settings.CompletionCheckInterval)
    try
        out = process.exitValue(); %Throws IllegalThreadStateException if process not completed
        break;
    catch
        %Process still running
    end %try-catch
    
    if (toc(process_start) &gt; settings.TimeLimit)
        process.destroy();
        fprintf(&#039;Time limit exceeded\n&#039;);
        tlimexceeded = 1;
        out = 0;
    end
end %while
&lt;/pre&gt;]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/explicit-multi-threading-in-matlab-part4#comment-381617">Knut A Meyer</a>.</p>
<p>Thanks for the quick reply Yair!<br />
I didn&#8217;t get how you identify the process ID of the called process though&#8230;? Perhaps something very easy I&#8217;m missing?<br />
But, I found a solution in the spirit of your last code example, which seems to be working:</p>
<pre lang="matlab">
function [out, tlimexceeded] = runscript(script, settings)
out = 0;
tlimexceeded = 0;
runtime = java.lang.Runtime.getRuntime();
process = runtime.exec(script);
process_start = tic;

while(1) %Check for completion
    pause(settings.CompletionCheckInterval)
    try
        out = process.exitValue(); %Throws IllegalThreadStateException if process not completed
        break;
    catch
        %Process still running
    end %try-catch
    
    if (toc(process_start) > settings.TimeLimit)
        process.destroy();
        fprintf('Time limit exceeded\n');
        tlimexceeded = 1;
        out = 0;
    end
end %while
</pre>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/explicit-multi-threading-in-matlab-part4#comment-381618</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Tue, 28 Jun 2016 17:11:48 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4688#comment-381618</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/explicit-multi-threading-in-matlab-part4#comment-381617&quot;&gt;Knut A Meyer&lt;/a&gt;.

@Knut - you can use the &lt;code&gt;tasklist&lt;/code&gt; command on Windows. For example:

&lt;pre lang=&quot;matlab&quot;&gt;
&gt;&gt; procId = feature(&#039;getPID&#039;);  % Matlab&#039;s own process ID
&gt;&gt; str = evalc(&#039;system([&#039;&#039;tasklist /v /fi &quot;PID eq &#039;&#039; num2str(procId) &#039;&#039;&quot; /FO LIST&#039;&#039;]);&#039;)
str = 
Image Name:   MATLAB.exe 
PID:          15212 
Session Name: Console 
Session#:     1 
Mem Usage:    1,314,408 K 
Status:       Running 
User Name:    Thinkpad-E530\BMPA 
CPU Time:     0:11:52 
Window Title: MATLAB R2016b 
&lt;/pre&gt;

Alternately, you can use &lt;a href=&quot;https://msdn.microsoft.com/en-us/library/76fkb36k(v=vs.110).aspx&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;&lt;code&gt;System.Diagnostics.Process.GetProcessById(procId)&lt;/code&gt;&lt;/a&gt; to determine whether a process is running or not, and if it is then you can also retrieve some process properties from the returned data object:

&lt;pre lang=&quot;matlab&quot;&gt;
try
   procObject = System.Diagnostics.Process.GetProcessById(procId);
   processName = char(procObject.ProcessName);  % procObj can be queried 
   isRunning = true;
catch
   isRunning = false;
end
&lt;/pre&gt;

For Linux/MacOS, see &lt;a target=&quot;_blank&quot; href=&quot;http://undocumentedmatlab.com/about/todo#comment-380556&quot; rel=&quot;nofollow&quot;&gt;here&lt;/a&gt; or simply use the &lt;code&gt;ps&lt;/code&gt; (rather than &lt;code&gt;tasklist&lt;/code&gt;) command with &lt;i&gt;&lt;b&gt;system&lt;/b&gt;&lt;/i&gt;.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/explicit-multi-threading-in-matlab-part4#comment-381617">Knut A Meyer</a>.</p>
<p>@Knut &#8211; you can use the <code>tasklist</code> command on Windows. For example:</p>
<pre lang="matlab">
>> procId = feature('getPID');  % Matlab's own process ID
>> str = evalc('system([''tasklist /v /fi "PID eq '' num2str(procId) ''" /FO LIST'']);')
str = 
Image Name:   MATLAB.exe 
PID:          15212 
Session Name: Console 
Session#:     1 
Mem Usage:    1,314,408 K 
Status:       Running 
User Name:    Thinkpad-E530\BMPA 
CPU Time:     0:11:52 
Window Title: MATLAB R2016b 
</pre>
<p>Alternately, you can use <a href="https://msdn.microsoft.com/en-us/library/76fkb36k(v=vs.110).aspx" target="_blank" rel="nofollow"><code>System.Diagnostics.Process.GetProcessById(procId)</code></a> to determine whether a process is running or not, and if it is then you can also retrieve some process properties from the returned data object:</p>
<pre lang="matlab">
try
   procObject = System.Diagnostics.Process.GetProcessById(procId);
   processName = char(procObject.ProcessName);  % procObj can be queried 
   isRunning = true;
catch
   isRunning = false;
end
</pre>
<p>For Linux/MacOS, see <a target="_blank" href="http://undocumentedmatlab.com/about/todo#comment-380556" rel="nofollow">here</a> or simply use the <code>ps</code> (rather than <code>tasklist</code>) command with <i><b>system</b></i>.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Knut A Meyer		</title>
		<link>https://undocumentedmatlab.com/articles/explicit-multi-threading-in-matlab-part4#comment-381617</link>

		<dc:creator><![CDATA[Knut A Meyer]]></dc:creator>
		<pubDate>Tue, 28 Jun 2016 16:51:31 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4688#comment-381617</guid>

					<description><![CDATA[Thanks Yair for this interesting series!
I found the ability of having more control over the external calls appealing. Do you know if there is a command for checking if a process is completed. 
I would like to terminate the process if it takes too much time:

&lt;pre lang=&quot;matlab&quot;&gt;
runtime = java.lang.Runtime.getRuntime();
process = runtime.exec(&#039;runsim.bat&#039;);
process_start = tic;
while(true)
	pause(CompletionCheckInterval)
 	if process.isCompleted()  %I would like a command like this!
  		break;
 	elseif toc(process_start) &gt; TimeLimit
		process.destroy();
		break;
	end %if
end %while
&lt;/pre&gt;]]></description>
			<content:encoded><![CDATA[<p>Thanks Yair for this interesting series!<br />
I found the ability of having more control over the external calls appealing. Do you know if there is a command for checking if a process is completed.<br />
I would like to terminate the process if it takes too much time:</p>
<pre lang="matlab">
runtime = java.lang.Runtime.getRuntime();
process = runtime.exec('runsim.bat');
process_start = tic;
while(true)
	pause(CompletionCheckInterval)
 	if process.isCompleted()  %I would like a command like this!
  		break;
 	elseif toc(process_start) > TimeLimit
		process.destroy();
		break;
	end %if
end %while
</pre>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/explicit-multi-threading-in-matlab-part4#comment-380135</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Sun, 12 Jun 2016 17:41:58 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4688#comment-380135</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/explicit-multi-threading-in-matlab-part4#comment-380014&quot;&gt;MU&lt;/a&gt;.

@MU - I think you should ask MathWorks support about this - perhaps it&#039;s a bug in the Matlab Compiler.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/explicit-multi-threading-in-matlab-part4#comment-380014">MU</a>.</p>
<p>@MU &#8211; I think you should ask MathWorks support about this &#8211; perhaps it&#8217;s a bug in the Matlab Compiler.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: MU		</title>
		<link>https://undocumentedmatlab.com/articles/explicit-multi-threading-in-matlab-part4#comment-380027</link>

		<dc:creator><![CDATA[MU]]></dc:creator>
		<pubDate>Sat, 11 Jun 2016 21:40:51 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4688#comment-380027</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/explicit-multi-threading-in-matlab-part4#comment-380014&quot;&gt;MU&lt;/a&gt;.

Hi Yair,

I was wondering if batch workers (parallel computing toolbox) have their own timers that we can use. Or are these disabled (much in the same way as GUI objects).

Many thanks for your help.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/explicit-multi-threading-in-matlab-part4#comment-380014">MU</a>.</p>
<p>Hi Yair,</p>
<p>I was wondering if batch workers (parallel computing toolbox) have their own timers that we can use. Or are these disabled (much in the same way as GUI objects).</p>
<p>Many thanks for your help.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: MU		</title>
		<link>https://undocumentedmatlab.com/articles/explicit-multi-threading-in-matlab-part4#comment-380014</link>

		<dc:creator><![CDATA[MU]]></dc:creator>
		<pubDate>Sat, 11 Jun 2016 19:40:22 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4688#comment-380014</guid>

					<description><![CDATA[Hi Yair,
Thank you for the brilliant article on multi-threading.
I am having an issue compiling an m-file (Main.m) which uses the batch function (parallel computing toolbox) to start a Matlab worker to asynchronously write to a mapped memory (without blocking the EDT). This works okay in MATLAB 2015aSP1. However when I compile Main.m using the Matlab Application compiler, the resulting executable doesnt launch a new worker as instructed by the batch command (though the home GUI screen does launch).
Is there a special way to compile scripts which use Parallel computing toolbox functions.
Many thanks]]></description>
			<content:encoded><![CDATA[<p>Hi Yair,<br />
Thank you for the brilliant article on multi-threading.<br />
I am having an issue compiling an m-file (Main.m) which uses the batch function (parallel computing toolbox) to start a Matlab worker to asynchronously write to a mapped memory (without blocking the EDT). This works okay in MATLAB 2015aSP1. However when I compile Main.m using the Matlab Application compiler, the resulting executable doesnt launch a new worker as instructed by the batch command (though the home GUI screen does launch).<br />
Is there a special way to compile scripts which use Parallel computing toolbox functions.<br />
Many thanks</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Mark G		</title>
		<link>https://undocumentedmatlab.com/articles/explicit-multi-threading-in-matlab-part4#comment-357208</link>

		<dc:creator><![CDATA[Mark G]]></dc:creator>
		<pubDate>Fri, 18 Sep 2015 18:02:16 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4688#comment-357208</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/explicit-multi-threading-in-matlab-part4#comment-357157&quot;&gt;Mark G&lt;/a&gt;.

@Stefan - Good find on the matlabcentral post.  That will save me from more time pursuing unlikely prospects.  Thanks all.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/explicit-multi-threading-in-matlab-part4#comment-357157">Mark G</a>.</p>
<p>@Stefan &#8211; Good find on the matlabcentral post.  That will save me from more time pursuing unlikely prospects.  Thanks all.</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
