I have written a code for Gaussian Elimination. But it only works for N>450 & N<500 where N is the num of rows.
For less than 450, it takes more time.
For 500 or greater it shows nothing.
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <omp.h>
int main() {
printf("\nGauss -\n");
double dt_start, dt_stop;
int i,j,k;
float A[500][500],c,sum=0.0;
int n=400;
printf("Matrix\n");
for(i=1; i<=n; i++){
for(j=1; j<=(n+1); j++)
{
A[i][j]=1.0*rand()/20 + 1;
}
}
//Serial execution
dt_start=omp_get_wtime();
for(j=1; j<=n; j++){ /*generation of upper triangular matrix serially*/
for(i=1; i<=n; i++){
if(i>j){
c=A[i][j]/A[j][j];
for(k=1; k<=n+1; k++)
{
A[i][k]=A[i][k]-c*A[j][k];
}
}
}
}
dt_stop=omp_get_wtime();
printf("\nExecution time (Serially): %lf \n",dt_stop-dt_start);
//parallel execution
dt_start=omp_get_wtime();
//#pragma omp parallel for
for(j=1; j<=n; j++){
/*generation of upper triangular matrix*/
#pragma omp parallel for shared(A,j,n) private(i,c,k) default(none)
for(i=1; i<=n; i++){
if(i>j){
c=A[i][j]/A[j][j];
for(k=1; k<=n+1; k++){
A[i][k]=A[i][k]-c*A[j][k];
}
}
}
}
#pragma omp barrier
dt_stop=omp_get_wtime();
printf("\nExecution time (parallelly): %lf \n",dt_stop-dt_start);
}
I have tried using different openmp commands but nothing seems to work.
Edit - It now works for 250 but not less than that. Also, more than 500 it's not working