Class: MiGA::Parallel
Overview
Parallel execution in MiGA.
Constant Summary
Constants included from MiGA
CITATION, VERSION, VERSION_DATE, VERSION_NAME
Class Method Summary collapse
-
.distribute(enum, threads, &blk) ⇒ Object
Distributes
enum
acrossthreads
and calls the passed block with args: 1. -
.process(threads) ⇒ Object
Executes the passed block with the thread number as argument (0-numbered) in
threads
processes. -
.thread_enum(enum, threads, thr) ⇒ Object
Enum through
enum
executing the passed block only for thread with indexthr
, one ofthreads
threads.
Methods inherited from MiGA
CITATION, CITATION_ARRAY, DEBUG, DEBUG_OFF, DEBUG_ON, DEBUG_TRACE_OFF, DEBUG_TRACE_ON, FULL_VERSION, LONG_VERSION, VERSION, VERSION_DATE, #advance, debug?, debug_trace?, initialized?, #like_io?, #num_suffix, rc_path, #result_files_exist?, #say
Methods included from Common::Path
Methods included from Common::Format
#clean_fasta_file, #seqs_length, #tabulate
Methods included from Common::Net
#download_file_ftp, #known_hosts, #remote_connection
Methods included from Common::SystemCall
Class Method Details
.distribute(enum, threads, &blk) ⇒ Object
Distributes enum
across threads
and calls the passed block with args:
-
Unitary object from
enum
-
Index of the unitary object
-
Index of the acting thread
22 23 24 |
# File 'lib/miga/parallel.rb', line 22 def distribute(enum, threads, &blk) process(threads) { |thr| thread_enum(enum, threads, thr, &blk) } end |
.process(threads) ⇒ Object
Executes the passed block with the thread number as argument (0-numbered) in threads
processes
10 11 12 13 14 15 |
# File 'lib/miga/parallel.rb', line 10 def process(threads) threads.times do |i| Process.fork { yield(i) } end Process.waitall end |
.thread_enum(enum, threads, thr) ⇒ Object
Enum through enum
executing the passed block only for thread with index thr
, one of threads
threads. The passed block has the same arguments as the one in #distribute
30 31 32 33 34 |
# File 'lib/miga/parallel.rb', line 30 def thread_enum(enum, threads, thr) enum.each_with_index do |obj, idx| yield(obj, idx, thr) if idx % threads == thr end end |