Page 1 of 1

OpenMP, studio.h, direct.h

Posted: 2017-09-02T04:02:44-07:00
by snibgo
Tested with IM 6.9.3-7 on Windows 8.1, with Cygwin.

To get parallel processing with OpenMP in programs that use ImageMagick, the program needs to contain ...

Code: Select all

#include "studio.h"
... because that contains includes for omp.h and pthread.h. However, I'm on Windows, building with Cygwin, and building with studio.h fails, "can't find direct.h". studio.h contains:

Code: Select all

#if defined(MAGICKCORE_WINDOWS_SUPPORT)
# include <direct.h>
# include <io.h>
# if !defined(MAGICKCORE_HAVE_STRERROR)
#  define HAVE_STRERROR
# endif
#endif
I have direct.h, but it's in a mingw directory, and contains stuff I don't need for a build.

My workaround is to copy-paste the bits I do need from studio.h into my program, which is just this:

Code: Select all

#if defined(_OPENMP) && ((_OPENMP >= 200203) || defined(__OPENCC__))
#  include <omp.h>
#  define MAGICKCORE_OPENMP_SUPPORT  1
#endif

#if defined(MAGICKCORE_THREAD_SUPPORT)
# include <pthread.h>
//#elif defined(MAGICKCORE_WINDOWS_SUPPORT)
//#include <winsock2.h>
//#include <ws2tcpip.h>
//#include <windows.h>
//#pragma comment (lib, "ws2_32.lib")
#endif
(I've commented-out lines that I don't need, though they are harmless.)

This works, and my program has OpenMP. But it seems to be a kludge. Perhaps IM can be smarter in distinguishing between Mingw and Cygwin.

Re: OpenMP, studio.h, direct.h

Posted: 2017-09-02T06:24:51-07:00
by magick
The studio.h header file is a private header file for the exclusive use of the ImageMagick API's and utilities. We do not recommend its use for anything other than the ImageMagick API's and utilities. For programs that call the ImageMagick libraries we provide the MagickCore.h, MagickWand.h, and Magick++.h public header files. If you require OpenMP in your programs, we recommend including the OpenMP header files directly in your source module instead of using studio.h.

We verified custom development works as designed with OpenMP enabled with ImageMagick 7.0.6-10 and https://www.imagemagick.org/source/core.c under the latest Cygwin x86_64 on a Windows 10 host. It built and ran without complaint. We did not try OpenMP directly in core.c but we can think of no reason why it would not work as advertised.

Re: OpenMP, studio.h, direct.h

Posted: 2017-09-02T07:47:16-07:00
by snibgo
Okay, thanks.