Coverage Report

Created: 2024-02-28 06:46

/src/tesseract/src/ccmain/par_control.cpp
Line
Count
Source (jump to first uncovered line)
1
///////////////////////////////////////////////////////////////////////
2
// File:        par_control.cpp
3
// Description: Control code for parallel implementation.
4
// Author:      Ray Smith
5
//
6
// (C) Copyright 2013, Google Inc.
7
// Licensed under the Apache License, Version 2.0 (the "License");
8
// you may not use this file except in compliance with the License.
9
// You may obtain a copy of the License at
10
// http://www.apache.org/licenses/LICENSE-2.0
11
// Unless required by applicable law or agreed to in writing, software
12
// distributed under the License is distributed on an "AS IS" BASIS,
13
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
// See the License for the specific language governing permissions and
15
// limitations under the License.
16
//
17
///////////////////////////////////////////////////////////////////////
18
19
#include "tesseractclass.h"
20
#ifdef _OPENMP
21
#  include <omp.h>
22
#endif // _OPENMP
23
24
namespace tesseract {
25
26
struct BlobData {
27
  BlobData() = default;
28
  BlobData(int index, Tesseract *tess, const WERD_RES &word)
29
      : blob(word.chopped_word->blobs[index])
30
      , tesseract(tess)
31
0
      , choices(&(*word.ratings)(index, index)) {}
32
33
  TBLOB *blob = nullptr;
34
  Tesseract *tesseract = nullptr;
35
  BLOB_CHOICE_LIST **choices = nullptr;
36
};
37
38
0
void Tesseract::PrerecAllWordsPar(const std::vector<WordData> &words) {
39
  // Prepare all the blobs.
40
0
  std::vector<BlobData> blobs;
41
0
  for (const auto &w : words) {
42
0
    if (w.word->ratings != nullptr && w.word->ratings->get(0, 0) == nullptr) {
43
0
      for (size_t s = 0; s < w.lang_words.size(); ++s) {
44
0
        Tesseract *sub = s < sub_langs_.size() ? sub_langs_[s] : this;
45
0
        const WERD_RES &word = *w.lang_words[s];
46
0
        for (unsigned b = 0; b < word.chopped_word->NumBlobs(); ++b) {
47
0
          blobs.emplace_back(b, sub, word);
48
0
        }
49
0
      }
50
0
    }
51
0
  }
52
  // Pre-classify all the blobs.
53
0
  if (tessedit_parallelize > 1) {
54
#ifdef _OPENMP
55
#  pragma omp parallel for num_threads(10)
56
#endif // _OPENMP
57
    // NOLINTNEXTLINE(modernize-loop-convert)
58
0
    for (size_t b = 0; b < blobs.size(); ++b) {
59
0
      *blobs[b].choices =
60
0
          blobs[b].tesseract->classify_blob(blobs[b].blob, "par", ScrollView::WHITE, nullptr);
61
0
    }
62
0
  } else {
63
    // TODO(AMD) parallelize this.
64
0
    for (auto &blob : blobs) {
65
0
      *blob.choices = blob.tesseract->classify_blob(blob.blob, "par", ScrollView::WHITE, nullptr);
66
0
    }
67
0
  }
68
0
}
69
70
} // namespace tesseract.