Skip to content

Commit 6140be6

Browse files
committed
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 <[email protected]>
1 parent c1ec06c commit 6140be6

File tree

7 files changed

+9
-14
lines changed

7 files changed

+9
-14
lines changed

api/Makefile.am

-3
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,7 @@ tesseract_LDADD = libtesseract.la
8888

8989
tesseract_LDFLAGS = $(OPENCL_LDFLAGS)
9090

91-
if OPENMP
9291
tesseract_LDADD += $(OPENMP_CFLAGS)
93-
endif
9492

9593
if T_WIN
9694
tesseract_LDADD += -lws2_32
@@ -99,4 +97,3 @@ endif
9997
if ADD_RT
10098
tesseract_LDADD += -lrt
10199
endif
102-

ccmain/Makefile.am

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ AM_CPPFLAGS += \
88
-I$(top_srcdir)/textord -I$(top_srcdir)/opencl
99

1010
AM_CPPFLAGS += $(OPENCL_CPPFLAGS)
11+
AM_CPPFLAGS += $(OPENMP_CXXFLAGS)
1112

1213
if VISIBILITY
1314
AM_CPPFLAGS += -DTESS_EXPORTS \

ccmain/par_control.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
///////////////////////////////////////////////////////////////////////
1919

2020
#include "tesseractclass.h"
21-
#ifdef OPENMP
21+
#ifdef _OPENMP
2222
#include <omp.h>
23-
#endif // OPENMP
23+
#endif // _OPENMP
2424

2525
namespace tesseract {
2626

@@ -53,7 +53,9 @@ void Tesseract::PrerecAllWordsPar(const GenericVector<WordData>& words) {
5353
}
5454
// Pre-classify all the blobs.
5555
if (tessedit_parallelize > 1) {
56+
#ifdef _OPENMP
5657
#pragma omp parallel for num_threads(10)
58+
#endif // _OPENMP
5759
for (int b = 0; b < blobs.size(); ++b) {
5860
*blobs[b].choices =
5961
blobs[b].tesseract->classify_blob(blobs[b].blob, "par", White, NULL);

configure.ac

-7
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,7 @@ if test "$enable_embedded" = "yes"; then
171171
fi
172172
173173
# check whether to build OpenMP support
174-
AM_CONDITIONAL([OPENMP], false)
175174
AC_OPENMP
176-
AS_IF([test "x$OPENMP_CFLAGS" != "x"],
177-
[AM_CONDITIONAL([OPENMP], true)
178-
AM_CPPFLAGS="$OPENMP_CXXFLAGS $AM_CPPFLAGS"
179-
AC_DEFINE([OPENMP], [], [Defined when compiled with OpenMP support])]
180-
)
181-
182175
183176
# check whether to build opencl version
184177
AC_MSG_CHECKING([--enable-opencl argument])

lstm/Makefile.am

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ AM_CPPFLAGS += \
44
-I$(top_srcdir)/dict -I$(top_srcdir)/lstm
55
AUTOMAKE_OPTIONS = subdir-objects
66
SUBDIRS =
7-
AM_CXXFLAGS = -fopenmp
7+
AM_CXXFLAGS = $(OPENMP_CXXFLAGS)
88

99
if !NO_TESSDATA_PREFIX
1010
AM_CXXFLAGS += -DTESSDATA_PREFIX=@datadir@/

lstm/lstm.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
#include "lstm.h"
2020

21-
#ifndef ANDROID_BUILD
21+
#ifdef _OPENMP
2222
#include <omp.h>
2323
#endif
2424
#include <stdio.h>

lstm/parallel.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818

1919
#include "parallel.h"
2020

21+
#ifdef _OPENMP
2122
#include <omp.h>
23+
#endif
2224

2325
#include "functions.h" // For conditional undef of _OPENMP.
2426
#include "networkscratch.h"

0 commit comments

Comments
 (0)