Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8619641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:23:22+00:00 2026-06-12T06:23:22+00:00

I am aware of tasks that offer fine grained control for short running tasks

  • 0

I am aware of tasks that offer fine grained control for short running tasks but I have a situation where it is more natural to use a foreach loop. The question is, is it possible to tell Parallel.For to expect short-running operations and use as many threads as possible to max out the CPU?

If not, then what method would you suggest to parallelize:

bool [,] grid = new bool [1000, 1000];
for (int y=0; y<1000; y++)
    for (int x=0; x<1000; x++)
        // Ignore the bounds error. This is just to illustrate a very short operation.
        grid[x, y] |= grid[x-1, y+1];
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T06:23:23+00:00Added an answer on June 12, 2026 at 6:23 am

    The question is, is it possible to tell Parallel.For to expect short-running operations and use as many threads as possible to max out the CPU?

    Yes, you can do this by making a Partitioner<T> and handling the partitioning yourself. For details, see How to: Speed Up Small Loop Bodies.

    However, in your case, it might be better to just parallelize the outer loop, and leave the inner loop sequential inside of each of the outer Parallel.For loop bodies. This would give each work item enough instructions that it would probably use the processor adequately.

    That being said, this is a situation where .NET will likely not do a great job with Parallel.For – at least not without some extra work. By assiging values to the same array in parallel, you’re going to be introducing false sharing due to the implicit array bounds check, which reads from the same location (just before the start of the array).

    There are various approaches to working around this – one option might be to switch from a multidimensional to a jagged array, for example. With the proper indexing and looping, this can reduce the number of writes to “shared” arrays. Another option would be to use unsafe code and pointers instead of direct array access, as this avoids the bounds checks, but requires very careful coding.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I aware that this will be a less programming question, but still... How can
I would like to sync my db (tasks on my db, that have a
I have a VBScript that does a number of tasks, including moving files from
i'm quite aware that it's not described in the spec, but if i can
I have a solid idea how GCD works, but I want to know more
For quick tasks where I only use an instantiated object once, I am aware
Are aware of any solution that let me deactivate my facebook account through an
I'm aware of using custom configuration values for my custom services, but what if
I'm aware it's a quite simple question but I'm a newbie to C#, ASP.NET
I have a .NET 4 C# service that is using the TPL libraries for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.