forked from moebiusband/NuSiF-Solver
		
	Compare commits
	
		
			1 Commits
		
	
	
		
			main
			...
			poisson/2D
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | 983ce4ff50 | 
							
								
								
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @@ -53,6 +53,3 @@ Module.symvers | |||||||
| Mkfile.old | Mkfile.old | ||||||
| dkms.conf | dkms.conf | ||||||
|  |  | ||||||
| # LSP config |  | ||||||
| **/compile_commands.json |  | ||||||
| **/.cache |  | ||||||
|   | |||||||
| @@ -45,6 +45,7 @@ int get_dim_start(int dim_rank, int dim_comm_size, int dim_size) | |||||||
|  |  | ||||||
| int get_x_choord(const int proc_num, const int const* dims) { return proc_num / dims[1]; } | int get_x_choord(const int proc_num, const int const* dims) { return proc_num / dims[1]; } | ||||||
| int get_y_choord(const int proc_num, const int const* dims) { return proc_num % dims[1]; } | int get_y_choord(const int proc_num, const int const* dims) { return proc_num % dims[1]; } | ||||||
|  |  | ||||||
| void initSolver(Solver* solver, Parameter* params, int problem) | void initSolver(Solver* solver, Parameter* params, int problem) | ||||||
| { | { | ||||||
|     solver->imax    = params->imax; |     solver->imax    = params->imax; | ||||||
| @@ -139,24 +140,22 @@ void solveRB(Solver* solver) | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     double res = 0.0; |     double res = 0.0; | ||||||
|  | #pragma omp parallel shared(res) | ||||||
|     for (int it = 0; it < itermax; ++it) { |  | ||||||
|  |  | ||||||
|         res = 0.0;  |  | ||||||
|  |  | ||||||
| #pragma omp parallel reduction(+ : res) |  | ||||||
|     { |     { | ||||||
|         const int tid      = omp_get_thread_num(); |         const int tid      = omp_get_thread_num(); | ||||||
|  |  | ||||||
|         const int li_start = get_dim_start(get_x_choord(tid, dim), dim[0], imax); |         const int li_start = get_dim_start(get_x_choord(tid, dim), dim[0], imax); | ||||||
|         const int lj_start = get_dim_start(get_y_choord(tid, dim), dim[1], jmax); |         const int lj_start = get_dim_start(get_y_choord(tid, dim), dim[1], jmax); | ||||||
|  |  | ||||||
|             const int limax = li_start + |         const int limax = li_start + distribute_dim(get_x_choord(tid, dim), dim[0], imax); | ||||||
|                               distribute_dim(get_x_choord(tid, dim), dim[0], imax); |         const int ljmax = lj_start + distribute_dim(get_y_choord(tid, dim), dim[1], jmax); | ||||||
|             const int ljmax = lj_start + |  | ||||||
|                               distribute_dim(get_y_choord(tid, dim), dim[1], jmax); |  | ||||||
|  |  | ||||||
|  |         for (int it = 0; it < itermax; ++it) { | ||||||
|  |  | ||||||
|  | #pragma omp single | ||||||
|  |             { | ||||||
|  |                 res = 0; | ||||||
|  |             } | ||||||
|  |             double local_res = 0; | ||||||
|             int jsw          = ((li_start) % 2 == 0) == ((lj_start) % 2 == 0) ? 1 : 2; |             int jsw          = ((li_start) % 2 == 0) == ((lj_start) % 2 == 0) ? 1 : 2; | ||||||
|  |  | ||||||
|             for (int pass = 0; pass < 2; ++pass) { |             for (int pass = 0; pass < 2; ++pass) { | ||||||
| @@ -170,13 +169,17 @@ void solveRB(Solver* solver) | |||||||
|                                            idy2); |                                            idy2); | ||||||
|  |  | ||||||
|                         P(i, j) -= factor * r; |                         P(i, j) -= factor * r; | ||||||
|                         res += r * r; /* reduction variable */ |                         local_res += r * r; /* reduction variable */ | ||||||
|                     } |                     } | ||||||
|                     isw = 3 - isw; |                     isw = 3 - isw; | ||||||
|                 } |                 } | ||||||
| #pragma omp barrier |  #pragma omp barrier | ||||||
|                 jsw = 3 - jsw; |                 jsw = 3 - jsw; | ||||||
|             } |             } | ||||||
|  | #pragma omp critical | ||||||
|  |             { | ||||||
|  |                 res += local_res; | ||||||
|  |             } | ||||||
|             if (lj_start == 0) |             if (lj_start == 0) | ||||||
|                 for (int i = li_start + 1; i < limax + 1; i++) |                 for (int i = li_start + 1; i < limax + 1; i++) | ||||||
|                     P(i, 0) = P(i, 1); |                     P(i, 0) = P(i, 1); | ||||||
| @@ -189,21 +192,20 @@ void solveRB(Solver* solver) | |||||||
|             if (limax == imax) |             if (limax == imax) | ||||||
|                 for (int j = lj_start + 1; j < ljmax + 1; j++) |                 for (int j = lj_start + 1; j < ljmax + 1; j++) | ||||||
|                     P(limax + 1, j) = P(limax, j); |                     P(limax + 1, j) = P(limax, j); | ||||||
|  | #pragma omp single | ||||||
|         }  |             { | ||||||
|  |  | ||||||
|                 res /= (double)(imax * jmax); |                 res /= (double)(imax * jmax); | ||||||
|  |  | ||||||
| #ifdef DEBUG | #ifdef DEBUG | ||||||
|                 printf("%d Residuum: %e\n", it, res); |                 printf("%d Residuum: %e\n", it, res); | ||||||
| #endif | #endif | ||||||
|  |             } | ||||||
|  | #pragma omp barrier | ||||||
|             if (res < epssq) { |             if (res < epssq) { | ||||||
|             printf("Solver took %d iterations to reach %e\n", it + 1, sqrt(res)); |                 break; | ||||||
|             return;  |             } | ||||||
|  | #pragma omp barrier | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     printf("Solver reached itermax (%d) with residual %e\n", itermax, sqrt(res)); |     printf("Solver reached itermax (%d) with residual %e\n", itermax, sqrt(res)); | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user