Распараллеливание транспонирования матрицы - C#
Формулировка задачи:
Помогите распараллелить.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace arr
{
public class myClass
{
private int m;
private int n;
myClass()
{
}
myClass(int m)
{
this.m = m;
}
myClass(int m, int n)
{
this.m = m;
this.n = n;
}
}
public class matrica
{
private int n;
private double[,] a;
public matrica(int n)
{
this.n = n;
a = new double[n, n];
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
a[i, j] = i + 2 * j + (i * j);
}
}
}
public void print()
{
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
Console.Write(" {0}", a[i, j]);
}
Console.WriteLine();
}
}
public void transp()
{
double tmp;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < i; j++)
{
tmp = a[i, j];
a[i, j] = a[j, i];
a[j, i] = tmp;
}
}
}
class Program
{
static void Main(string[] args)
{
matrica a = new matrica(3);
a.print();
a.transp();
Console.WriteLine();
a.print();
Console.WriteLine();
}
}
}
}Решение задачи: «Распараллеливание транспонирования матрицы»
textual
Листинг программы
Parallel.For(0, n, (i) => myfunc(i));
private void myfunc(int i)
{
for (int j = 0; j < i; j++) { double tmp = arr1[i, j];
arr1[i, j] = arr1[j, i];
arr1[j, i] = tmp;
};