diff --git a/sor_convergence/sor_static_wavefront/Makefile b/sor_convergence/sor_static_wavefront/Makefile index f772322..4cee729 100755 --- a/sor_convergence/sor_static_wavefront/Makefile +++ b/sor_convergence/sor_static_wavefront/Makefile @@ -1,9 +1,13 @@ -CC = /opt/rh/devtoolset-2/root/usr/bin/gcc -#CC = gcc +#CC = /opt/rh/devtoolset-2/root/usr/bin/gcc +CC = gcc OMP_FLAG = -fopenmp +<<<<<<< HEAD +CFLAGS = -O3 -c ${OMP_FLAG} +======= CFLAGS = -O1 -c ${OMP_FLAG} #CFLAGS = -O2 -c ${OMP_FLAG} #CFLAGS = -c ${OMP_FLAG} +>>>>>>> 7046cb8ce94f73f6687fb2a3c9e75bd38a03fb26 LFLAGS = -lm .SUFFIXES : .o .c diff --git a/sor_convergence/sor_static_wavefront/sor_wavefront b/sor_convergence/sor_static_wavefront/sor_wavefront new file mode 100755 index 0000000..a8e41a1 Binary files /dev/null and b/sor_convergence/sor_static_wavefront/sor_wavefront differ diff --git a/sor_convergence/sor_static_wavefront/sor_wavefront.o b/sor_convergence/sor_static_wavefront/sor_wavefront.o new file mode 100644 index 0000000..b714b27 Binary files /dev/null and b/sor_convergence/sor_static_wavefront/sor_wavefront.o differ diff --git a/sor_original/Makefile b/sor_original/Makefile new file mode 100755 index 0000000..731f767 --- /dev/null +++ b/sor_original/Makefile @@ -0,0 +1,17 @@ +#CC = /opt/rh/devtoolset-2/root/usr/bin/gcc +CC = gcc +OMP_FLAG = -fopenmp +#CFLAGS = -O2 -c ${OMP_FLAG} +CFLAGS = -O3 -c ${OMP_FLAG} +LFLAGS = -lm + +.SUFFIXES : .o .c + +.c.o: + ${CC} ${CFLAGS} -o $@ $*.c + +sor: sor.o + ${CC} ${OMP_FLAG} -o $@ $@.o ${LFLAGS} + +clean: + rm *.o sor diff --git a/sor_original/sor b/sor_original/sor new file mode 100755 index 0000000..5f03efc Binary files /dev/null and b/sor_original/sor differ diff --git a/sor_original/sor.c b/sor_original/sor.c new file mode 100644 index 0000000..a3ef1ad --- /dev/null +++ b/sor_original/sor.c @@ -0,0 +1,97 @@ +#include +#include +#include + +// *** Solution of Laplace's Equation. +// *** +// *** Uxx + Uyy = 0 +// *** 0 <= x <= pi, 0 <= y <= pi +// *** U(x,pi) = sin(x), U(x,0) = U(0,y) = U(pi,y) = 0 +// *** +// *** then U(x,y) = (sinh(y)*sin(x)) / sinh(pi) +// *** +// *** Should converge with +// *** tol = 0.001 and M = 22 in 60 iterations. +// *** and with tol = 0.001 and M = 102 in 200 iterations. +// *** and with tol = 0.001 and M = 502 in 980 iterations. +// *** + +#define N 502 +#define MAX(a,b) ( ( (a)>(b) ) ? (a) : (b) ) + +double x[N][N], xnew[N][N], solution[N][N]; + +double calcerror(double g[][N], int iter); + +int main(int argc, char *argv[]){ + double tol=0.001, h, omega, error; + double pi = (double)4.0*atan((double)1.0); + int iter=0, i, j; + + h = M_PI/(double)(N-1); + + for(i=0; i= tol){ + + for(i=1; i +#include +#include +#include + +// *** Solution of Laplace's Equation. +// *** +// *** Uxx + Uyy = 0 +// *** 0 <= x <= pi, 0 <= y <= pi +// *** U(x,pi) = sin(x), U(x,0) = U(0,y) = U(pi,y) = 0 +// *** +// *** then U(x,y) = (sinh(y)*sin(x)) / sinh(pi) +// *** +// *** Should converge with +// *** tol = 0.001 and M = 22 in 60 iterations. +// *** and with tol = 0.001 and M = 102 in 200 iterations. +// *** and with tol = 0.001 and M = 502 in 980 iterations. +// *** + +#define N 502 +#define MAX(a,b) ( ( (a)>(b) ) ? (a) : (b) ) + +double x[N][N], xnew[N][N], solution[N][N]; + +double calcerror(double g[][N], int iter); + +int main(int argc, char *argv[]){ + double tol=0.001, h, omega, error; + double pi = (double)4.0*atan((double)1.0); + int iter=0, i, j; + double total_start; + double total_time = 0.0; + + total_start = omp_get_wtime(); + h = M_PI/(double)(N-1); + + for(i=0; i= tol){ + //red + for(i=1; i +#include +#include +#include + +// *** Solution of Laplace's Equation. +// *** +// *** Uxx + Uyy = 0 +// *** 0 <= x <= pi, 0 <= y <= pi +// *** U(x,pi) = sin(x), U(x,0) = U(0,y) = U(pi,y) = 0 +// *** +// *** then U(x,y) = (sinh(y)*sin(x)) / sinh(pi) +// *** +// *** Should converge with +// *** tol = 0.001 and M = 22 in 60 iterations. +// *** and with tol = 0.001 and M = 102 in 200 iterations. +// *** and with tol = 0.001 and M = 502 in 980 iterations. +// *** + +#define N 180 +#define MAX(a,b) ( ( (a)>(b) ) ? (a) : (b) ) + + +double x[N][N], xnew[N][N], solution[N][N]; + +double calcerror(double g[][N], int iter); + +int main(int argc, char *argv[]){ + double tol=0.001, h, omega, error; + double pi = (double)4.0*atan((double)1.0); + int iter=0, i, j; + double total_start; + double total_time = 0.0; + int numthreads; + + total_start = omp_get_wtime(); + h = M_PI/(double)(N-1); + + for(i=0; i= tol){ + #pragma omp parallel for \ + schedule (static) + //red + for(i=1; i +#include +#include +#include + +// *** Solution of Laplace's Equation. +// *** Note that this experiment is using wavefront +// *** Uxx + Uyy = 0 +// *** 0 <= x <= pi, 0 <= y <= pi +// *** U(x,pi) = sin(x), U(x,0) = U(0,y) = U(pi,y) = 0 +// *** +// *** then U(x,y) = (sinh(y)*sin(x)) / sinh(pi) +// *** +// *** Should converge with +// *** tol = 0.001 and N = 22 in 60 iterations. +// *** and with tol = 0.001 and N = 102 in 200 iterations. +// *** and with tol = 0.001 and N = 502 in 980 iterations. +// *** + +#define N 502 // 50 is a good size to be used for debugging. The wavefront algorithm is VERY slow on sequential machines. +#define MAX(a,b) ( ( (a)>(b) ) ? (a) : (b) ) + +// To paralise the code, x[][], xnew[][] and solution[][] should not be global +//double x[N][N], xnew[N][N], solution[N][N]; + +double calcerror(double **g, int iter, double **s); +void matrix_initialise(double **x_matrix, double **xnew_matrix, double **solution_matrix, double h); + +int main(int argc, char *argv[]){ + double tol=0.001, h, omega, error; + double pi = (double)4.0*atan((double)1.0); + int iter=0, i, j; + double x[N][N], **x_ptr; + double xnew[N][N], **xnew_ptr; + double solution[N][N], **solution_ptr; + int slength; // variable to skip the first and last two diagonal strips + int z; // variable to skip boundary elements + + // variables for omp timmer + double calcerror_start; + double calcerror_time = 0.0; + + // calculate constant values, h and omega + h = M_PI/(double)(N-1); + omega = 2.0/(1.0+sin(M_PI/(double)(N-1))); + + // set up pointers to allow x[][], xnew[][] and solution[][] access in calcerror + x_ptr = (double **)malloc((unsigned) N * sizeof(double)); + for (i=0; i < N; i++) { + x_ptr[i] = x[i]; + } + + xnew_ptr = (double **)malloc((unsigned) N * sizeof(double)); + for (i=0; i < N; i++) { + xnew_ptr[i] = xnew[i]; + } + + solution_ptr = (double **)malloc((unsigned) N * sizeof(double)); + for (i=0; i < N; i++) { + solution_ptr[i] = solution[i]; + } + + // initialise x, xnew, y + matrix_initialise(x_ptr, xnew_ptr, solution_ptr, h); + + // boundary conditions, copy the box boundaires from x to xnew array + for(i=0; i= tol){ + // wavefront parallelism + for (i=0; i < (2*N -1); i++){ + int k = (i < N) ? 0 : (i - N + 1); + slength = (i - k -k + 1); + if (slength > 2) { + #pragma omp parallel for + for (j=k; j <= i-k; j++){ + if (j==k || j == i-k) { + continue; // skip boundary conditions + } + xnew[j][i-j] = x[j][i-j]+0.25*omega*(xnew[j-1][i-j] + xnew[j][i-j-1] \ + + x[j+1][i-j] + x[j][i-j+1] - (4*x[j][i-j])); + } + } + } + #pragma omp parallel for + for(i=1; i +#include +#include +#include + +// *** Solution of Laplace's Equation. +// *** Note that this experiment is using wavefront +// *** Uxx + Uyy = 0 +// *** 0 <= x <= pi, 0 <= y <= pi +// *** U(x,pi) = sin(x), U(x,0) = U(0,y) = U(pi,y) = 0 +// *** +// *** then U(x,y) = (sinh(y)*sin(x)) / sinh(pi) +// *** +// *** Should converge with +// *** tol = 0.001 and N = 22 in 60 iterations. +// *** and with tol = 0.001 and N = 102 in 200 iterations. +// *** and with tol = 0.001 and N = 502 in 980 iterations. +// *** + +#define N 180 // 50 is a good size to be used for debugging. The wavefront algorithm is VERY slow on sequential machines. +#define MAX(a,b) ( ( (a)>(b) ) ? (a) : (b) ) + +// To paralise the code, x[][], xnew[][] and solution[][] should not be global +//double x[N][N], xnew[N][N], solution[N][N]; + +double calcerror(double **g, int iter, double **s); +void matrix_initialise(double **x_matrix, double **xnew_matrix, double **solution_matrix, double h); + +int main(int argc, char *argv[]){ + double tol=0.001, h, omega, error; + double pi = (double)4.0*atan((double)1.0); + int iter=0, i, j; + double x[N][N], **x_ptr; + double xnew[N][N], **xnew_ptr; + double solution[N][N], **solution_ptr; + int slength; // variable to skip the first and last two diagonal strips + int z; // variable to skip boundary elements + + // variables for omp timmer + double calcerror_start; + double calcerror_time = 0.0; + + // calculate constant values, h and omega + h = M_PI/(double)(N-1); + omega = 2.0/(1.0+sin(M_PI/(double)(N-1))); + + // set up pointers to allow x[][], xnew[][] and solution[][] access in calcerror + x_ptr = (double **)malloc((unsigned) N * sizeof(double)); + for (i=0; i < N; i++) { + x_ptr[i] = x[i]; + } + + xnew_ptr = (double **)malloc((unsigned) N * sizeof(double)); + for (i=0; i < N; i++) { + xnew_ptr[i] = xnew[i]; + } + + solution_ptr = (double **)malloc((unsigned) N * sizeof(double)); + for (i=0; i < N; i++) { + solution_ptr[i] = solution[i]; + } + + // initialise x, xnew, y + matrix_initialise(x_ptr, xnew_ptr, solution_ptr, h); + + // boundary conditions, copy the box boundaires from x to xnew array + for(i=0; i= tol){ + // wavefront parallelism + for (i=0; i < (2*N -1); i++){ + int k = (i < N) ? 0 : (i - N + 1); + slength = (i - k -k + 1); + if (slength > 2 && ((slength+2)%2==0)) { + #pragma omp parallel for + for (j=k; j <= i-k; j++){ + if (j==k || j == i-k) { + continue; // skip boundary conditions + } + xnew[j][i-j] = x[j][i-j]+0.25*omega*(xnew[j-1][i-j] + xnew[j][i-j-1] \ + + x[j+1][i-j] + x[j][i-j+1] - (4*x[j][i-j])); + } + for(i=1; i 2 && ((slength+2)%2==1)) { + #pragma omp parallel for + for (j=k; j <= i-k; j++){ + if (j==k || j == i-k) { + continue; // skip boundary conditions + } + xnew[j][i-j] = x[j][i-j]+0.25*omega*(xnew[j-1][i-j] + xnew[j][i-j-1] \ + + x[j+1][i-j] + x[j][i-j+1] - (4*x[j][i-j])); + } + for(i=1; i