Performance issues on Windows


#42

I am using the v2.4.4 final release from git.
I also cloned the latest version of the CImg repository from framagit and attempted to compile the examples with MSVC 2017 and 2010.

The default command quoted below compiles on both versions of MSVC.
cl /W4 /wd"4127" /wd"4311" /wd"4312" /wd"4512" /wd"4571" /wd"4640" /wd"4706" /wd"4710" /wd"4800" /wd"4804" /wd"4820" /wd"4996" /Ox /Ob2 /Oi /Ot /c /EHsc /D "_CRT_SECURE_NO_WARNINGS" /I"\Include" /I"..\\" CImg_demo.cpp

But if that command is changed to build CImg with OpenMP.
cl /openmp /Dcimg_use_openmp /W4 /wd"4127" /wd"4311" /wd"4312" /wd"4512" /wd"4571" /wd"4640" /wd"4706" /wd"4710" /wd"4800" /wd"4804" /wd"4820" /wd"4996" /Ox /Ob2 /Oi /Ot /c /EHsc /D "_CRT_SECURE_NO_WARNINGS" /I"\Include" /I"..\\" CImg_demo.cpp

Both MSVC versions fail with errors due to the fact that CImg is using OpenMP 3.0 and MSVC only supports OpenMP 2.0.
C3005: 'collapse': unexpected token encountered on OpenMP 'parallel for' directive

As mentioned in the posts above, even after fixing that error in the header you still have the issue that OpenMP 2.0 does not support for loops using pointer indexers.

I do not expect you to change CImg to support OpenMP 2.0, the fact MSVC does not support OpenMP 3 and later when GCC and many other compilers do is something that Microsoft needs to fix.

I am building the Release version that is stripped during linking, I also checked to make sure that Qt and the other binaries were stripped.
The difference in size between the Gimp and Paint.NET downloads is due to the fact that the Paint.NET plugin download has to include libpng, zlib and all of the other Qt dependencies that are already present as part of the standard Gimp installation.

For some reason Qt and its dependencies are smaller when built by Visual C++ using VCPkg.


(G'MIC staff) #43

I guess that is because you need to define the macro cimg_OS=2 to avoid CImg.h trying to parallelize loops that use pointers. I’ve done changes recently to ensure it compiles on Windows with OpenMP 2.0, instead of OpenMP 3.0.
I can ensure I’ve compiled G’MIC on MSVC with /openmp enabled, after I did the changes.

Same here. We provide all the required .dll with the installed and .zip package, as the GIMP plug-in is installed in its own directory, and we want to avoid dll conflicts. Qt is not used in GIMP, so we provide it as well (and it’s quite big as you say). Anyway, we still have an installer around 25-30 Mb.


#44

You must be using a more tolerant version of MSVC than 2017. :slightly_smiling_face:

Even after setting the cimg_OS=2 define, MSVC throws a number of errors when it finds more OpenMP 3 directives.

Any parallel for collapse directives (such as line #13121) trigger an error.
I managed to fix those with by replacing it with the following define on MSVC.
#define cimg_openmp_for_collapse(x) parallel for

The remaining errors I encountered were due to a few ‘for’ loops that use unsigned integer indexers (such as lines 29702 and 34068).
After commenting out the OpenMP statements on all of those lines it finally was able to compile.


(G'MIC staff) #45

That’s interesting, thanks for the details.
I’ll then also remove the collapse() directive for Windows, when using MSVC.

It’s a bit a pity MSVC doesn’t support collapse(), as it is a part of the OpenMP 2.0 standard.


(G'MIC staff) #46

I’ve just tested once again, with Visual Studio 2012, to be sure I didn’t forget anything.
I’m using these compilation flags:

/GS /W4 /wd"4127" /wd"4244" /wd"4311" /wd"4312" /wd"4512" /wd"4571" /wd"4640" /wd"4706" /wd"4710" /wd"4800" /wd"4804" /wd"4820" /wd"4996" /Zc:wchar_t /Zi /Gm /Od /Ob0 /Fd"x64\Debug\vc110.pdb" /fp:precise /D "gmic_build" /D "gmic_main" /D "gmic_is_parallel" /D "cimg_display=2" /D "_CRT_SECURE_NO_WARNINGS" /D "_MBCS" /errorReport:prompt /WX- /Zc:forScope /RTC1 /Gd /MDd /openmp /Fa"x64\Debug\" /EHsc /nologo /Fo"x64\Debug\" /Fp"x64\Debug\gmic.pch" 

Everything seems to compile fine:

What I don’t understand is actually this page : https://stackoverflow.com/questions/10174329/omp-for-with-collapse-clause-is-not-compiling
says that collapse() is an OpenMP 3.0 directive (not 2.0 as I thought).

So if MSVC is inly supporting OpenMP 2.0, why did I succeed in compiling G’MIC with the latest CImg code ?


(G'MIC staff) #47

OK, so I’ve followed your suggestions, and did some changes in files CImg.h and gmic.cpp to only use OpenMP 2.0 directives when compiled with MSVC.
@PDN_GMIC, could you check my changes and tell me that everything is OK with the current version from the git ? Thanks!


#48

It looks like your command line may be missing the /D "cimg_use_openmp".

It compiles after fixing one more ‘for’ loop that was using an unsigned int (line 47289).

With that fix it looks like you will be able to close issue 7.


(G'MIC staff) #49

Ah that’s it, thanks , silly me !
I’ve been able to make the changes this morning. Along with the recent optimizations on the patch matching algorithm done with @heckflosse, that seems to be a good reason for an official update to new version 2.4.5 :slight_smile: