Skip to content

Commit

Permalink
use prod
Browse files Browse the repository at this point in the history
  • Loading branch information
WeiyiVirtonomy committed Sep 18, 2024
1 parent 28b9e9a commit 2615d53
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions src/shared/meshes/cell_linked_list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,6 @@ void CellLinkedList::searchNeighborsByParticles(
});
}
//=================================================================================================//
inline size_t get_1d_number_of_cells(const Array2i &all_cells)
{
return all_cells[0] * all_cells[1];
}
inline size_t get_1d_number_of_cells(const Array3i &all_cells)
{
return all_cells[0] * all_cells[1] * all_cells[2];
}
//=================================================================================================//
template <class LocalDynamicsFunction>
void CellLinkedList::particle_for_split(const execution::SequencedPolicy &, const LocalDynamicsFunction &local_dynamics_function)
{
Expand All @@ -105,7 +96,7 @@ void CellLinkedList::particle_for_split(const execution::SequencedPolicy &, cons
// i_max = (M - m - 1) / 3 + 1, j_max = (N - n - 1) / 3 + 1
// e.g. all_cells = (M,N) = (6, 9), (m, n) = (1, 1), then i_max = 2, j_max = 3
const Arrayi all_cells_k = (all_cells_ - split_cell_index - Arrayi::Ones()) / 3 + Arrayi::Ones();
const size_t number_of_cells = get_1d_number_of_cells(all_cells_k); // i_max * j_max
const size_t number_of_cells = all_cells_k.prod(); // i_max * j_max

// looping over all cells in the split cell k
for (size_t l = 0; l < number_of_cells; l++)
Expand All @@ -130,7 +121,7 @@ void CellLinkedList::particle_for_split(const execution::SequencedPolicy &, cons
{
const Arrayi split_cell_index = transfer1DtoMeshIndex(3 * Arrayi::Ones(), k - 1);
const Arrayi all_cells_k = (all_cells_ - split_cell_index - Arrayi::Ones()) / 3 + Arrayi::Ones();
const size_t number_of_cells = get_1d_number_of_cells(all_cells_k);
const size_t number_of_cells = all_cells_k.prod();

for (size_t l = 0; l < number_of_cells; l++)
{
Expand All @@ -152,7 +143,7 @@ void CellLinkedList::particle_for_split(const execution::ParallelPolicy &, const
{
const Arrayi split_cell_index = transfer1DtoMeshIndex(3 * Arrayi::Ones(), k);
const Arrayi all_cells_k = (all_cells_ - split_cell_index - Arrayi::Ones()) / 3 + Arrayi::Ones();
const size_t number_of_cells = get_1d_number_of_cells(all_cells_k);
const size_t number_of_cells = all_cells_k.prod();

parallel_for(
IndexRange(0, number_of_cells),
Expand All @@ -176,7 +167,7 @@ void CellLinkedList::particle_for_split(const execution::ParallelPolicy &, const
{
const Arrayi split_cell_index = transfer1DtoMeshIndex(3 * Arrayi::Ones(), k - 1);
const Arrayi all_cells_k = (all_cells_ - split_cell_index - Arrayi::Ones()) / 3 + Arrayi::Ones();
const size_t number_of_cells = get_1d_number_of_cells(all_cells_k);
const size_t number_of_cells = all_cells_k.prod();

parallel_for(
IndexRange(0, number_of_cells),
Expand Down

0 comments on commit 2615d53

Please sign in to comment.