From 6140be6a5575e9159e3678adf4ee9e673b3ff2cc Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Sun, 4 Dec 2016 18:36:18 +0100 Subject: [PATCH] openmp: Fix build with clang++ and compilers without OpenMP support Builds without support for OpenMP failed with the old code. Fix this: * Add OPENMP_CXXFLAGS for ccmain. * Replace unconditional -fopenmp by OPENMP_CXXFLAGS for lstm. * Always use _OPENMP for conditional compilation. * Remove OPENMP as there is already _OPENMP. * Include omp.h conditionally. Signed-off-by: Stefan Weil --- api/Makefile.am | 3 --- ccmain/Makefile.am | 1 + ccmain/par_control.cpp | 6 ++++-- configure.ac | 7 ------- lstm/Makefile.am | 2 +- lstm/lstm.cpp | 2 +- lstm/parallel.cpp | 2 ++ 7 files changed, 9 insertions(+), 14 deletions(-) diff --git a/api/Makefile.am b/api/Makefile.am index 140279b5..225e37dd 100644 --- a/api/Makefile.am +++ b/api/Makefile.am @@ -88,9 +88,7 @@ tesseract_LDADD = libtesseract.la tesseract_LDFLAGS = $(OPENCL_LDFLAGS) -if OPENMP tesseract_LDADD += $(OPENMP_CFLAGS) -endif if T_WIN tesseract_LDADD += -lws2_32 @@ -99,4 +97,3 @@ endif if ADD_RT tesseract_LDADD += -lrt endif - diff --git a/ccmain/Makefile.am b/ccmain/Makefile.am index 38edb2fd..885d4ecb 100644 --- a/ccmain/Makefile.am +++ b/ccmain/Makefile.am @@ -8,6 +8,7 @@ AM_CPPFLAGS += \ -I$(top_srcdir)/textord -I$(top_srcdir)/opencl AM_CPPFLAGS += $(OPENCL_CPPFLAGS) +AM_CPPFLAGS += $(OPENMP_CXXFLAGS) if VISIBILITY AM_CPPFLAGS += -DTESS_EXPORTS \ diff --git a/ccmain/par_control.cpp b/ccmain/par_control.cpp index 7a7d0415..82cd55c9 100644 --- a/ccmain/par_control.cpp +++ b/ccmain/par_control.cpp @@ -18,9 +18,9 @@ /////////////////////////////////////////////////////////////////////// #include "tesseractclass.h" -#ifdef OPENMP +#ifdef _OPENMP #include -#endif // OPENMP +#endif // _OPENMP namespace tesseract { @@ -53,7 +53,9 @@ void Tesseract::PrerecAllWordsPar(const GenericVector& words) { } // Pre-classify all the blobs. if (tessedit_parallelize > 1) { +#ifdef _OPENMP #pragma omp parallel for num_threads(10) +#endif // _OPENMP for (int b = 0; b < blobs.size(); ++b) { *blobs[b].choices = blobs[b].tesseract->classify_blob(blobs[b].blob, "par", White, NULL); diff --git a/configure.ac b/configure.ac index cba2c127..9e6fe5c3 100644 --- a/configure.ac +++ b/configure.ac @@ -171,14 +171,7 @@ if test "$enable_embedded" = "yes"; then fi # check whether to build OpenMP support -AM_CONDITIONAL([OPENMP], false) AC_OPENMP -AS_IF([test "x$OPENMP_CFLAGS" != "x"], - [AM_CONDITIONAL([OPENMP], true) - AM_CPPFLAGS="$OPENMP_CXXFLAGS $AM_CPPFLAGS" - AC_DEFINE([OPENMP], [], [Defined when compiled with OpenMP support])] -) - # check whether to build opencl version AC_MSG_CHECKING([--enable-opencl argument]) diff --git a/lstm/Makefile.am b/lstm/Makefile.am index fddd6230..81e7a7b6 100644 --- a/lstm/Makefile.am +++ b/lstm/Makefile.am @@ -4,7 +4,7 @@ AM_CPPFLAGS += \ -I$(top_srcdir)/dict -I$(top_srcdir)/lstm AUTOMAKE_OPTIONS = subdir-objects SUBDIRS = -AM_CXXFLAGS = -fopenmp +AM_CXXFLAGS = $(OPENMP_CXXFLAGS) if !NO_TESSDATA_PREFIX AM_CXXFLAGS += -DTESSDATA_PREFIX=@datadir@/ diff --git a/lstm/lstm.cpp b/lstm/lstm.cpp index 80c4d8cf..9fe16cf8 100644 --- a/lstm/lstm.cpp +++ b/lstm/lstm.cpp @@ -18,7 +18,7 @@ #include "lstm.h" -#ifndef ANDROID_BUILD +#ifdef _OPENMP #include #endif #include diff --git a/lstm/parallel.cpp b/lstm/parallel.cpp index 2c4d5fb6..c60778bf 100644 --- a/lstm/parallel.cpp +++ b/lstm/parallel.cpp @@ -18,7 +18,9 @@ #include "parallel.h" +#ifdef _OPENMP #include +#endif #include "functions.h" // For conditional undef of _OPENMP. #include "networkscratch.h"