<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.2" -->
<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">
	<channel>
		<title>k-Wave User Forum &#187; Topic: time per simulation increases using parfor</title>
		<link>http://www.k-wave.org/forum/topic/time-per-simulation-increases-using-parfor</link>
		<description>Support for the k-Wave MATLAB toolbox</description>
		<language>en-US</language>
		<pubDate>Wed, 13 May 2026 16:24:45 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.2</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://www.k-wave.org/forum/search.php</link>
		</textInput>
		<atom:link href="http://www.k-wave.org/forum/rss/topic/time-per-simulation-increases-using-parfor" rel="self" type="application/rss+xml" />

		<item>
			<title>JRF on "time per simulation increases using parfor"</title>
			<link>http://www.k-wave.org/forum/topic/time-per-simulation-increases-using-parfor#post-6181</link>
			<pubDate>Tue, 31 Oct 2017 19:03:19 +0000</pubDate>
			<dc:creator>JRF</dc:creator>
			<guid isPermaLink="false">6181@http://www.k-wave.org/forum/</guid>
			<description>&#60;p&#62;Hi Brad,&#60;/p&#62;
&#60;p&#62;Thank you for your explanation. I did not realize matlab parallelised the FFT automatically. This makes sense now. &#60;/p&#62;
&#60;p&#62;- Jon
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Bradley Treeby on "time per simulation increases using parfor"</title>
			<link>http://www.k-wave.org/forum/topic/time-per-simulation-increases-using-parfor#post-6175</link>
			<pubDate>Sun, 29 Oct 2017 10:31:16 +0000</pubDate>
			<dc:creator>Bradley Treeby</dc:creator>
			<guid isPermaLink="false">6175@http://www.k-wave.org/forum/</guid>
			<description>&#60;p&#62;Hi Jon,&#60;/p&#62;
&#60;p&#62;This is what I would expect. There are two things to consider. (1) The time-loop consists more-or-less of element-wise operations and FFTs, both of which are already parallelised by MATLAB across multiple cores. (2) For large dimension sizes, the simulations are memory bound, so trying to run multiple simulations at the same time will reduce the available memory bandwidth to each simulation.&#60;/p&#62;
&#60;p&#62;Hope that helps,&#60;/p&#62;
&#60;p&#62;Brad.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>JRF on "time per simulation increases using parfor"</title>
			<link>http://www.k-wave.org/forum/topic/time-per-simulation-increases-using-parfor#post-6171</link>
			<pubDate>Thu, 26 Oct 2017 16:54:05 +0000</pubDate>
			<dc:creator>JRF</dc:creator>
			<guid isPermaLink="false">6171@http://www.k-wave.org/forum/</guid>
			<description>&#60;p&#62;Hello,&#60;/p&#62;
&#60;p&#62;I have been looking into running independent 2D k-wave simulations on multiple cpu's using parfor in matlab (i.e. one simulation per cpu). To test the performance I ran two simulations using a for loop and then ran the exact same simulations again using a parfor loop using a two core pool (code below) on  a 4 core system. When I run simulations using parfor each simulation is ~ 1.7 times slower compared to being run inside a for loop. Therefore the execution time of each loop is nearly the same. I also tested 128x128, 256x256 and 512x512 grids and I saw a factor of 1.7 slow down there too, so I don't think this is due to transferring the grids and data to and from the worker. I have seen the same effect on multiple machines and in HPC environments. I would like to get the simulations to run faster in the parfor loop. Any help or insight on how to do this or if it is possible would be greatly appreciated.&#60;/p&#62;
&#60;p&#62;- Jon&#60;/p&#62;
&#60;p&#62;Code:&#60;/p&#62;
&#60;p&#62;kgrid, medium, source, sensor and input_args are set using the example file &#34;example_pr_2D_TR_circular_sensor.m&#34; in the k-wave toolbox V 1.1.1. the only modification is that PlotSim is set to false.&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;t_start = tic;

for aa= 1:2

    out(aa).sensor_data = kspaceFirstOrder2D(kgrid, medium, source, sensor, input_args{:});

end

t_end_1 = toc(t_start)

t_start = tic;

parfor aa= 1:2

    out(aa).sensor_data = kspaceFirstOrder2D(kgrid, medium, source, sensor, input_args{:});

end

t_end_2 = toc(t_start)&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Results: &#60;/p&#62;
&#60;p&#62;computation time per simulation in for loop =  15.0 seconds&#60;/p&#62;
&#60;p&#62;copmutation time per simulation in parfor loop = 24.6 seconds&#60;/p&#62;
&#60;p&#62;t_end_1 =&#60;/p&#62;
&#60;p&#62;   30.1976&#60;/p&#62;
&#60;p&#62;t_end_2 =&#60;/p&#62;
&#60;p&#62;   24.8956
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
