Class: CassiopeeMt::CrawlerMt

Inherits:
Crawler
  • Object
show all
Defined in:
lib/cassiopee-mt.rb

Overview

Multi threaded search using a Crawler per thread Filtering is used to split the input data according to maxthread Matches of each thread are merge to matches of CrawlerMT

Constant Summary collapse

MINSEQSIZE =
10

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCrawlerMt

Returns a new instance of CrawlerMt.


23
24
25
26
27
# File 'lib/cassiopee-mt.rb', line 23

def initialize
	super
	@th = []
	@matches = Array.new
end

Instance Attribute Details

#maxthreadObject

Max number fo threads to use


19
20
21
# File 'lib/cassiopee-mt.rb', line 19

def maxthread
  @maxthread
end

Instance Method Details

#searchApproximate(s, edit) ⇒ Object


75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/cassiopee-mt.rb', line 75

def searchApproximate(s,edit)
     len = @sequence.length
     if(@min_position>0)
       min = @min_position
      else
       min = 0 
     end
      if(@max_position>0)
        max = @max_position
      else
        max = @sequence.length
     end
     len = max - min
     if(len<MINSEQSIZE)
           @maxthread=1
     end
     nb = len.div(maxthread)
     (1..maxthread).each do |i|
       crawler = Crawler.new
       setParams(crawler,i)
       curmax = min + nb
       if(i==maxthread)
          curmax = max
       end
       crawler.filter_position(min,curmax)
       $log.debug("Start new Thread between " << min.to_s << " and " << curmax.to_s)
       @th[i-1] = Thread.new{ Thread.current["matches"] = crawler.searchApproximate(s,edit) }
       min = curmax + 1
     end
     @th.each {|t| t.join; t["matches"].each { |m| @matches << m }}
     return @matches
end

#searchExact(pattern) ⇒ Object


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/cassiopee-mt.rb', line 42

def searchExact(pattern)
     len = @sequence.length
     if(@min_position>0)
       min = @min_position
      else
       min = 0  
     end
      if(@max_position>0)
        max = @max_position
      else
        max= @sequence.length
     end
     len = max - min 
     if(len<MINSEQSIZE)
           @maxthread=1
     end
     nb = len.div(maxthread)
     (1..maxthread).each do |i|
crawler = Crawler.new
setParams(crawler,i)
curmax = min + nb
if(i==maxthread)
	curmax = max
end
crawler.filter_position(min,curmax)
$log.debug("Start new Thread between " << min.to_s << " and " << curmax.to_s)
@th[i-1] = Thread.new{ Thread.current["matches"] = crawler.searchExact(pattern) }
min = curmax + 1
     end
     @th.each {|t| t.join; t["matches"].each { |m| @matches << m }}
     return @matches
end

#setParams(crawler, threadId) ⇒ Object


30
31
32
33
34
35
36
37
38
39
40
# File 'lib/cassiopee-mt.rb', line 30

def setParams(crawler,threadId)
  crawler.setLogLevel($log.level)
  crawler.file_suffix = @file_suffix
  crawler.loadIndex()
	  crawler.method = @method
  crawler.comments = @comments
  crawler.useAmbiguity = @useAmbiguity
  crawler.ambiguous = @ambiguous
  crawler.useCache = @useCache
  #crawler.file_suffix = @file_suffix+"."+threadId.to_s
end