Note that there are some explanatory texts on larger screens.

plurals
  1. POOpenMP is not doing actual parallelism when using GCC
    primarykey
    data
    text
    <p>I am running Ubuntu 12 on Virtual box and I am using GCC to compile this simple C program that has simple OpenMp pragmas :</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;omp.h&gt; #define MAX 10000000000 void main() { unsigned long long i,j,k,l; int threadnumber; #pragma omp parallel shared(i,j,k,l) { threadnumber = omp_get_thread_num(); if(threadnumber == 0) { for(i = 0; i &lt; (MAX / 4); i++) ; } else if(threadnumber == 1) { for(j = (MAX / 4); j &lt; (MAX / 2); j++) ; } else if(threadnumber == 2) { for(k = (MAX / 2); k &lt; (3 * (MAX / 4));k++) ; } else { for(l = (3 * (MAX / 4)); l &lt; MAX; l++) ; } } } </code></pre> <p>My Processor is an Intel Core i5 one. The program is indeed working in parallel (verified through adding some printf()s) , I have set the environment variable(OMP_NUM_THREADS) to 4. The problem is that code is taking much time than this one which is not parallel :</p> <pre><code>#include &lt;stdio.h&gt; #define MAX 10000000000 void main() { unsigned long long i; for(i = 0; i &lt; MAX; i++) ; } </code></pre> <p>I have also tried to add <code>clock()</code> calls before and after the loop in both versions and I am getting a higher time in the parallel version. I have also tried to measure the time using : time <code>./a.out</code> and I am getting (in the parallel version only) different "real" time than what is returned by <code>clock()</code> !</p> <p>I have compiled both codes on visual studio and here are the results : </p> <ol> <li>In Debug mode : both codes are given nearly equal times and that time is near to what is given by GCC.</li> <li>In Release mode : Both codes are faster and the parallel one shows a great improvement in time. The Problem in a nutshell :</li> <li>I want to run the program in parallel with that same efficiency as in the release version of visual studio's compiler. 2) Is there a parameter or option that I should pass to GCC other than the <code>"-fopenmp"</code> to make it build a release version exactly like visual studio. 3) I want to know if it is an Ubuntu thing problem or a GCC one or WHAT ???</li> </ol> <p>P.S : I have tried running the same procedure on an Ubuntu with wubi installation and on an Ubuntu as a standalone OS (on an ext4 File System) and on the same platform and I am getting the same results.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload