Skip to content

Parallel.ForEach should not be used for IO bound tasks. #22232

Closed

Description

@jvanlangen

I think using Parallel.ForEach on things that uses IO, is not a good example. I would restrict it to CPU bound processing.


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Activity

  1. IEvangelist commented on Jan 5, 2021

    @IEvangelist
    Member

    Hi @jvanlangen - I agree, the example should be CPU bound and not IO. I'm updating this to be an "up for grabs", feel free to create a pull request changing this and I'll happily review it. Otherwise, I'll try to get to it. Thanks again

  2. self-assigned this
    on Jan 5, 2021
  3. surenderssm commented on Feb 12, 2021

    @surenderssm
    Contributor

    @IEvangelist - I agree given example is misleading.
    I would love to give it a shot to fix this.
    Let me know your views on the following proposals.
    Objective : Showcase the power of Parallel.ForEach for CPU intensive operations.

    Proposal : We pick up a CPU intensive operation let's say crude way to Findout if given number is prime or not. We start with fix size collection of random integer. In scenario 1 we can iterate over a collection with Foreach and in scenario 2 we iterate with Parallel.Foreach. In the end we display total number of prime numbers and time taken by both the scenarios.

    Do let me know perspective or any other thoughts ?

  4. IEvangelist commented on Feb 12, 2021

    @IEvangelist
    Member

    Hi @surenderssm - I like that idea, and look forward to a PR.

  5. surenderssm commented on Feb 15, 2021

    @surenderssm
    Contributor

    Thanks @IEvangelist - Will share the PR asap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions