Debian Codegraph @

seatac/thr-search.C

raw symbols SCIP
1 #include "seatac.H"
2
3 char const *srchGbye = "[%ld] computed: "uint64FMTW(8)" blocked: "uint64FMTW(4)"/"uint64FMTW(4)" encodeTime: %7.2f searchTime: %7.2f processTime: %7.2f\n";
4
5 class searcherState {
6 public:
7 uint64 posnMax;
8 uint64 posnLen;
9 uint64 *posn;
10
11 double encodeTime;
12 double maskTime;
13 double searchTime;
14 double processTime;
15
16 searcherState() {
17 posnMax = 16384;
18 posnLen = 0;
19 posn = new uint64 [ posnMax ];
20
21 encodeTime = 0.0;
22 maskTime = 0.0;
23 searchTime = 0.0;
24 processTime = 0.0;
25 };
26
27 ~searcherState() {
28 delete [] posn;
29 };
30 };
31
32
33 void
34 doSearch(searcherState *state,
35 seqInCore *seq,
36 uint32 idx,
37 bool rc,
38 filterObj *FO) {
39 encodedQuery *query = 0L;
40 hitMatrix *matrix = 0L;
41 double startTime = 0.0;
42 uint64 mer = uint64ZERO;
43 uint32 pos = uint32ZERO;
44 uint64 count = 0;
45
46 // Build and mask the query
47 //
48 startTime = getTime();
49 query = new encodedQuery(seq->sequence(), seq->sequenceLength(), config._merSize, rc);
50 state->encodeTime += getTime() - startTime;
51
52 // Get the hits
53 //
54 startTime = getTime();
55 matrix = new hitMatrix(seq->sequenceLength(), idx);
56
57 while (query->getMer(mer, pos) == true)
58 if (positions->getExact(mer, state->posn, state->posnMax, state->posnLen, count))
59 matrix->addHits(pos, state->posn, state->posnLen);
60
61 state->searchTime += getTime() - startTime;
62
63 // Begin processing
64 //
65 startTime = getTime();
66 matrix->processMatrix(rc ? 'r' : 'f', FO);
67 state->processTime += getTime() - startTime;
68
69 delete matrix;
70 delete query;
71 }
72
73
74
75 void*
76 searchThread(void *U) {
77 uint32 idx = 0;
78 seqInCore *seq = 0L;
79 uint32 blockedI = 0;
80 uint32 blockedO = 0;
81 uint32 computed = 0;
82
83 searcherState *state = new searcherState;
84
85 // Allocate and fill out the thread stats -- this ensures that we
86 // always have stats (even if they're bogus).
87 //
88 threadStats[(long)U] = new char [1025];
89 sprintf(threadStats[(long)U], srchGbye,
90 (long)U,
91 (uint32)0, (uint32)0, (uint32)0,
92 0.0, 0.0, 0.0);
93
94 while (inputTail < numberOfQueries) {
95
96 // Grab the next sequence.
97 //
98 pthread_mutex_lock(&inputTailMutex);
99 idx = inputTail;
100 if (idx < numberOfQueries) {
101 seq = input[idx];
102 input[idx] = 0L;
103 if (seq)
104 inputTail++;
105 }
106 pthread_mutex_unlock(&inputTailMutex);
107
108 // Still need to check that the index is valid. Another thread
109 // could (and does) steal execution between the while and the
110 // mutex lock.
111 //
112 if (idx < numberOfQueries) {
113
114 // If there is no sequence, oh boy, we are in bad shape. Sleep a
115 // little bit to let the loader catch up, then try again.
116 //
117 if (seq == 0L) {
118 //if (config._loaderWarnings)
119 // fprintf(stderr, "%lu Blocked by input.\n", (uint64)U);
120 blockedI++;
121 nanosleep(&config._searchSleep, 0L);
122 } else {
123
124 // If our idx is too far away from the output thread, sleep
125 // a little bit. We keep the idx and seq that we have obtained,
126 // though.
127 //
128 while (idx > (outputPos + config._writerHighWaterMark)) {
129 if (config._writerWarnings)
130 fprintf(stderr, uint64FMT" Blocked by output (idx = "uint32FMT", outputPos = "uint32FMT").\n", (long)U, idx, outputPos);
131 blockedO++;
132 nanosleep(&config._searchSleep, 0L);
133 }
134
135 // Construct a filter object
136 //
137 filterObj *FO = new filterObj(config._filterObj, config._filteropts);
138
139 // Do searches.
140 //
141 if (config._doForward)
142 doSearch(state, seq, idx, false, FO);
143 if (config._doReverse)
144 doSearch(state, seq, idx, true, FO);
145
146 // Do filtering.
147 //
148 FO->filter();
149
150 // Signal that we are done.
151 //
152 output[idx] = FO;
153 computed++;
154
155 delete seq;
156
157 } // end of seq != 0L
158 } // end of idx < numberOfQueries
159 } // end of inputTail < numberOfQueries
160
161
162 // OK, now fill out the read thread stats
163 //
164 sprintf(threadStats[(long)U], srchGbye, (long)U,
165 computed, blockedI, blockedO,
166 state->encodeTime,
167 state->searchTime,
168 state->processTime);
169
170 delete state;
171
172 return(0L);
173 }