Module: ParallelHelper

Included in:
Preprocessor::Simple, Selector::Simple
Defined in:
lib/svm_helper/parallel_helper.rb

Constant Summary collapse

THREAD_COUNT =
(ENV['OMP_NUM_THREADS'] || 2).to_i

Instance Method Summary collapse

Instance Method Details

#p_map(data, &block) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/svm_helper/parallel_helper.rb', line 12

def p_map data, &block
  if parallel? && RUBY_PLATFORM == 'java'
    Parallel.map(data, in_threads: THREAD_COUNT ){|e| yield e }
  elsif parallel?
    Parallel.map(data, in_processes: THREAD_COUNT ){|e| yield e }
  else
    data.map {|e| yield e }
  end
end

#p_map_with_index(data, &block) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/svm_helper/parallel_helper.rb', line 3

def p_map_with_index data, &block
  if parallel? && RUBY_PLATFORM == 'java'
    Parallel.map_with_index(data, in_threads: THREAD_COUNT ){|e,i| yield e,i }
  elsif parallel?
    Parallel.map_with_index(data, in_processes: THREAD_COUNT ){|e,i| yield e,i }
  else
    data.map.with_index {|e,i| yield e,i }
  end
end

#parallel?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/svm_helper/parallel_helper.rb', line 21

def parallel?
  defined?(Parallel) == 'constant' && @parallel
end