| 325 | } |
| 326 | |
| 327 | void SingleEndProcessor::readerTask() |
| 328 | { |
| 329 | if(mOptions->verbose) |
| 330 | loginfo("start to load data"); |
| 331 | long lastReported = 0; |
| 332 | int slept = 0; |
| 333 | long readNum = 0; |
| 334 | bool splitSizeReEvaluated = false; |
| 335 | Read** data = new Read*[PACK_SIZE]; |
| 336 | memset(data, 0, sizeof(Read*)*PACK_SIZE); |
| 337 | int cpus = std::thread::hardware_concurrency(); |
| 338 | int bgzfBudget = std::max(1, ((int)cpus - mOptions->thread - 3) / 1); // -workers -reader -writer |
| 339 | FastqReader reader(mOptions->in1, true, mOptions->phred64, bgzfBudget); |
| 340 | reader.setReadPool(mReadPool); |
| 341 | int count=0; |
| 342 | bool needToBreak = false; |
| 343 | while(true){ |
| 344 | Read* read = reader.read(); |
| 345 | if(!read || needToBreak){ |
| 346 | // the last pack |
| 347 | ReadPack* pack = new ReadPack; |
| 348 | pack->data = data; |
| 349 | pack->count = count; |
| 350 | mInputLists[mPackReadCounter % mOptions->thread]->produce(pack); |
| 351 | mPackReadCounter++; |
| 352 | mBackpressureCV.notify_all(); |
| 353 | data = NULL; |
| 354 | if(read) { |
| 355 | delete read; |
| 356 | read = NULL; |
| 357 | } |
| 358 | break; |
| 359 | } |
| 360 | data[count] = read; |
| 361 | count++; |
| 362 | // configured to process only first N reads |
| 363 | if(mOptions->readsToProcess >0 && count + readNum >= mOptions->readsToProcess) { |
| 364 | needToBreak = true; |
| 365 | } |
| 366 | if(mOptions->verbose && count + readNum >= lastReported + 1000000) { |
| 367 | lastReported = count + readNum; |
| 368 | string msg = "loaded " + to_string((lastReported/1000000)) + "M reads"; |
| 369 | loginfo(msg); |
| 370 | } |
| 371 | // a full pack |
| 372 | if(count == PACK_SIZE || needToBreak){ |
| 373 | ReadPack* pack = new ReadPack; |
| 374 | pack->data = data; |
| 375 | pack->count = count; |
| 376 | mInputLists[mPackReadCounter % mOptions->thread]->produce(pack); |
| 377 | mPackReadCounter++; |
| 378 | mBackpressureCV.notify_all(); |
| 379 | //re-initialize data for next pack |
| 380 | data = new Read*[PACK_SIZE]; |
| 381 | memset(data, 0, sizeof(Read*)*PACK_SIZE); |
| 382 | // if the processor is far behind this reader, sleep and wait to limit memory usage |
| 383 | { |
| 384 | std::unique_lock<std::mutex> lk(mBackpressureMtx); |
nothing calls this directly
no test coverage detected