Hello,
I created a Console Project to test Open MP inside QtCreator/MingW32. My Qt version is 5.3. The compiler is mingw482_32.
Here is the project file
Qt Code:
  1. #-------------------------------------------------
  2. #
  3. # Project created by QtCreator 2021-06-18T17:05:54
  4. #
  5. #-------------------------------------------------
  6.  
  7. QT += core
  8.  
  9. QT -= gui
  10.  
  11. TARGET = OpenMPTest
  12. CONFIG += console
  13. CONFIG -= app_bundle
  14.  
  15. TEMPLATE = app
  16.  
  17. win32:CONFIG(release, debug|release):QMAKE_CXXFLAGS += -std=c++11 -O3
  18. QMAKE_CXXFLAGS+= -openmp
  19. QMAKE_LFLAGS += -fopenmp
  20.  
  21. SOURCES += main.cpp \
  22. testOpenMP.cpp
  23.  
  24. HEADERS += \
  25. testOpenMP.h
To copy to clipboard, switch view to plain text mode 

And here is the content of testOpenMP.cpp:
Qt Code:
  1. #include <iostream>
  2. #include <math.h>
  3. #include <time.h>
  4. #include <omp.h>
  5. #define SIZE_ARRAY 20000
  6.  
  7. int array_floor_total[SIZE_ARRAY];
  8.  
  9. void do_compute(int j)
  10. {
  11. double total = 0;
  12. for (int i = 0; i < SIZE_ARRAY; ++i)
  13. total += sqrt(i+j);
  14. int floor_total;
  15. floor_total = floor(total);
  16. array_floor_total[j] = floor_total % 2;// the various threads need to write to common memory
  17. }
  18.  
  19. void test_accellerate_loop()
  20. {
  21. int end = SIZE_ARRAY;
  22. clock_t t1 = clock();
  23.  
  24. for (int i = 0; i < end; ++i)
  25. do_compute(i);
  26. clock_t t2 = clock();
  27. std::cout << "time taken (no acceleration)"<<t2 -t1<<"\n";
  28. clock_t t3 = clock();
  29. #pragma omp parallel for // This OMP directive tells the compiler to parallelise the next loop
  30. for (int i = 0; i < end; ++i)
  31. do_compute(i);
  32. clock_t t4 = clock();
  33. std::cout << "time taken (with acceleration)" << t4 - t3 << "\n";
  34.  
  35. std::cout << "Press return\n";
  36. getchar();// pause
  37. }
To copy to clipboard, switch view to plain text mode 

The main file is essentially a call to test_accellerate_loop();

Now here's the unexpected fact:
Whereas the acceleration is considerable in Debug mode, it's almost non existent in Release mode.
Here is one MignW32 output
time taken (no acceleration)840
time taken (with acceleration)847

I compiled the same testOpenMp.cpp in Visual Studio. There is a big difference. And outside VS the program runs even much faster.
Visual Studio executable, at the command line.
time taken (no acceleration)1076
time taken (with acceleration)203

Any explanation? Do I have the wrong optimiser flags?