Debian Codegraph @

meryl/build.C

raw symbols SCIP
1 #cxx . . $ `<file>/meryl/build.C`/include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <strings.h>
5 #include <math.h>
6
7 #include "bio++.H"cxx . . $ `<file>/libbio/bio++.H`/
8 #include "meryl.H"cxx . . $ `<file>/meryl/meryl.H`/
9 #include "libmeryl.H"cxx . . $ `<file>/libmeryl/libmeryl.H`/
10 #include "seqStream.H"cxx . . $ `<file>/libseq/seqStream.H`/
11 #include "merStream.H"cxx . . $ `<file>/libseq/merStream.H`/
12
13 void runThreadedcxx . . $ runThreaded(aab238e627804bcb).(merylArgscxx . . $ merylArgs# *args);
14
15 // You probably want this to be the same as KMER_WORDS, but in rare
16 // cases, it can be less.
17 //
18 #define SORTED_LIST_WIDTHcxx . . $ `meryl/build.C:18:9`! KMER_WORDScxx . . $ `libbio/kmer.H:26:9`!
19
20 // to make the sorted list be wider, we also need to store wide
21 // things in the bitpackedarray buckets. probably easy (do multiple
22 // adds of data, each at most 64 bits) but not braindead.
23
24 #if SORTED_LIST_WIDTHcxx . . $ `meryl/build.C:18:9`! == 1
25
26 class sortedList_tcxx . . $ sortedList_t# {
27 public:
28 uint64cxx . . $ uint64# _wcxx . . $ sortedList_t#_w.;
29 uint32cxx . . $ uint32# _pcxx . . $ sortedList_t#_p.;
30
31 bool operatorcxx . . $ sortedList_t#`operator<`(5e2dce3971cd96ce).<(sortedList_tcxx . . $ sortedList_t# &that) {
32 return(_wcxx . . $ sortedList_t#_w. < that._wcxx . . $ sortedList_t#_w.);
33 };
34
35 bool operatorcxx . . $ sortedList_t#`operator>=`(5e2dce3971cd96ce).>=(sortedList_tcxx . . $ sortedList_t# &that) {
36 return(_wcxx . . $ sortedList_t#_w. >= that._wcxx . . $ sortedList_t#_w.);
37 };
38
39 sortedList_tcxx . . $ sortedList_t# &operatorcxx . . $ sortedList_t#`operator=`(657ad474b633d480).=(sortedList_tcxx . . $ sortedList_t# &that) {
40 _wcxx . . $ sortedList_t#_w. = that._wcxx . . $ sortedList_t#_w.;
41 _pcxx . . $ sortedList_t#_p. = that._pcxx . . $ sortedList_t#_p.;
42 return(*this);
43 };
44 };
45
46 #else
47
48 class sortedList_t {
49 public:
50 uint64 _w[SORTED_LIST_WIDTH];
51 uint32 _p;
52
53 bool operator<(sortedList_t &that) {
54 for (uint32 i=SORTED_LIST_WIDTH; i--; ) {
55 if (_w[i] < that._w[i]) return(true);
56 if (_w[i] > that._w[i]) return(false);
57 }
58 return(false);
59 };
60
61 bool operator>=(sortedList_t &that) {
62 for (uint32 i=SORTED_LIST_WIDTH; i--; ) {
63 if (_w[i] > that._w[i]) return(true);
64 if (_w[i] < that._w[i]) return(false);
65 }
66 return(true);
67 };
68
69 sortedList_t &operator=(sortedList_t &that) {
70 for (uint32 i=SORTED_LIST_WIDTH; i--; )
71 _w[i] = that._w[i];
72 _p = that._p;
73 return(*this);
74 };
75 };
76
77 #endif
78
79
80
81
82 void
83 adjustHeapcxx . . $ adjustHeap(bb6bc42eb96b96f).(sortedList_tcxx . . $ sortedList_t# *M, int64cxx . . $ int64# i, int64cxx . . $ int64# n) {
84 sortedList_tcxx . . $ sortedList_t# m = M[i];
85 int64cxx . . $ int64# j = (i << 1) + 1; // let j be the left child
86
87 while (j < n) {
88 if (j<n-1 && M[j] <cxx . . $ sortedList_t#`operator<`(5e2dce3971cd96ce). M[j+1])
89 j++; // j is the larger child
90
91 if (m >=cxx . . $ sortedList_t#`operator>=`(5e2dce3971cd96ce). M[j]) // a position for M[i] has been found
92 break;
93
94 M[(j-1)/2] =cxx . . $ sortedList_t#`operator=`(657ad474b633d480). M[j]; // Move larger child up a level
95
96 j = (j << 1) + 1;
97 }
98
99 M[(j-1)/2] =cxx . . $ sortedList_t#`operator=`(657ad474b633d480). m;
100 }
101
102
103 void
104 submitPrepareBatchcxx . . $ submitPrepareBatch(aab238e627804bcb).(merylArgscxx . . $ merylArgs# *args) {
105 FILE *F;
106 char nam[1024];
107 char cmd[1024];
108
109 sprintf(nam, "%s-prepare.sh", args->outputFilecxx . . $ merylArgs#outputFile.);
110
111 errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = 0;
112 F = fopen(nam, "w");
113 if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)
114 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Failed to open '%s': %s\n", nam, strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)), exitcxx . . $ exit(44ed87f96534fad7).(1);
115
116 fprintf(F, "#!/bin/sh\n\n");
117 fprintf(F, ". $SGE_ROOT/$SGE_CELL/common/settings.sh\n");
118 fprintf(F, "%s -forcebuild %s\n", args->execNamecxx . . $ merylArgs#execName., args->optionscxx . . $ merylArgs#options.);
119 fclose(F);
120
121 if (args->sgeMergeOptcxx . . $ merylArgs#sgeMergeOpt.)
122 sprintf(cmd, "qsub -cwd -b n -j y -o %s-prepare.err %s -N mp%s %s-prepare.sh",
123 args->outputFilecxx . . $ merylArgs#outputFile., args->sgeMergeOptcxx . . $ merylArgs#sgeMergeOpt., args->sgeJobNamecxx . . $ merylArgs#sgeJobName., args->outputFilecxx . . $ merylArgs#outputFile.);
124 else
125 sprintf(cmd, "qsub -cwd -b n -j y -o %s-prepare.err -N mp%s %s-prepare.sh",
126 args->outputFilecxx . . $ merylArgs#outputFile., args->sgeJobNamecxx . . $ merylArgs#sgeJobName., args->outputFilecxx . . $ merylArgs#outputFile.);
127 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s\n", cmd);
128 if (systemcxx . . $ system(5c4306d8553b3696).(cmd))
129 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s\nFailed to execute qsub command: %s\n", cmd, strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)), exitcxx . . $ exit(44ed87f96534fad7).(1);
130 }
131
132
133 void
134 submitCountBatchescxx . . $ submitCountBatches(aab238e627804bcb).(merylArgscxx . . $ merylArgs# *args) {
135 FILE *F;
136 char nam[1024];
137 char cmd[1024];
138
139 sprintf(nam, "%s-count.sh", args->outputFilecxx . . $ merylArgs#outputFile.);
140
141 errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = 0;
142 F = fopen(nam, "w");
143 if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)
144 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Failed to open '%s': %s\n", nam, strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)), exitcxx . . $ exit(44ed87f96534fad7).(1);
145
146 fprintf(F, "#!/bin/sh\n\n");
147 fprintf(F, ". $SGE_ROOT/$SGE_CELL/common/settings.sh\n");
148 fprintf(F, "batchnum=`expr $SGE_TASK_ID - 1`\n");
149 fprintf(F, "%s -v -countbatch $batchnum -o %s\n", args->execNamecxx . . $ merylArgs#execName., args->outputFilecxx . . $ merylArgs#outputFile.);
150 fclose(F);
151
152 if (args->sgeBuildOptcxx . . $ merylArgs#sgeBuildOpt.)
153 sprintf(cmd, "qsub -t 1-"uint64FMTcxx . . $ `libutil/util.h:55:10`!" -cwd -b n -j y -o %s-count-\\$TASK_ID.err %s -N mc%s %s-count.sh",
154 args->segmentLimitcxx . . $ merylArgs#segmentLimit., args->outputFilecxx . . $ merylArgs#outputFile., args->sgeBuildOptcxx . . $ merylArgs#sgeBuildOpt., args->sgeJobNamecxx . . $ merylArgs#sgeJobName., args->outputFilecxx . . $ merylArgs#outputFile.);
155 else
156 sprintf(cmd, "qsub -t 1-"uint64FMTcxx . . $ `libutil/util.h:55:10`!" -cwd -b n -j y -o %s-count-\\$TASK_ID.err -N mc%s %s-count.sh",
157 args->segmentLimitcxx . . $ merylArgs#segmentLimit., args->outputFilecxx . . $ merylArgs#outputFile., args->sgeJobNamecxx . . $ merylArgs#sgeJobName., args->outputFilecxx . . $ merylArgs#outputFile.);
158 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s\n", cmd);
159 if (systemcxx . . $ system(5c4306d8553b3696).(cmd))
160 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s\nFailed to execute qsub command: %s\n", cmd, strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)), exitcxx . . $ exit(44ed87f96534fad7).(1);
161
162 // submit the merge
163
164 sprintf(nam, "%s-merge.sh", args->outputFilecxx . . $ merylArgs#outputFile.);
165
166 errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = 0;
167 F = fopen(nam, "w");
168 if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)
169 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Failed to open '%s': %s\n", nam, strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)), exitcxx . . $ exit(44ed87f96534fad7).(1);
170
171 fprintf(F, "#!/bin/sh\n\n");
172 fprintf(F, ". $SGE_ROOT/$SGE_CELL/common/settings.sh\n");
173 fprintf(F, "%s -mergebatch -o %s\n", args->execNamecxx . . $ merylArgs#execName., args->outputFilecxx . . $ merylArgs#outputFile.);
174 fclose(F);
175
176 if (args->sgeMergeOptcxx . . $ merylArgs#sgeMergeOpt.)
177 sprintf(cmd, "qsub -hold_jid mc%s -cwd -b n -j y -o %s-merge.err %s -N mm%s %s-merge.sh",
178 args->sgeJobNamecxx . . $ merylArgs#sgeJobName., args->outputFilecxx . . $ merylArgs#outputFile., args->sgeMergeOptcxx . . $ merylArgs#sgeMergeOpt., args->sgeJobNamecxx . . $ merylArgs#sgeJobName., args->outputFilecxx . . $ merylArgs#outputFile.);
179 else
180 sprintf(cmd, "qsub -hold_jid mc%s -cwd -b n -j y -o %s-merge.err -N mm%s %s-merge.sh",
181 args->sgeJobNamecxx . . $ merylArgs#sgeJobName., args->outputFilecxx . . $ merylArgs#outputFile., args->sgeJobNamecxx . . $ merylArgs#sgeJobName., args->outputFilecxx . . $ merylArgs#outputFile.);
182 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s\n", cmd);
183 if (systemcxx . . $ system(5c4306d8553b3696).(cmd))
184 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s\nFailed to execute qsub command: %s\n", cmd, strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)), exitcxx . . $ exit(44ed87f96534fad7).(1);
185 }
186
187
188 void
189 prepareBatchcxx . . $ prepareBatch(aab238e627804bcb).(merylArgscxx . . $ merylArgs# *args) {
190 bool fatalError = false;
191
192 if (args->inputFilecxx . . $ merylArgs#inputFile. == 0L)
193 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "ERROR - no input file specified.\n"), fatalError = true;
194
195 if (args->outputFilecxx . . $ merylArgs#outputFile. == 0L)
196 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "ERROR - no output file specified.\n"), fatalError = true;
197
198 if ((args->doForwardcxx . . $ merylArgs#doForward. == false) &&
199 (args->doReversecxx . . $ merylArgs#doReverse. == false) &&
200 (args->doCanonicalcxx . . $ merylArgs#doCanonical. == false))
201 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "ERROR - need to specify at least one of -f, -r, -C\n"), fatalError = true;
202
203 if ((args->doForwardcxx . . $ merylArgs#doForward. && args->doReversecxx . . $ merylArgs#doReverse.) ||
204 (args->doForwardcxx . . $ merylArgs#doForward. && args->doCanonicalcxx . . $ merylArgs#doCanonical.) ||
205 (args->doReversecxx . . $ merylArgs#doReverse. && args->doCanonicalcxx . . $ merylArgs#doCanonical.))
206 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "ERROR - only one of -f, -r and -C may be specified!\n"), fatalError = true;
207
208 if (args->lowCountcxx . . $ merylArgs#lowCount. > args->highCountcxx . . $ merylArgs#highCount.)
209 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "ERROR - lowCount > highCount??\n"), fatalError = true;
210
211 if (args->segmentLimitcxx . . $ merylArgs#segmentLimit. && args->memoryLimitcxx . . $ merylArgs#memoryLimit.)
212 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "ERROR: Only one of -memory and -segments can be specified.\n"), fatalError=true;
213
214 if (fatalError)
215 exitcxx . . $ exit(44ed87f96534fad7).(1);
216
217 // If we were given no segment or memory limit, but threads, we
218 // really want to create n segments.
219 //
220 if ((args->numThreadscxx . . $ merylArgs#numThreads. > 0) && (args->segmentLimitcxx . . $ merylArgs#segmentLimit. == 0) && (args->memoryLimitcxx . . $ merylArgs#memoryLimit. == 0))
221 args->segmentLimitcxx . . $ merylArgs#segmentLimit. = args->numThreadscxx . . $ merylArgs#numThreads.;
222
223
224 {
225 seqStreamcxx . . $ seqStream# *seqstr = new seqStreamcxx . . $ seqStream#(args->inputFilecxx . . $ merylArgs#inputFile.);
226
227 args->numBasesActualcxx . . $ merylArgs#numBasesActual. = 0;
228 for (uint32cxx . . $ uint32# i=0; i<seqstr->numberOfSequencescxx . . $ seqStream#numberOfSequences(db52760e79bf9054).(); i++)
229 args->numBasesActualcxx . . $ merylArgs#numBasesActual. += seqstr->lengthOfcxx . . $ seqStream#lengthOf(2141b656ce2cc063).(i);
230
231 merStreamcxx . . $ merStream# *merstr = new merStreamcxx . . $ merStream#(new kMerBuildercxx . . $ kMerBuilder#(args->merSizecxx . . $ merylArgs#merSize.), seqstr, true, true);
232
233 args->numMersActualcxx . . $ merylArgs#numMersActual. = merstr->approximateNumberOfMerscxx . . $ merStream#approximateNumberOfMers(f708dce9a8856c70).() + 1;
234
235 delete merstr;
236 }
237
238 #warning not submitting prepareBatch to grid
239 #if 0
240 if ((args->isOnGrid) || (args->sgeJobName == 0L)) {
241 } else {
242
243 // Shucks, we need to build the merstream file. Lets do it
244 // on the grid!
245 //
246 submitPrepareBatch(args);
247 exit(0);
248 }
249 #endif
250
251
252 // If there is a memory limit, figure out how to divide the work into an integer multiple of
253 // numThreads segments.
254 //
255 // Otherwise, if there is a segment limit, split the total number of mers into n pieces.
256 //
257 // Otherwise, we must be doing it all in one fell swoop.
258 //
259 if (args->memoryLimitcxx . . $ merylArgs#memoryLimit.) {
260 args->mersPerBatchcxx . . $ merylArgs#mersPerBatch. = estimateNumMersInMemorySizecxx . . $ estimateNumMersInMemorySize(523f3ef4c24d4155).(args->merSizecxx . . $ merylArgs#merSize., args->memoryLimitcxx . . $ merylArgs#memoryLimit., args->positionsEnabledcxx . . $ merylArgs#positionsEnabled., args->beVerbosecxx . . $ merylArgs#beVerbose.);
261
262 if (args->mersPerBatchcxx . . $ merylArgs#mersPerBatch. > args->numMersActualcxx . . $ merylArgs#numMersActual.)
263 args->mersPerBatchcxx . . $ merylArgs#mersPerBatch. = args->numMersActualcxx . . $ merylArgs#numMersActual.;
264
265 args->mersPerBatchcxx . . $ merylArgs#mersPerBatch. = (uint64cxx . . $ uint64#)ceilcxx . . $ ceil(fee4f1d22bc8e617).((double)args->mersPerBatchcxx . . $ merylArgs#mersPerBatch. / (double)args->numThreadscxx . . $ merylArgs#numThreads.);
266 args->segmentLimitcxx . . $ merylArgs#segmentLimit. = (uint64cxx . . $ uint64#)ceilcxx . . $ ceil(fee4f1d22bc8e617).((double)args->numMersActualcxx . . $ merylArgs#numMersActual. / (double)args->mersPerBatchcxx . . $ merylArgs#mersPerBatch.);
267
268 args->segmentLimitcxx . . $ merylArgs#segmentLimit. = args->numThreadscxx . . $ merylArgs#numThreads. * (uint32cxx . . $ uint32#)ceilcxx . . $ ceil(fee4f1d22bc8e617).((double)args->segmentLimitcxx . . $ merylArgs#segmentLimit. / (double)args->numThreadscxx . . $ merylArgs#numThreads.);
269
270 } else if (args->segmentLimitcxx . . $ merylArgs#segmentLimit.) {
271 args->mersPerBatchcxx . . $ merylArgs#mersPerBatch. = (uint64cxx . . $ uint64#)ceilcxx . . $ ceil(fee4f1d22bc8e617).((double)args->numMersActualcxx . . $ merylArgs#numMersActual. / (double)args->segmentLimitcxx . . $ merylArgs#segmentLimit.);
272
273 } else {
274 args->mersPerBatchcxx . . $ merylArgs#mersPerBatch. = args->numMersActualcxx . . $ merylArgs#numMersActual.;
275 args->segmentLimitcxx . . $ merylArgs#segmentLimit. = 1;
276 }
277
278 args->basesPerBatchcxx . . $ merylArgs#basesPerBatch. = (uint64cxx . . $ uint64#)ceilcxx . . $ ceil(fee4f1d22bc8e617).((double)args->numBasesActualcxx . . $ merylArgs#numBasesActual. / (double)args->segmentLimitcxx . . $ merylArgs#segmentLimit.);
279
280 // Choose the optimal number of buckets to reduce memory usage. Yes, this is already done in
281 // estimateNumMersInMemorySize() (but not saved) and we need to do it for the other cases anyway.
282 //
283 // We use the number of mers per batch + 1 because we need to store the first position after the
284 // last mer. That is, if there are two mers, we will store that the first mer is at position 0,
285 // the second mer is at position 1, and the end of the second mer is at position 2.
286 //
287 args->bucketPointerWidthcxx . . $ merylArgs#bucketPointerWidth. = logBaseTwo64cxx . . $ logBaseTwo64(ecdaa1632f49f591).(args->basesPerBatchcxx . . $ merylArgs#basesPerBatch. + 1);
288 args->numBuckets_log2cxx . . $ merylArgs#numBuckets_log2. = optimalNumberOfBucketscxx . . $ optimalNumberOfBuckets(5f3177df75efc44).(args->merSizecxx . . $ merylArgs#merSize., args->basesPerBatchcxx . . $ merylArgs#basesPerBatch., args->positionsEnabledcxx . . $ merylArgs#positionsEnabled.);
289 args->numBucketscxx . . $ merylArgs#numBuckets. = (uint64ONEcxx . . $ `libutil/util.h:51:10`! << args->numBuckets_log2cxx . . $ merylArgs#numBuckets_log2.);
290 args->merDataWidthcxx . . $ merylArgs#merDataWidth. = args->merSizecxx . . $ merylArgs#merSize. * 2 - args->numBuckets_log2cxx . . $ merylArgs#numBuckets_log2.;
291
292 if (args->merDataWidthcxx . . $ merylArgs#merDataWidth. > SORTED_LIST_WIDTHcxx . . $ `meryl/build.C:18:9`! * 64) {
293 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " numMersActual = "uint64FMTcxx . . $ `libutil/util.h:55:10`!"\n", args->numMersActualcxx . . $ merylArgs#numMersActual.);
294 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " mersPerBatch = "uint64FMTcxx . . $ `libutil/util.h:55:10`!"\n", args->mersPerBatchcxx . . $ merylArgs#mersPerBatch.);
295 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " basesPerBatch = "uint64FMTcxx . . $ `libutil/util.h:55:10`!"\n", args->basesPerBatchcxx . . $ merylArgs#basesPerBatch.);
296 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " numBuckets = "uint64FMTcxx . . $ `libutil/util.h:55:10`!" ("uint32FMTcxx . . $ `libutil/util.h:65:10`!" bits)\n", args->numBucketscxx . . $ merylArgs#numBuckets., args->numBuckets_log2cxx . . $ merylArgs#numBuckets_log2.);
297 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " bucketPointerWidth = "uint32FMTcxx . . $ `libutil/util.h:65:10`!"\n", args->bucketPointerWidthcxx . . $ merylArgs#bucketPointerWidth.);
298 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " merDataWidth = "uint32FMTcxx . . $ `libutil/util.h:65:10`!"\n", args->merDataWidthcxx . . $ merylArgs#merDataWidth.);
299 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Sorry! merSize too big! Increase KMER_WORDS in libbio.kmer.H\n");
300 exitcxx . . $ exit(44ed87f96534fad7).(1);
301 }
302
303 if (args->beVerbosecxx . . $ merylArgs#beVerbose.) {
304 if (args->memoryLimitcxx . . $ merylArgs#memoryLimit.)
305 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Computing "uint64FMTcxx . . $ `libutil/util.h:55:10`!" segments using "uint32FMTcxx . . $ `libutil/util.h:65:10`!" threads and "uint64FMTcxx . . $ `libutil/util.h:55:10`!"MB memory ("uint64FMTcxx . . $ `libutil/util.h:55:10`!"MB if in one batch).\n",
306 args->segmentLimitcxx . . $ merylArgs#segmentLimit., args->numThreadscxx . . $ merylArgs#numThreads.,
307 estimateMemorycxx . . $ estimateMemory(d0900995b195fb9f).(args->merSizecxx . . $ merylArgs#merSize., args->mersPerBatchcxx . . $ merylArgs#mersPerBatch., args->positionsEnabledcxx . . $ merylArgs#positionsEnabled.) * args->numThreadscxx . . $ merylArgs#numThreads.,
308 estimateMemorycxx . . $ estimateMemory(d0900995b195fb9f).(args->merSizecxx . . $ merylArgs#merSize., args->numMersActualcxx . . $ merylArgs#numMersActual., args->positionsEnabledcxx . . $ merylArgs#positionsEnabled.));
309 else
310 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Computing "uint64FMTcxx . . $ `libutil/util.h:55:10`!" segments using "uint32FMTcxx . . $ `libutil/util.h:65:10`!" threads and "uint64FMTcxx . . $ `libutil/util.h:55:10`!"MB memory ("uint64FMTcxx . . $ `libutil/util.h:55:10`!"MB if in one batch).\n",
311 estimateMemorycxx . . $ estimateMemory(d0900995b195fb9f).(args->merSizecxx . . $ merylArgs#merSize., args->mersPerBatchcxx . . $ merylArgs#mersPerBatch., args->positionsEnabledcxx . . $ merylArgs#positionsEnabled.) * args->numThreadscxx . . $ merylArgs#numThreads.,
312 estimateMemorycxx . . $ estimateMemory(d0900995b195fb9f).(args->merSizecxx . . $ merylArgs#merSize., args->numMersActualcxx . . $ merylArgs#numMersActual., args->positionsEnabledcxx . . $ merylArgs#positionsEnabled.));
313
314 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " numMersActual = "uint64FMTcxx . . $ `libutil/util.h:55:10`!"\n", args->numMersActualcxx . . $ merylArgs#numMersActual.);
315 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " mersPerBatch = "uint64FMTcxx . . $ `libutil/util.h:55:10`!"\n", args->mersPerBatchcxx . . $ merylArgs#mersPerBatch.);
316 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " basesPerBatch = "uint64FMTcxx . . $ `libutil/util.h:55:10`!"\n", args->basesPerBatchcxx . . $ merylArgs#basesPerBatch.);
317 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " numBuckets = "uint64FMTcxx . . $ `libutil/util.h:55:10`!" ("uint32FMTcxx . . $ `libutil/util.h:65:10`!" bits)\n", args->numBucketscxx . . $ merylArgs#numBuckets., args->numBuckets_log2cxx . . $ merylArgs#numBuckets_log2.);
318 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " bucketPointerWidth = "uint32FMTcxx . . $ `libutil/util.h:65:10`!"\n", args->bucketPointerWidthcxx . . $ merylArgs#bucketPointerWidth.);
319 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " merDataWidth = "uint32FMTcxx . . $ `libutil/util.h:65:10`!"\n", args->merDataWidthcxx . . $ merylArgs#merDataWidth.);
320 }
321 }
322
323
324
325
326 void
327 runSegmentcxx . . $ runSegment(48ab5ff733a8c644).(merylArgscxx . . $ merylArgs# *args, uint64cxx . . $ uint64# segment) {
328 merStreamcxx . . $ merStream# *M = 0L;
329 merylStreamWritercxx . . $ merylStreamWriter# *W = 0L;
330 speedCountercxx . . $ speedCounter# *C = 0L;
331 uint32cxx . . $ uint32# *bucketSizes = 0L;
332 uint64cxx . . $ uint64# *bucketPointers = 0L;
333 uint64cxx . . $ uint64# *merDataArray[SORTED_LIST_WIDTHcxx . . $ `meryl/build.C:18:9`!] = { 0L };
334 uint32cxx . . $ uint32# *merPosnArray = 0L;
335
336 // If this segment exists already, skip it.
337 //
338 // XXX: This should be a command line option.
339 // XXX: This should check that the files are complete meryl files.
340 //
341 char *filename = new char [strlen(args->outputFilecxx . . $ merylArgs#outputFile.) + 17];
342 sprintf(filename, "%s.batch"uint64FMTcxx . . $ `libutil/util.h:55:10`!".mcdat", args->outputFilecxx . . $ merylArgs#outputFile., segment);
343
344 if (fileExists(filename)) {
345 if (args->beVerbosecxx . . $ merylArgs#beVerbose.)
346 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Found result for batch "uint64FMTcxx . . $ `libutil/util.h:55:10`!" in %s.\n", segment, filename);
347 delete [] filename;
348 return;
349 }
350
351 if ((args->beVerbosecxx . . $ merylArgs#beVerbose.) && (args->segmentLimitcxx . . $ merylArgs#segmentLimit. > 1))
352 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Computing segment "uint64FMTcxx . . $ `libutil/util.h:55:10`!" of "uint64FMTcxx . . $ `libutil/util.h:55:10`!".\n", segment+1, args->segmentLimitcxx . . $ merylArgs#segmentLimit.);
353
354 delete [] filename;
355
356
357
358 //
359 // We can do all allocations up front:
360 // mer data storage (the buckets themselves, plus 64 for slop)
361 // bucket pointers (plus an extra bucket at the end and a little for slop)
362 // bucket size counting space, last because we toss it out quickly
363 //
364 if (args->beVerbosecxx . . $ merylArgs#beVerbose.)
365 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " Allocating "uint64FMTcxx . . $ `libutil/util.h:55:10`!"MB for mer storage ("uint32FMTcxx . . $ `libutil/util.h:65:10`!" bits wide).\n",
366 (args->basesPerBatchcxx . . $ merylArgs#basesPerBatch. * args->merDataWidthcxx . . $ merylArgs#merDataWidth. + 64) >> 23, args->merDataWidthcxx . . $ merylArgs#merDataWidth.);
367
368 // Mer storage - if mers are bigger than 32, we allocate full
369 // words. The last allocation is always a bitPacked array.
370
371 for (uint64cxx . . $ uint64# mword=0, width=args->merDataWidthcxx . . $ merylArgs#merDataWidth.; width > 0; ) {
372 if (width >= 64) {
373 merDataArray[mword] = new uint64cxx . . $ uint64# [ args->basesPerBatchcxx . . $ merylArgs#basesPerBatch. + 1 ];
374 width -= 64;
375 mword++;
376 } else {
377 merDataArray[mword] = new uint64cxx . . $ uint64# [ (args->basesPerBatchcxx . . $ merylArgs#basesPerBatch. * width + 64) >> 6 ];
378 width = 0;
379 }
380 }
381
382 if (args->positionsEnabledcxx . . $ merylArgs#positionsEnabled.) {
383 if (args->beVerbosecxx . . $ merylArgs#beVerbose.)
384 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " Allocating "uint64FMTcxx . . $ `libutil/util.h:55:10`!"MB for mer position storage.\n",
385 (args->basesPerBatchcxx . . $ merylArgs#basesPerBatch. * 32 + 32) >> 23);
386 merPosnArray = new uint32cxx . . $ uint32# [ args->basesPerBatchcxx . . $ merylArgs#basesPerBatch. + 1 ];
387 }
388
389 if (args->beVerbosecxx . . $ merylArgs#beVerbose.)
390 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " Allocating "uint64FMTcxx . . $ `libutil/util.h:55:10`!"MB for bucket pointer table ("uint32FMTcxx . . $ `libutil/util.h:65:10`!" bits wide).\n",
391 (args->numBucketscxx . . $ merylArgs#numBuckets. * args->bucketPointerWidthcxx . . $ merylArgs#bucketPointerWidth. + 128) >> 23, args->bucketPointerWidthcxx . . $ merylArgs#bucketPointerWidth.);
392 bucketPointers = new uint64cxx . . $ uint64# [(args->numBucketscxx . . $ merylArgs#numBuckets. * args->bucketPointerWidthcxx . . $ merylArgs#bucketPointerWidth. + 128) >> 6];
393
394
395 if (args->beVerbosecxx . . $ merylArgs#beVerbose.)
396 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " Allocating "uint64FMTcxx . . $ `libutil/util.h:55:10`!"MB for counting the size of each bucket.\n", args->numBucketscxx . . $ merylArgs#numBuckets. >> 18);
397 bucketSizes = new uint32cxx . . $ uint32# [ args->numBucketscxx . . $ merylArgs#numBuckets. ];
398 for (uint64cxx . . $ uint64# i=args->numBucketscxx . . $ merylArgs#numBuckets.; i--; )
399 bucketSizes[i] = uint32ZEROcxx . . $ `libutil/util.h:60:10`!;
400
401
402 // Position the mer stream at the start of this segments' mers.
403 // The last segment goes until the stream runs out of mers,
404 // everybody else does args->basesPerBatch mers.
405
406 C = new speedCountercxx . . $ speedCounter#(" Counting mers in buckets: %7.2f Mmers -- %5.2f Mmers/second\r", 1000000.0, 0x1fffff, args->beVerbosecxx . . $ merylArgs#beVerbose.);
407 M = new merStreamcxx . . $ merStream#(new kMerBuildercxx . . $ kMerBuilder#(args->merSizecxx . . $ merylArgs#merSize., args->merCompcxx . . $ merylArgs#merComp.),
408 new seqStreamcxx . . $ seqStream#(args->inputFilecxx . . $ merylArgs#inputFile.),
409 true, true);
410 M->setBaseRangecxx . . $ merStream#setBaseRange(6714b5f2551eea49).(args->basesPerBatchcxx . . $ merylArgs#basesPerBatch. * segment, args->basesPerBatchcxx . . $ merylArgs#basesPerBatch. * segment + args->basesPerBatchcxx . . $ merylArgs#basesPerBatch.);
411
412 char mstring[256];
413
414 if (args->doForwardcxx . . $ merylArgs#doForward.) {
415 while (M->nextMercxx . . $ merStream#nextMer(dfa6e707f7696010).()) {
416 //fprintf(stderr, "FMER %s\n", M->theFMer().merToString(mstring));
417 bucketSizes[ args->hashcxx . . $ merylArgs#hash(ca592cb021009579).(M->theFMercxx . . $ merStream#theFMer(52e25c29fea41909).()) ]++;
418 C->tickcxx . . $ speedCounter#tick(c9857a73d68e59ba).();
419 }
420 }
421
422 if (args->doReversecxx . . $ merylArgs#doReverse.) {
423 while (M->nextMercxx . . $ merStream#nextMer(dfa6e707f7696010).()) {
424 //fprintf(stderr, "RMER %s\n", M->theRMer().merToString(mstring));
425 bucketSizes[ args->hashcxx . . $ merylArgs#hash(ca592cb021009579).(M->theRMercxx . . $ merStream#theRMer(52e25c29fea41909).()) ]++;
426 C->tickcxx . . $ speedCounter#tick(c9857a73d68e59ba).();
427 }
428 }
429
430 if (args->doCanonicalcxx . . $ merylArgs#doCanonical.) {
431 while (M->nextMercxx . . $ merStream#nextMer(dfa6e707f7696010).()) {
432 if (M->theFMercxx . . $ merStream#theFMer(52e25c29fea41909).() <=cxx . . $ kMerTiny#`operator<=`(3a2dde3078dcd13f). M->theRMercxx . . $ merStream#theRMer(52e25c29fea41909).()) {
433 //fprintf(stderr, "FMER %s\n", M->theFMer().merToString(mstring));
434 bucketSizes[ args->hashcxx . . $ merylArgs#hash(ca592cb021009579).(M->theFMercxx . . $ merStream#theFMer(52e25c29fea41909).()) ]++;
435 } else {
436 //fprintf(stderr, "RMER %s\n", M->theRMer().merToString(mstring));
437 bucketSizes[ args->hashcxx . . $ merylArgs#hash(ca592cb021009579).(M->theRMercxx . . $ merStream#theRMer(52e25c29fea41909).()) ]++;
438 }
439 C->tickcxx . . $ speedCounter#tick(c9857a73d68e59ba).();
440 }
441 }
442
443 delete C;
444 delete M;
445
446 // Create the hash index using the counts. The hash points
447 // to the end of the bucket; when we add a word, we move the
448 // hash bucket pointer down one.
449 //
450 // When done, we can deallocate the counting table.
451 //
452 if (args->beVerbosecxx . . $ merylArgs#beVerbose.)
453 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " Creating bucket pointers.\n");
454
455 {
456 uint64cxx . . $ uint64# mi=0;
457 uint64cxx . . $ uint64# mj=0;
458 uint64cxx . . $ uint64# mc=0;
459
460 while (mi < args->numBucketscxx . . $ merylArgs#numBuckets.) {
461 mc += bucketSizes[mi++];
462 setDecodedValuecxx . . $ setDecodedValue(27c5c035d40d5a77).(bucketPointers, mj, args->bucketPointerWidthcxx . . $ merylArgs#bucketPointerWidth., mc);
463 mj += args->bucketPointerWidthcxx . . $ merylArgs#bucketPointerWidth.;
464 }
465
466 // Add the location of the end of the table. This is not
467 // modified when adding words, but is used to determine
468 // the size of the last bucket.
469 //
470 setDecodedValuecxx . . $ setDecodedValue(27c5c035d40d5a77).(bucketPointers, mj, args->bucketPointerWidthcxx . . $ merylArgs#bucketPointerWidth., mc);
471 }
472
473
474 // All done with the counting table, get rid of it.
475 //
476 if (args->beVerbosecxx . . $ merylArgs#beVerbose.)
477 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " Releasing "uint64FMTcxx . . $ `libutil/util.h:55:10`!"MB from counting the size of each bucket.\n", args->numBucketscxx . . $ merylArgs#numBuckets. >> 18);
478 delete [] bucketSizes;
479
480
481 C = new speedCountercxx . . $ speedCounter#(" Filling mers into list: %7.2f Mmers -- %5.2f Mmers/second\r", 1000000.0, 0x1fffff, args->beVerbosecxx . . $ merylArgs#beVerbose.);
482 M = new merStreamcxx . . $ merStream#(new kMerBuildercxx . . $ kMerBuilder#(args->merSizecxx . . $ merylArgs#merSize., args->merCompcxx . . $ merylArgs#merComp.),
483 new seqStreamcxx . . $ seqStream#(args->inputFilecxx . . $ merylArgs#inputFile.),
484 true, true);
485 M->setBaseRangecxx . . $ merStream#setBaseRange(6714b5f2551eea49).(args->basesPerBatchcxx . . $ merylArgs#basesPerBatch. * segment, args->basesPerBatchcxx . . $ merylArgs#basesPerBatch. * segment + args->basesPerBatchcxx . . $ merylArgs#basesPerBatch.);
486
487 while (M->nextMercxx . . $ merStream#nextMer(dfa6e707f7696010).()) {
488
489 kMercxx . . $ kMer# const &m = ((args->doReversecxx . . $ merylArgs#doReverse.) || (args->doCanonicalcxx . . $ merylArgs#doCanonical. && (M->theFMercxx . . $ merStream#theFMer(52e25c29fea41909).() >cxx . . $ kMerTiny#`operator>`(3a2dde3078dcd13f). M->theRMercxx . . $ merStream#theRMer(52e25c29fea41909).()))) ?
490 M->theRMercxx . . $ merStream#theRMer(52e25c29fea41909).()
491 :
492 M->theFMercxx . . $ merStream#theFMer(52e25c29fea41909).();
493
494 uint64cxx . . $ uint64# element = preDecrementDecodedValuecxx . . $ preDecrementDecodedValue(468c11c2fa5c07c6).(bucketPointers,
495 args->hashcxx . . $ merylArgs#hash(ca592cb021009579).(m) * args->bucketPointerWidthcxx . . $ merylArgs#bucketPointerWidth.,
496 args->bucketPointerWidthcxx . . $ merylArgs#bucketPointerWidth.);
497
498 #if SORTED_LIST_WIDTHcxx . . $ `meryl/build.C:18:9`! == 1
499 // Even though this would work in the general loop below, we
500 // special case one word mers to avoid the loop overhead.
501 //
502 setDecodedValuecxx . . $ setDecodedValue(27c5c035d40d5a77).(merDataArray[0],
503 element * args->merDataWidthcxx . . $ merylArgs#merDataWidth.,
504 args->merDataWidthcxx . . $ merylArgs#merDataWidth.,
505 m.endOfMercxx . . $ kMerTiny#endOfMer(24d83b250d602a6a).(args->merDataWidthcxx . . $ merylArgs#merDataWidth.));
506 #else
507 for (uint64 mword=0, width=args->merDataWidth; width>0; ) {
508 if (width >= 64) {
509 merDataArray[mword][element] = m.getWord(mword);
510 width -= 64;
511 mword++;
512 } else {
513 setDecodedValue(merDataArray[mword],
514 element * width,
515 width,
516 m.getWord(mword) & uint64MASK(width));
517 width = 0;
518 }
519 }
520 #endif
521
522 if (args->positionsEnabledcxx . . $ merylArgs#positionsEnabled.)
523 merPosnArray[element] = M->thePositionInStreamcxx . . $ merStream#thePositionInStream(f708dce9a8856c70).();
524
525 C->tickcxx . . $ speedCounter#tick(c9857a73d68e59ba).();
526 }
527
528 delete C;
529 delete M;
530
531 char *batchOutputFile = new char [strlen(args->outputFilecxx . . $ merylArgs#outputFile.) + 33];
532 sprintf(batchOutputFile, "%s.batch"uint64FMTcxx . . $ `libutil/util.h:55:10`!, args->outputFilecxx . . $ merylArgs#outputFile., segment);
533
534 C = new speedCountercxx . . $ speedCounter#(" Writing output: %7.2f Mmers -- %5.2f Mmers/second\r", 1000000.0, 0x1fffff, args->beVerbosecxx . . $ merylArgs#beVerbose.);
535 W = new merylStreamWritercxx . . $ merylStreamWriter#((args->segmentLimitcxx . . $ merylArgs#segmentLimit. == 1) ? args->outputFilecxx . . $ merylArgs#outputFile. : batchOutputFile,
536 args->merSizecxx . . $ merylArgs#merSize., args->merCompcxx . . $ merylArgs#merComp.,
537 args->numBuckets_log2cxx . . $ merylArgs#numBuckets_log2.,
538 args->positionsEnabledcxx . . $ merylArgs#positionsEnabled.);
539
540 // Sort each bucket into sortedList, then output the mers
541 //
542 sortedList_tcxx . . $ sortedList_t# *sortedList = 0L;
543 uint32cxx . . $ uint32# sortedListMax = 0;
544 uint32cxx . . $ uint32# sortedListLen = 0;
545
546 for (uint64cxx . . $ uint64# bucket=0, bucketPos=0; bucket < args->numBucketscxx . . $ merylArgs#numBuckets.; bucket++) {
547 uint64cxx . . $ uint64# st = getDecodedValuecxx . . $ getDecodedValue(468c11c2fa5c07c6).(bucketPointers, bucketPos, args->bucketPointerWidthcxx . . $ merylArgs#bucketPointerWidth.);
548 bucketPos += args->bucketPointerWidthcxx . . $ merylArgs#bucketPointerWidth.;
549 uint64cxx . . $ uint64# ed = getDecodedValuecxx . . $ getDecodedValue(468c11c2fa5c07c6).(bucketPointers, bucketPos, args->bucketPointerWidthcxx . . $ merylArgs#bucketPointerWidth.);
550
551 if (ed < st) {
552 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "ERROR: In segment "uint64FMTcxx . . $ `libutil/util.h:55:10`!"\n", segment);
553 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "ERROR: Bucket "uint64FMTcxx . . $ `libutil/util.h:55:10`!" (out of "uint64FMTcxx . . $ `libutil/util.h:55:10`!") ends before it starts!\n",
554 bucket, args->numBucketscxx . . $ merylArgs#numBuckets.);
555 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "ERROR: start="uint64FMTcxx . . $ `libutil/util.h:55:10`!"\n", st);
556 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "ERROR: end ="uint64FMTcxx . . $ `libutil/util.h:55:10`!"\n", ed);
557 }
558 assertcxx . . $ `<external>/4398592474888995393/assert.h:102:11`!(ed >= st);
559
560 if ((ed - st) > (uint64ONEcxx . . $ `libutil/util.h:51:10`! << 30)) {
561 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "ERROR: In segment "uint64FMTcxx . . $ `libutil/util.h:55:10`!"\n", segment);
562 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "ERROR: Bucket "uint64FMTcxx . . $ `libutil/util.h:55:10`!" (out of "uint64FMTcxx . . $ `libutil/util.h:55:10`!") is HUGE!\n",
563 bucket, args->numBucketscxx . . $ merylArgs#numBuckets.);
564 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "ERROR: start="uint64FMTcxx . . $ `libutil/util.h:55:10`!"\n", st);
565 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "ERROR: end ="uint64FMTcxx . . $ `libutil/util.h:55:10`!"\n", ed);
566 }
567
568 // Nothing here? Keep going.
569 if (ed == st)
570 continue;
571
572 sortedListLen = (uint32cxx . . $ uint32#)(ed - st);
573
574 // Allocate more space, if we need to.
575 //
576 if (sortedListLen > sortedListMax) {
577 delete [] sortedList;
578 sortedList = new sortedList_tcxx . . $ sortedList_t# [2 * sortedListLen + 1];
579 sortedListMax = 2 * sortedListLen;
580 }
581
582 // Clear out the sortedList -- if we don't, we leave the high
583 // bits unset which will probably make the sort random.
584 //
585 bzero(sortedList, sizeof(sortedList_tcxx . . $ sortedList_t#) * sortedListLen);
586
587 // Unpack the mers into the sorting array
588 //
589 if (args->positionsEnabledcxx . . $ merylArgs#positionsEnabled.)
590 for (uint64cxx . . $ uint64# i=st; i<ed; i++)
591 sortedList[i-st]._pcxx . . $ sortedList_t#_p. = merPosnArray[i];
592
593 #if SORTED_LIST_WIDTHcxx . . $ `meryl/build.C:18:9`! == 1
594 for (uint64cxx . . $ uint64# i=st, J=st*args->merDataWidthcxx . . $ merylArgs#merDataWidth.; i<ed; i++, J += args->merDataWidthcxx . . $ merylArgs#merDataWidth.)
595 sortedList[i-st]._wcxx . . $ sortedList_t#_w. = getDecodedValuecxx . . $ getDecodedValue(468c11c2fa5c07c6).(merDataArray[0], J, args->merDataWidthcxx . . $ merylArgs#merDataWidth.);
596 #else
597 for (uint64 i=st; i<ed; i++) {
598 for (uint64 mword=0, width=args->merDataWidth; width>0; ) {
599 if (width >= 64) {
600 sortedList[i-st]._w[mword] = merDataArray[mword][i];
601 width -= 64;
602 mword++;
603 } else {
604 sortedList[i-st]._w[mword] = getDecodedValue(merDataArray[mword], i * width, width);
605 width = 0;
606 }
607 }
608 }
609 #endif
610
611 // Sort if there is more than one item
612 //
613 if (sortedListLen > 1) {
614 for (int64cxx . . $ int64# t=(sortedListLen-2)/2; t>=0; t--)
615 adjustHeapcxx . . $ adjustHeap(bb6bc42eb96b96f).(sortedList, t, sortedListLen);
616
617 for (int64cxx . . $ int64# t=sortedListLen-1; t>0; t--) {
618 sortedList_tcxx . . $ sortedList_t# tv = sortedList[t];
619 sortedList[t] =cxx . . $ sortedList_t#`operator=`(657ad474b633d480). sortedList[0];
620 sortedList[0] =cxx . . $ sortedList_t#`operator=`(657ad474b633d480). tv;
621
622 adjustHeapcxx . . $ adjustHeap(bb6bc42eb96b96f).(sortedList, 0, t);
623 }
624 }
625
626 // Dump the list of mers to the file.
627 //
628 kMercxx . . $ kMer# mercxx . . $ kMerTiny#kMerTiny(cb2f890c2fdad230).(args->merSizecxx . . $ merylArgs#merSize.);
629
630 for (uint32cxx . . $ uint32# t=0; t<sortedListLen; t++) {
631 C->tickcxx . . $ speedCounter#tick(c9857a73d68e59ba).();
632
633 // Build the complete mer
634 //
635 #if SORTED_LIST_WIDTHcxx . . $ `meryl/build.C:18:9`! == 1
636 mer.setWordcxx . . $ kMerTiny#setWord(588cb903c6b0e163).(0, sortedList[t]._wcxx . . $ sortedList_t#_w.);
637 #else
638 for (uint64 mword=0; mword < SORTED_LIST_WIDTH; mword++)
639 mer.setWord(mword, sortedList[t]._w[mword]);
640 #endif
641 mer.setBitscxx . . $ kMerTiny#setBits(a30eb5e4a3566ff4).(args->merDataWidthcxx . . $ merylArgs#merDataWidth., args->numBuckets_log2cxx . . $ merylArgs#numBuckets_log2., bucket);
642
643 // Add it
644 if (args->positionsEnabledcxx . . $ merylArgs#positionsEnabled.)
645 W->addMercxx . . $ merylStreamWriter#addMer(5afe88a7d2541197).(mer, 1, &sortedList[t]._pcxx . . $ sortedList_t#_p.);
646 else
647 W->addMercxx . . $ merylStreamWriter#addMer(5afe88a7d2541197).(mer, 1, 0L);
648
649 }
650 }
651
652 delete [] sortedList;
653
654 delete C;
655 delete W;
656
657 delete [] batchOutputFile;
658
659 for (uint32cxx . . $ uint32# x=0; x<SORTED_LIST_WIDTHcxx . . $ `meryl/build.C:18:9`!; x++)
660 delete [] merDataArray[x];
661
662 delete [] merPosnArray;
663
664 delete [] bucketPointers;
665
666 if (args->beVerbosecxx . . $ merylArgs#beVerbose.)
667 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Segment "uint64FMTcxx . . $ `libutil/util.h:55:10`!" finished.\n", segment);
668 }
669
670
671
672 void
673 buildcxx . . $ build(aab238e627804bcb).(merylArgscxx . . $ merylArgs# *args) {
674
675 if (!args->countBatchcxx . . $ merylArgs#countBatch. && !args->mergeBatchcxx . . $ merylArgs#mergeBatch.)
676 prepareBatchcxx . . $ prepareBatch(aab238e627804bcb).(args);
677
678 // Three choices:
679 //
680 // threaded -- start threads, launch pieces in each thread. This
681 // thread waits for completion and then merges the results.
682 //
683 // batched -- write info file and exit. Compute and merge is done
684 // on separate invocations.
685 //
686 // segmented -- write info file, then do each piece sequentially.
687 // After all pieces finished, do a merge.
688 //
689 //
690
691 bool doMerge = false;
692
693 if (args->configBatchcxx . . $ merylArgs#configBatch.) {
694
695 // Write out our configuration and exit if we are -configbatch
696 //
697 args->writeConfigcxx . . $ merylArgs#writeConfig(c9857a73d68e59ba).();
698
699 if (args->sgeJobNamecxx . . $ merylArgs#sgeJobName.) {
700 fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "Batch prepared. Submitting to the grid.\n");
701 submitCountBatchescxx . . $ submitCountBatches(aab238e627804bcb).(args);
702 } else {
703 fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "Batch prepared. Please run:\n");
704 for (uint64cxx . . $ uint64# s=0; s<args->segmentLimitcxx . . $ merylArgs#segmentLimit.; s++)
705 fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "%s -countbatch "uint64FMTcxx . . $ `libutil/util.h:55:10`!" -o %s\n", args->execNamecxx . . $ merylArgs#execName., s, args->outputFilecxx . . $ merylArgs#outputFile.);
706 fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "%s -mergebatch -o %s\n", args->execNamecxx . . $ merylArgs#execName., args->outputFilecxx . . $ merylArgs#outputFile.);
707 }
708 } else if (args->countBatchcxx . . $ merylArgs#countBatch.) {
709
710 // Read back the configuration, run the segment and exit if we
711 // are -countbatch
712 //
713 merylArgscxx . . $ merylArgs# *savedArgs = new merylArgscxx . . $ merylArgs#(args->outputFilecxx . . $ merylArgs#outputFile.);
714 savedArgs->beVerbosecxx . . $ merylArgs#beVerbose. = args->beVerbosecxx . . $ merylArgs#beVerbose.;
715 runSegmentcxx . . $ runSegment(48ab5ff733a8c644).(savedArgs, args->batchNumbercxx . . $ merylArgs#batchNumber.);
716 delete savedArgs;
717 } else if (args->mergeBatchcxx . . $ merylArgs#mergeBatch.) {
718
719 // Check that all the files exist if we are -mergebatch and
720 // continue with execution
721 //
722 // MEMORY LEAK! We should delete this at the end of the
723 // function, but it's a pain, and who cares?
724 //
725 merylArgscxx . . $ merylArgs# *savedArgs = new merylArgscxx . . $ merylArgs#(args->outputFilecxx . . $ merylArgs#outputFile.);
726 savedArgs->beVerbosecxx . . $ merylArgs#beVerbose. = args->beVerbosecxx . . $ merylArgs#beVerbose.;
727
728 args = savedArgs;
729
730 doMerge = true;
731 } else {
732
733 if (args->numThreadscxx . . $ merylArgs#numThreads. > 1)
734
735 // Run, using threads. There is a lot of baloney needed, so it's
736 // all in a separate function.
737 //
738 runThreadedcxx . . $ runThreaded(aab238e627804bcb).(args);
739 else
740 // No special options given, do all the work here and now
741 //
742 for (uint64cxx . . $ uint64# s=0; s<args->segmentLimitcxx . . $ merylArgs#segmentLimit.; s++)
743 runSegmentcxx . . $ runSegment(48ab5ff733a8c644).(args, s);
744
745 // Either case, we want to merge now.
746 //
747 doMerge = true;
748 }
749
750
751 // If there is more than one segment, merge them to get the output.
752 //
753 // We do this by contructing a meryl command line and recursively
754 // (effectively) calling meryl.
755 //
756 // The command line is
757 //
758 // ./meryl -M merge [-v] -s batch1 -s batch2 ... -s batchN -o outputFile
759 //
760 if ((doMerge) && (args->segmentLimitcxx . . $ merylArgs#segmentLimit. > 1)) {
761
762 if (args->beVerbosecxx . . $ merylArgs#beVerbose.)
763 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Merge results.\n");
764
765 int argc = 0;
766 char **argv = new char* [7 + 2 * args->segmentLimitcxx . . $ merylArgs#segmentLimit.];
767 bool *arga = new bool [7 + 2 * args->segmentLimitcxx . . $ merylArgs#segmentLimit.];
768
769 arga[argc] = false; argv[argc++] = "meryl-build-merge";
770 arga[argc] = false; argv[argc++] = "-M";
771 arga[argc] = false; argv[argc++] = "merge";
772
773 if (args->beVerbosecxx . . $ merylArgs#beVerbose.) {
774 arga[argc] = false;
775 argv[argc++] = "-v";
776 }
777
778 for (uint32cxx . . $ uint32# i=0; i<args->segmentLimitcxx . . $ merylArgs#segmentLimit.; i++) {
779 arga[argc] = false;
780 argv[argc++] = "-s";
781 arga[argc] = true;
782 argv[argc] = new char [strlen(args->outputFilecxx . . $ merylArgs#outputFile.) + 33];
783 sprintf(argv[argc], "%s.batch"uint32FMTcxx . . $ `libutil/util.h:65:10`!, args->outputFilecxx . . $ merylArgs#outputFile., i);
784 argc++;
785 }
786
787 arga[argc] = false; argv[argc++] = "-o";
788 arga[argc] = false; argv[argc++] = args->outputFilecxx . . $ merylArgs#outputFile.;
789
790 merylArgscxx . . $ merylArgs# *addArgs = new merylArgscxx . . $ merylArgs#(argc, argv);
791 multipleOperationscxx . . $ multipleOperations(aab238e627804bcb).(addArgs);
792
793 // Cleanup the memory leak.
794 //
795 delete addArgs;
796 for (int i=0; i<argc; i++)
797 if (arga[i])
798 delete [] argv[i];
799 delete [] argv;
800 delete [] arga;
801
802 // Remove temporary files
803 //
804 char *filename = new char [strlen(args->outputFilecxx . . $ merylArgs#outputFile.) + 17];
805
806 for (uint32cxx . . $ uint32# i=0; i<args->segmentLimitcxx . . $ merylArgs#segmentLimit.; i++) {
807 sprintf(filename, "%s.batch"uint32FMTcxx . . $ `libutil/util.h:65:10`!".mcidx", args->outputFilecxx . . $ merylArgs#outputFile., i);
808 unlink(filename);
809 sprintf(filename, "%s.batch"uint32FMTcxx . . $ `libutil/util.h:65:10`!".mcdat", args->outputFilecxx . . $ merylArgs#outputFile., i);
810 unlink(filename);
811 sprintf(filename, "%s.batch"uint32FMTcxx . . $ `libutil/util.h:65:10`!".mcpos", args->outputFilecxx . . $ merylArgs#outputFile., i);
812 unlink(filename);
813 }
814
815 delete [] filename;
816 }
817
818 // If we just merged, delete the merstream file
819 //
820 if (doMerge) {
821 char *filename = new char [strlen(args->outputFilecxx . . $ merylArgs#outputFile.) + 17];
822
823 sprintf(filename, "%s.merStream", args->outputFilecxx . . $ merylArgs#outputFile.);
824 unlink(filename);
825
826 delete [] filename;
827 }
828 }