-
Notifications
You must be signed in to change notification settings - Fork 6
Use Kokkos::Parallel in DirectSolverTake #262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -5,17 +5,17 @@ namespace direct_solver_coo_mumps_take | |||||
|
|
||||||
| #ifdef GMGPOLAR_USE_MUMPS | ||||||
| // When using the MUMPS solver, the matrix is assembled in COO format. | ||||||
| static inline void updateMatrixElement(SparseMatrixCOO<double, Kokkos::HostSpace>& matrix, int ptr, int offset, int row, | ||||||
| int column, double value) | ||||||
| static KOKKOS_INLINE_FUNCTION void updateMatrixElement(const SparseMatrixCOO<double, Kokkos::HostSpace>& matrix, | ||||||
| int ptr, int offset, int row, int column, double value) | ||||||
| { | ||||||
| matrix.set_row_index(ptr + offset, row); | ||||||
| matrix.set_col_index(ptr + offset, column); | ||||||
| matrix.set_value(ptr + offset, value); | ||||||
| } | ||||||
| #else | ||||||
| // When using the in-house solver, the matrix is stored in CSR format. | ||||||
| static inline void updateMatrixElement(SparseMatrixCSR<double, Kokkos::HostSpace>& matrix, int ptr, int offset, int row, | ||||||
| int column, double value) | ||||||
| static KOKKOS_INLINE_FUNCTION void updateMatrixElement(const SparseMatrixCSR<double, Kokkos::HostSpace>& matrix, | ||||||
| int ptr, int offset, int row, int column, double value) | ||||||
| { | ||||||
| matrix.set_row_nz_index(row, offset, column); | ||||||
| matrix.set_row_nz_entry(row, offset, value); | ||||||
|
|
@@ -26,10 +26,10 @@ static inline void updateMatrixElement(SparseMatrixCSR<double, Kokkos::HostSpace | |||||
|
|
||||||
| template <class LevelCacheType> | ||||||
| void DirectSolverTake<LevelCacheType>::nodeBuildSolverMatrixTake(int i_r, int i_theta, const PolarGrid& grid, | ||||||
| bool DirBC_Interior, SystemMatrix& solver_matrix, | ||||||
| bool DirBC_Interior, const SystemMatrix& solver_matrix, | ||||||
| ConstVector<double>& arr, ConstVector<double>& att, | ||||||
| ConstVector<double>& art, ConstVector<double>& detDF, | ||||||
| ConstVector<double>& coeff_beta) | ||||||
| ConstVector<double>& coeff_beta) const | ||||||
| { | ||||||
| using direct_solver_coo_mumps_take::updateMatrixElement; | ||||||
| int ptr, offset; | ||||||
|
|
@@ -473,7 +473,6 @@ typename DirectSolverTake<LevelCacheType>::SystemMatrix DirectSolverTake<LevelCa | |||||
| { | ||||||
| const PolarGrid& grid = DirectSolver<LevelCacheType>::grid_; | ||||||
| const LevelCacheType& level_cache = DirectSolver<LevelCacheType>::level_cache_; | ||||||
| const int num_omp_threads = DirectSolver<LevelCacheType>::num_omp_threads_; | ||||||
| const bool DirBC_Interior = DirectSolver<LevelCacheType>::DirBC_Interior_; | ||||||
|
|
||||||
| assert(validateSolverMatrixIndexing() && "Solver matrix indexing is inconsistent"); | ||||||
|
|
@@ -501,25 +500,36 @@ typename DirectSolverTake<LevelCacheType>::SystemMatrix DirectSolverTake<LevelCa | |||||
| ConstVector<double> detDF = level_cache.detDF(); | ||||||
| ConstVector<double> coeff_beta = level_cache.coeff_beta(); | ||||||
|
|
||||||
| #pragma omp parallel num_threads(num_omp_threads) | ||||||
| { | ||||||
| /* Circle Section */ | ||||||
| #pragma omp for nowait | ||||||
| for (int i_r = 0; i_r < grid.numberSmootherCircles(); i_r++) { | ||||||
| for (int i_theta = 0; i_theta < grid.ntheta(); i_theta++) { | ||||||
| nodeBuildSolverMatrixTake(i_r, i_theta, grid, DirBC_Interior, solver_matrix, arr, att, art, detDF, | ||||||
| coeff_beta); | ||||||
| } | ||||||
| } | ||||||
| /* Radial Section */ | ||||||
| #pragma omp for nowait | ||||||
| for (int i_theta = 0; i_theta < grid.ntheta(); i_theta++) { | ||||||
| for (int i_r = grid.numberSmootherCircles(); i_r < grid.nr(); i_r++) { | ||||||
| nodeBuildSolverMatrixTake(i_r, i_theta, grid, DirBC_Interior, solver_matrix, arr, att, art, detDF, | ||||||
| coeff_beta); | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| /* We split the loops into two regions to better respect the */ | ||||||
| /* access patterns of the smoother and improve cache locality. */ | ||||||
|
|
||||||
| // The For loop matches circular access pattern */ | ||||||
| Kokkos::parallel_for( | ||||||
| "DirectSolverTake: BuildSolverMatrix (Circular)", | ||||||
| Kokkos::MDRangePolicy<Kokkos::DefaultHostExecutionSpace, Kokkos::Rank<2>>( // Rank of the index space | ||||||
| {0, 0}, // Starting point of the index space | ||||||
| {grid.numberSmootherCircles(), grid.ntheta()} // Ending point of the index space | ||||||
| ), | ||||||
| // Kokkos lambda function to execute for each point in the index space | ||||||
| KOKKOS_LAMBDA(const int i_r, const int i_theta) { | ||||||
| nodeBuildSolverMatrixTake(i_r, i_theta, grid, DirBC_Interior, solver_matrix, arr, att, art, detDF, | ||||||
| coeff_beta); | ||||||
| }); | ||||||
|
|
||||||
| /* For loop matches radial access pattern */ | ||||||
| Kokkos::parallel_for( | ||||||
| "DirectSolverTake: BuildSolverMatrix (Radial)", | ||||||
| Kokkos::MDRangePolicy<Kokkos::DefaultHostExecutionSpace, Kokkos::Rank<2>>( // Rank of the index space | ||||||
| {0, grid.numberSmootherCircles()}, // Starting point of the index space | ||||||
| {grid.ntheta(), grid.nr()} // Ending point of the index space | ||||||
| ), | ||||||
| // Kokkos lambda function to execute for each point in the index space | ||||||
| KOKKOS_CLASS_LAMBDA(const int i_theta, const int i_r) { | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| nodeBuildSolverMatrixTake(i_r, i_theta, grid, DirBC_Interior, solver_matrix, arr, att, art, detDF, | ||||||
| coeff_beta); | ||||||
| }); | ||||||
|
|
||||||
| Kokkos::fence(); | ||||||
|
|
||||||
| return solver_matrix; | ||||||
| } | ||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.