21 #include <system_error>
25 #include <kvikio/defaults.hpp>
26 #include <kvikio/error.hpp>
27 #include <kvikio/utils.hpp>
43 template <
typename F,
typename T>
44 std::future<std::size_t> parallel_io(F op,
47 std::size_t file_offset,
48 std::size_t task_size,
49 std::size_t devPtr_offset)
51 if (task_size == 0) {
throw std::invalid_argument(
"`task_size` cannot be zero"); }
54 if (task_size >= size || page_size >= size) {
59 std::vector<std::future<std::size_t>> tasks;
60 tasks.reserve(size / task_size + 2);
63 while (size >= task_size) {
65 file_offset += task_size;
66 devPtr_offset += task_size;
76 auto gather_tasks = [](std::vector<std::future<std::size_t>>&& tasks) -> std::size_t {
78 for (
auto& task : tasks) {
83 return std::async(std::launch::deferred, gather_tasks, std::move(tasks));
static kvikio::third_party::thread_pool & thread_pool()
Get the default thread pool.
std::future< bool > submit(const F &task, const A &... args)
Submit a function with zero or more arguments and no return value into the task queue,...