This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/49575] New: OpenMP has a problem with -funroll-loops


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49575

           Summary: OpenMP has a problem with -funroll-loops
           Product: gcc
           Version: 4.5.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: sailorweb2@hotmail.com


-funroll-loops optimisation option does not work on OpenMP in some cases.
Attached an example. Compiled with options

g++ -g -O2 -funroll-loops -fomit-frame-pointer -march=native -fopenmp

On a 4-core single Intel CPU machine with Kubuntu 11.04, the following program
compiled with OpenMP is around 20 times slower than the program compiled
without OpenMP, because -funroll-loops option does not work on the OpenMP
version. Defining k variable as constant or moving its declaration to inside
the for loop can solve the problem, but they should not be necessary. I think
-funroll-loops should work on the following program as it is.


#include <math.h>
#include <iostream>

using namespace std;

int main ()
{
  long double i=0;
  long double k=0.7;

  #pragma omp parallel for firstprivate(k) reduction(+:i)
  for(int t=1; t<300000000; t++){       
    for(int n=1; n<16; n++){
      i=i+pow(k,n);
    }
  }

  cout << i<<"\t";
  return 0;
}

Initial discussion on this topic was at
http://stackoverflow.com/questions/6506987/why-openmp-version-is-slower


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]