B
B
benderspb2012-04-23 02:04:42
C++ / C#
benderspb, 2012-04-23 02:04:42

No performance benefit from autoparallelizing gcc code (floop-parallelize-all ftree-parallelize-loops=4)?

I am studying the possibility of auto-parallelization of C code. The program is filling the array. When I use the calculated value of an array element, I see a performance gain. When I use rand_r() to fill an array with random numbers, there is no gain, but the program is still executed in several threads. How to get a performance benefit using random array filling?
Normal compilation:
gcc -O2 -o seq code.c
Parallel:
gcc -O2 -floop-parallelize-all -ftree-parallelize-loops=4 -o auto code.c
Code

#include &lt;stdio.h&gt;<br/>
#include &lt;stdlib.h&gt;<br/>
#include &lt;time.h&gt;<br/>
<br/>
int main(int argc, char* argv[])<br/>
{<br/>
<br/>
int N = atoi(argv[1]);<br/>
<br/>
struct timeval t0, t1;<br/>
 <br/>
 int e,i,j,k,l; <br/>
<br/>
double* M1;<br/>
<br/>
M1 = calloc(N * N, sizeof(double));<br/>
 <br/>
 unsigned int seed = 1;<br/>
<br/>
gettimeofday(&t0, NULL);<br/>
<br/>
for(i = 0; i &lt; N*N; i++)<br/>
M1[i] = rand_r(&seed);<br/>
//M1[i] = i*i*i / 3.12514565;<br/>
<br/>
gettimeofday(&t1, NULL);<br/>
 double elapsed = ( (t1.tv_sec-t0.tv_sec)*1000000 + t1.tv_usec-t0.tv_usec )/1000000.0;<br/>
 printf(&quot;%.3f;&quot;, elapsed); <br/>
<br/>
free(M1);<br/>
<br/>
return 0;<br/>
}<br/>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question