fastq_to_fasta
A template for creation of SeqAn3 apps, with a FASTQ to FASTA example app.
do_parallel.hpp
Go to the documentation of this file.
1 // --------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2022, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2022, Knut Reinert & MPI für molekulare Genetik
4 // This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
5 // shipped with this file and also available at: https://github.com/seqan/raptor/blob/main/LICENSE.md
6 // --------------------------------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <chrono>
11 #include <future>
12 #include <vector>
13 
14 namespace raptor
15 {
16 
17 template <typename algorithm_t>
18 void do_parallel(algorithm_t && worker, size_t const num_records, size_t const threads, double & compute_time)
19 {
20  auto start = std::chrono::high_resolution_clock::now();
21  std::vector<decltype(std::async(std::launch::async, worker, size_t{}, size_t{}))> tasks;
22  size_t const records_per_thread = num_records / threads;
23 
24  for (size_t i = 0; i < threads; ++i)
25  {
26  size_t const start = records_per_thread * i;
27  size_t const end = i == (threads - 1) ? num_records : records_per_thread * (i + 1);
28  tasks.emplace_back(std::async(std::launch::async, worker, start, end));
29  }
30 
31  for (auto && task : tasks)
32  task.wait();
33 
34  auto end = std::chrono::high_resolution_clock::now();
35  compute_time += std::chrono::duration_cast<std::chrono::duration<double>>(end - start).count();
36 }
37 
38 } // namespace raptor
Definition: adjust_seed.hpp:13
void do_parallel(algorithm_t &&worker, size_t const num_records, size_t const threads, double &compute_time)
Definition: do_parallel.hpp:18