W
W
woodyJS2017-05-25 17:17:50
C++ / C#
woodyJS, 2017-05-25 17:17:50

Parallel programming, what operations should be divided into?

Good afternoon, I need to write the last. and parallel versions of a program that solves slough by square roots.
Wrote last. and I have been sitting for a long time thinking how to parallelize it. After all, in order to proceed to the next step of the solution, you need to wait for the results of the previous step.
code fragment where the solution is calculated.

// A = U(t)*U, далее находим U and U(t)
            double temp;
            double[,] U = new double[n, n];      
            for(int i=0;i<n;i++)
                for (int j=0;j<n;j++)
                {
                    U[i, j] = 0;
                }
            for (int i = 0; i < n; i++)
            {
                temp = 0;
                for (int k=0;k<i;k++)
                    temp = temp + Math.Pow(U[k, i], 2);
                U[i, i] =Math.Sqrt(A[i, i] - temp);
                for (int j = i; j < n; j++)
                {
                    temp = 0;
                    for (int k = 0; k < i; k++)
                        temp = temp + U[k, i] * U[k, j];
                    U[i, j] = (A[i, j] - temp) / U[i, i];
                    
                }
                
            }
            for (int i = 0; i<n;i++)
            {
                for (int j=0; j < n; j++)
                {
                    Console.Write("{0} ", U[i, j]);
                }
                Console.WriteLine();
            }


            double[] x = new double[n];
            double[] y = new double[n];
           
            for (int i=0;i<n;i++)
            {
                temp = 0;
                for(int k=0;k<i;k++)               
                    temp = temp + U[k, i] * y[k];
                y[i] = (b[i] - temp) / U[i, i];
            }
            for(int i=n-1;i>=0;i--)
            {
                temp = 0;
                for (int k = i + 1; k < n; k++)
                    temp = temp + U[i, k] * x[k];
                x[i] = (y[i] - temp) / U[i, i];
            }
            for (int i = 0; i < n; i++)
                Console.Write("{0} ", x[i]);
            Console.WriteLine();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
tomatho, 2017-05-25
@woodyJS

The first parallel is:

for (int k = 0; k < i; k++)
    temp = temp + U[k, i] * U[k, j];

Just split the range of j values ​​into M kernels.
It's easier that way. If we have N operations and we want to split into M cores then it's (N+M-1)/M rounded down operations per core.
Update: Not everything is as simple as it seemed to me, in general, this is not the answer.
You can try to parallelize others, but this is the most resource-intensive part. In general, the description of the parallelization of this algorithm
is well googled .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question