Sha256: 629d7b51767e40b724202f0407097036766b27cf8b8994b16b35efd8dc2320d3

Contents?: true

Size: 757 Bytes

Versions: 1

Compression:

Stored size: 757 Bytes

Contents

module ParallelHelper
  THREAD_COUNT = (ENV['OMP_NUM_THREADS'] || 2).to_i
  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
  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
  def parallel?
    defined?(Parallel) == 'constant' && @parallel
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
svm_helper-0.2.1 lib/svm_helper/parallel_helper.rb