MCPcopy Create free account
hub / github.com/antmachineintelligence/mtgbmcode / ArgMaxMT

Method ArgMaxMT

include/LightGBM/utils/array_args.h:22–51  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20class ArrayArgs {
21 public:
22 inline static size_t ArgMaxMT(const std::vector<VAL_T>& array) {
23 int num_threads = 1;
24#pragma omp parallel
25#pragma omp master
26 {
27 num_threads = omp_get_num_threads();
28 }
29 int step = std::max(1, (static_cast<int>(array.size()) + num_threads - 1) / num_threads);
30 std::vector<size_t> arg_maxs(num_threads, 0);
31 #pragma omp parallel for schedule(static, 1)
32 for (int i = 0; i < num_threads; ++i) {
33 size_t start = step * i;
34 if (start >= array.size()) { continue; }
35 size_t end = std::min(array.size(), start + step);
36 size_t arg_max = start;
37 for (size_t j = start + 1; j < end; ++j) {
38 if (array[j] > array[arg_max]) {
39 arg_max = j;
40 }
41 }
42 arg_maxs[i] = arg_max;
43 }
44 size_t ret = arg_maxs[0];
45 for (int i = 1; i < num_threads; ++i) {
46 if (array[arg_maxs[i]] > array[ret]) {
47 ret = arg_maxs[i];
48 }
49 }
50 return ret;
51 }
52 inline static size_t ArgMax(const std::vector<VAL_T>& array) {
53 if (array.empty()) {
54 return 0;

Callers

nothing calls this directly

Calls 2

omp_get_num_threadsFunction · 0.70
sizeMethod · 0.45

Tested by

no test coverage detected