Click here to Skip to main content
15,893,814 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
I have converted the GE algorithm given in the book. Now I want to parallelize it using MPI. Can somebody please guide me how to do that. My serial version is given below:

void GaussianElimination(double **A, double *b,double *y) {
     cout<<"Inside Gaussian 1";
     for(int k=0; k<=n-1; ++k) {
        cout<<"k =" <<k<<endl;
        for(int j= k+1; j <=n-1; ++j){
           cout<<"A["<<k<<"]["<<k<<"] =" <<A[k][k] <<endl;
           A[k][j] = A[k][j]/A[k][k]; 
         }
      
       
        y[k] = b[k]/A[k][k];
        A[k][k]=1;
        cout<<"Reached";
        for(int i=k+1; i<=n-1; i++){
           for(int j=k+1; j<=n-1; j++)
              A[i][j] = A[i][j] -A[i][k] *A[k][j];
           b[i]= b[i] -A[i][k] * y[k];
           A[i][k] = 0;
        }
     }
     cout<<"answers"<<endl;
     for(int i=0; i<=n-1; i++){
        for(int j=0;j<=n-1;j++)
        cout<<A[i][j]<<" ";
        cout<<endl;
     }
} 


Some body please guide me.

What I have tried:

Hi,
I am searching web.

Zulfi.
Posted
Updated 9-May-19 0:32am
Comments
[no name] 2-May-19 15:51pm    
Have you figured out what can run parallel?

The main problem in parallelizing an algorithm is identifying pieces of code that are 100% independent of the rest of the code, in the sense that the order of processing each of the pieces does not matter. For Gaussian elimination in its original form, this is not easily possible: every step builds on another.

Yes you can run the body of the innermost loops in parallel, but these only consist of a single statement, and creating a thread takes way more resources and processing time - so what would be the point?

Which raises the question: what is the goal that you want to achieve by parallelizing GE?


P.S.: I doubted that its' possible to parallelize GE in a meaningful way, but I knew that optimized libraries can do this kind of stuff very efficiently, so I did a search, and found this article:
Parallel Gaussian Elimination using MPI (pdf)[^]
 
Share this answer
 
v2
Comments
zak100 9-May-19 9:35am    
Goal is to become familiar with parallelization techniques. Once we know this technique we can utilize the clusters in an effective manner. This is not an answer. This is a question. I have already given an answer. I have asked for its improvement. Any way thanks for your response. God bless you.
Stefan_Lang 9-May-19 10:28am    
You are right, that was not an answer. I got curious and looked around a bit - please check my solution again for the link I've found.
zak100 9-May-19 23:28pm    
Actually the link you have shown is about GE using pivots. My algorithm is a different one. It is known as Gauss Elimination (GE) with no pivots. I found that link too.Thanks for your time.
Hi,
Yes, the inner loop can be, outermost can't be unless we use pipelined technique.

for(int j= k+1; j <=n-1; ++j){
          :
          
          :
          :
   

     }


Zulfi.
 
Share this answer
 
Comments
[no name] 2-May-19 17:12pm    
The inner loop depends on "k" from the outer loop; and the rest of the outer loop depends on the results of the inner loop. You need multiple outer loops if you want to start multiple "inners" in parallel.

And, you've "answered" your own question.
zak100 2-May-19 17:39pm    
Hi,
One naive approach could be:
if(rank == 0){
k=0;
for(int j= k+1; j <=n-1; ++j){
:

:
:


}
}
else if(rank == 1) {
k=1;
:
:
}
else if (rank== 20){//
k=20;
:
:
}
Can any body please improve on this?

Zulfi.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900