<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Parallelisierung mit OpenMP funktioniert nicht]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich möchte folgenden Codeabschnitt parallelisieren. Hab auch schon die, nach meinem Verständnis notwendigen, OpenMp-Anweisungen eingebaut. Aber leider funktioniert es so nicht (ist langsamer als ohne omp und das Endergebnis von sum ist auch nicht korrekt.</p>
<pre><code class="language-cpp">...
#pragma omp parallel shared(matrix, sobelX, sobelY, sum)
{
	#pragma omp for reduction(+: sum)
	for (int y = 1; y &lt; (SIZE - 1); y++) {
		for (int x = 1; x &lt; (SIZE - 1); x++) {
			int *pMatrix;
			int tmpX = 0;
			int tmpY = 0;
			int *pKernelx = sobelX;
			int *pKernely = sobelY;
			for (int ky = -1; ky &lt;= 1; ky++) {
				pMatrix = matrix + (y + ky) * SIZE + x - 1;
				for (int kx = -1; kx &lt;= 1; kx++) {
					tmpX += *pMatrix * *pKernelx++;
					tmpY += *pMatrix++ * *pKernely++;
				}
			}
			sum += sqrt(tmpX * tmpX + tmpY * tmpY);
		}
	}
}
...
</code></pre>
<p>Ich hoffe mir kann jemand einen Hinweis geben, wo der Fehler liegt.</p>
<p>Vielen Dank schonmal.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/241136/parallelisierung-mit-openmp-funktioniert-nicht</link><generator>RSS for Node</generator><lastBuildDate>Mon, 21 Sep 2026 17:31:47 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/241136.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 16 May 2009 11:16:14 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Parallelisierung mit OpenMP funktioniert nicht on Sat, 16 May 2009 11:16:14 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich möchte folgenden Codeabschnitt parallelisieren. Hab auch schon die, nach meinem Verständnis notwendigen, OpenMp-Anweisungen eingebaut. Aber leider funktioniert es so nicht (ist langsamer als ohne omp und das Endergebnis von sum ist auch nicht korrekt.</p>
<pre><code class="language-cpp">...
#pragma omp parallel shared(matrix, sobelX, sobelY, sum)
{
	#pragma omp for reduction(+: sum)
	for (int y = 1; y &lt; (SIZE - 1); y++) {
		for (int x = 1; x &lt; (SIZE - 1); x++) {
			int *pMatrix;
			int tmpX = 0;
			int tmpY = 0;
			int *pKernelx = sobelX;
			int *pKernely = sobelY;
			for (int ky = -1; ky &lt;= 1; ky++) {
				pMatrix = matrix + (y + ky) * SIZE + x - 1;
				for (int kx = -1; kx &lt;= 1; kx++) {
					tmpX += *pMatrix * *pKernelx++;
					tmpY += *pMatrix++ * *pKernely++;
				}
			}
			sum += sqrt(tmpX * tmpX + tmpY * tmpY);
		}
	}
}
...
</code></pre>
<p>Ich hoffe mir kann jemand einen Hinweis geben, wo der Fehler liegt.</p>
<p>Vielen Dank schonmal.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1711377</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1711377</guid><dc:creator><![CDATA[openmpNeuling]]></dc:creator><pubDate>Sat, 16 May 2009 11:16:14 GMT</pubDate></item><item><title><![CDATA[Reply to Parallelisierung mit OpenMP funktioniert nicht on Sun, 17 May 2009 08:56:25 GMT]]></title><description><![CDATA[<p>Hat denn niemand eine Idee?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1711673</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1711673</guid><dc:creator><![CDATA[openmpNeuling]]></dc:creator><pubDate>Sun, 17 May 2009 08:56:25 GMT</pubDate></item><item><title><![CDATA[Reply to Parallelisierung mit OpenMP funktioniert nicht on Sun, 17 May 2009 12:23:18 GMT]]></title><description><![CDATA[<p>Was mir auffällt... sum ist shared und gleichzeitig das Argument für reduction. Sowas ist böse! Falls das nicht hilft: Wie hast Du kompiliert und wie hast Du das aufgerufen (gesetzte Umgebungsvariablen etc., falls manuell gesetzt)?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1711730</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1711730</guid><dc:creator><![CDATA[Walli]]></dc:creator><pubDate>Sun, 17 May 2009 12:23:18 GMT</pubDate></item><item><title><![CDATA[Reply to Parallelisierung mit OpenMP funktioniert nicht on Sun, 17 May 2009 15:02:23 GMT]]></title><description><![CDATA[<p>Danke für den Hinweis mit sum. Hab es gleich mal ausprobiert, ändert aber leider nichts.<br />
Kompiliert habe ich so:<br />
g++ -O3 -Wall -fopenmp -o maxgrad maxgrad.c</p>
<p>Ich habe es auch ohne Optimierung probiert, dadurch wirds aber auch nicht besser.<br />
Umgebungsvariablen habe ich keine gesetzt. Ich weiß aber nicht, was Du meinst mit, wie ich es aufgerufen habe.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1711812</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1711812</guid><dc:creator><![CDATA[openmpNeuling]]></dc:creator><pubDate>Sun, 17 May 2009 15:02:23 GMT</pubDate></item></channel></rss>