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 8832889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:38:39+00:00 2026-06-14T08:38:39+00:00

I need to allocate a workload on different processes, depending on the number of

  • 0

I need to allocate a workload on different processes, depending on the number of logical cores of the user’s PC.
The workload is done by the following code :

static void work()
{
    WorkData myData = new WorkData();
    Worker myWorker = new Worker(myData);
    MyWorker.doWork()
}

I count the logical cores with this code :

int nbProcessors = 1;
foreach (var item in new System.Management.ManagementObjectSearcher("Select *  from Win32_ComputerSystem").Get())
{
    nbProcessors = Convert.ToInt32(item["NumberOfLogicalProcessors"]);
}

Now, I have to do my work() 10000 times, by sharing the work on the logical cores, so in the case of my pc it would mean starting 8 processes with 1250 iterations of work() each.
I also need each process to have its own data, so that I don’t get conflicts.

How can I do that?

  • 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-14T08:38:40+00:00Added an answer on June 14, 2026 at 8:38 am

    I think you should review Parallel methods and ThreadPool methods.
    Both of this classes are counting on current workstation configuration, so you can easily use them for your task.

    Example of Parrallel usage:

    Parallel Loops:

    int n = 10 000;
    Parallel.For(0, n, (i, loopState) =>
    {
      // ... 
      if (/* stopping condition is true */)
      {
        loopState.Break();
        return;   
      }
    });
    

    Thread Pool task-oriented example:

    public void DoWork()
    {
        // Queue a task.
        System.Threading.ThreadPool.QueueUserWorkItem(
            new System.Threading.WaitCallback(SomeLongTask));
        // Queue another task.
        System.Threading.ThreadPool.QueueUserWorkItem(
            new System.Threading.WaitCallback(AnotherLongTask));
    }
    
    private void SomeLongTask(Object state)
    {
        // Insert code to perform a long task.
    }
    
    private void AnotherLongTask(Object state)
    {
        // Insert code to perform a long task.
    }
    

    Update from comments:

    Task Parallel Library (Parralel class) internally uses Threading.Tasks namespace, with some process managing:

    the scheduling of threads on the ThreadPool

    Two another links about: Task Parallelism and Data Parallelism. I think second link can help you with balancing the work for your data.

    When possible, the scheduler redistributes work among multiple threads and processors if the workload becomes unbalanced.

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

Sidebar

Related Questions

Just on the following code do I need to allocate memory with new for
I need to allocate arrays of structures in a bunch of different places in
That's pretty much it. I need to allocate memory and pass it to a
Need some regular expressions help. So far I have my code working to allow
suppose I need to allocate and delete object on heap frequently (of arbitrary size),
In c-strings we need to allocate reasonable size of memory. To avoid reallocations in
I work on win7 and need to allocate 2 buffers using malloc ,each of
what are my options when i need to allocate virtual memory beyond the limits
In C/C++ under Linux, I need to allocate a large (several gigabyte) block of
I have a constructor for my Arduino-code which is something like the following: class

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.