F
F
fs_name2015-09-30 21:53:46
C++ / C#
fs_name, 2015-09-30 21:53:46

C# Parallel.ForEach in Parallel.ForEach. Does it make sense?

Good afternoon. The question is purely theoretical - there is such a piece of code:

ParallelOptions _parallel_options = new ParallelOptions();
         _parallel_options.MaxDegreeOfParallelism = _ret.threads_count;

         Parallel.ForEach<string>(File.ReadLines(_ret.file_name, _codepage)
                                  , _parallel_options
                                  , (_line, _parallel_state, _index) =>
         {
            //some code
            Parallel.For(0, _idx, (_field_index) =>
            {
            //some code
            });
         });

Is it possible to get some profit from parallel - a construction inside parallel, if you do not limit the MaxDegreeOfParallelism of the first loop? Or if you limit?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
VanKrock, 2015-09-30
@VanKrock

It seems to me that in this case you will run into reading from disk

D
Dmitry Chernyakov, 2015-10-01
@Kubatai

There was a task, I decided to do it in a similar way. As a result, when using such a structure without creating a second thread for the internal Parallel.ForEach, a performance drop was noticed when executing a piece of code. As a result, for my task, it was decided to use only one Parallel.ForEach.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question