none
Parallel For and MaxDegreeOfParallelism = Environment.ProcessorCount * 10 RRS feed

  • Question

  • var options = new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount * 10 };
    Parallel.ForEach(sourceCollection, options, sourceItem =>
    {
        // do something
    });

    just got the code https://stackoverflow.com/a/17883856/10839668

    i like to know is it good approach to mention no of thread like MaxDegreeOfParallelism = Environment.ProcessorCount * 10 ?

    does it slow down or degrade my process  ? please share the knowledge. thanks

    Thursday, January 10, 2019 12:44 PM

Answers

All replies

  • I would think that using the lock version would be best and that this limits the number of concurrently running operations but not slow slow processes down under normal circumstances.

    I would encouage you to read all the comments post on the page provided.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Thursday, January 10, 2019 2:16 PM
    Moderator
  • Sorry madam not clear what you said...please make your point clear with example. thanks
    Friday, January 11, 2019 7:41 AM
  • What do you mean by lock version  I would think that using the lock version would be best

    please explain with code example.

    Saturday, January 12, 2019 5:04 PM
  • Hi Sudio_inn

    Thank you for posting here.

    You could use threads to speed up a process, please refer to the following link.

    https://stackoverflow.com/questions/45359516/using-threads-to-speed-up-a-process

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Sudip_inn Saturday, February 9, 2019 10:28 AM
    Tuesday, January 29, 2019 8:12 AM
    Moderator
  • Hi Stupid_inn,

    Try to use TaskScheduler to handle the low-level work of queuing tasks onto threads and limit the number of threads used by the app.

    Please refer to the MSDN document. It provides a sample for your reference.

    https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.taskscheduler?redirectedfrom=MSDN&view=netframework-4.7.2

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Sudip_inn Saturday, February 9, 2019 10:28 AM
    Monday, February 4, 2019 7:50 AM
    Moderator
  • I doubt the *10 will do anything useful, since the number of parallell foreaches will be auto-optimized, but Im not 100% sure.

    but using Environment.ProcessorCount is clever, no doubt



    • Edited by ThisNewbie Monday, February 4, 2019 4:07 PM
    Monday, February 4, 2019 4:06 PM