Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] How to start tasks approximately in order #1056

Open
Pr0methean opened this issue Jun 18, 2023 · 2 comments
Open

[Question] How to start tasks approximately in order #1056

Pr0methean opened this issue Jun 18, 2023 · 2 comments

Comments

@Pr0methean
Copy link

Pr0methean commented Jun 18, 2023

I have a Vec of tasks that vary widely in duration. To maximize utilization of the whole thread pool, I want the tasks at lower indices in the Vec to start soonest, so that the last long-running task runs in parallel with some short-running tasks rather than becoming a bottleneck at the end. How do I ensure this? Right now I'm using

        let planned_tasks: Vec<CloneableLazyTask<()>>
            = large_tasks.into_iter().chain(small_tasks.into_iter()).collect();
        planned_tasks.into_par_iter().for_each(move |task| {
            let name = task.name.to_owned();
            task.into_result()
                .unwrap_or_else(|err| panic!("Error running task {}: {:?}", name, err));
        });

However, the ordering within large_tasks also matters.

@cuviper
Copy link
Member

cuviper commented Jun 18, 2023

Maybe scope_fifo and its associated spawn_fifo would suit you better? Then you would not need planned_tasks at all, just create a scope and then spawn the tasks directly from their original sources.

@Pr0methean
Copy link
Author

Pr0methean commented Jun 20, 2023

Thanks; I'll test that once tonight's nightly Rust build comes out (I'm blocked by rust-lang/rust#112831).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants