Answer the question
In order to leave comments, you need to log in
How to specify the number of cores and threads when parallelizing?
Hello! The task is quite simple, but something I ran into difficulties. The bottom line is this: you need to produce a product of matrices on several cores, on several threads.
About kernels:
This task is solved using the Parallel class :
List<Action> actions = new List<Action>();
int m = a.Rows;
int step = m / countCPU;
// производим разделение начальных данных (то есть дробим матрицу на подматрицы)
for (int i = 0; i < countCPU; i++)
{
int indexMin = i * step;
int indexMax = (i == (countCPU- 1)) ? (m - 1) : (step * (i + 1) - 1);
// метод CalcMulty выполняет собственное произведение матриц
actions.Add(delegate() { CalcMulty(a.getRangeRows(indexMin, indexMax), b); });
}
// выполняем операции и делаем замер времени
Stopwatch time = new Stopwatch();
time.Start();
Parallel.Invoke(new ParallelOptions() { MaxDegreeOfParallelism = countCPU}, actions.ToArray());
time.Stop();
return time.Elapsed;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question