Raptor
A fast and space-efficient pre-filter
All Classes Namespaces Files Functions Variables Macros Pages Concepts
call_parallel_on_bins.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
2// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
3// SPDX-License-Identifier: BSD-3-Clause
4
10#pragma once
11
12#include <algorithm>
13#include <bit>
14#include <functional>
15#include <omp.h>
16#include <vector>
17
18#include <hibf/contrib/std/chunk_view.hpp>
19#include <hibf/contrib/std/zip_view.hpp>
20#include <hibf/misc/divide_and_ceil.hpp>
21
22namespace raptor
23{
24
25template <typename algorithm_t>
26void call_parallel_on_bins(algorithm_t && worker,
27 std::vector<std::vector<std::string>> const & bin_paths,
28 uint8_t const threads)
29{
30 size_t const number_of_bins = bin_paths.size();
31 // clang-format off
32 size_t const chunk_size = std::clamp<size_t>(
33 std::bit_ceil(seqan::hibf::divide_and_ceil(number_of_bins, threads)),
34 8u,
35 64u);
36 auto chunked_view = seqan::stl::views::zip(bin_paths, std::views::iota(0u, number_of_bins))
37 | seqan::stl::views::chunk(chunk_size);
38 // clang-format on
39 size_t const number_of_chunks = std::ranges::size(chunked_view);
40
41#pragma omp parallel for schedule(dynamic) num_threads(threads)
42 for (size_t i = 0; i < number_of_chunks; ++i)
43 {
44 std::invoke(worker, chunked_view[i]);
45 }
46}
47
48} // namespace raptor
T bit_ceil(T... args)
T invoke(T... args)
T min(T... args)
Hide me