OpenMP, studio.h, direct.h

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

OpenMP, studio.h, direct.h

Post 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.
snibgo's IM pages: im.snibgo.com
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: OpenMP, studio.h, direct.h

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: OpenMP, studio.h, direct.h

Post by snibgo »

Okay, thanks.
snibgo's IM pages: im.snibgo.com
Post Reply