Nested loop over cells in a parallel distributed triangulation

21 views
Skip to first unread message

Davit Gyulamiryan

unread,
Jan 9, 2025, 6:56:26 AM1/9/25
to deal.II User Group
Hi,

I have encountered a problem when introducing a second loop over cells (in parallel distributed triangulation). The code looks something like this:

for (const auto &cell_outer : dof_handler_vel.active_cell_iterators())
{
if (cell_outer->is_locally_owned()) {do something...}
for (const auto &cell_inner : dof_handler_vel.active_cell_iterators())
{
if (cell_inner->is_locally_owned()) {do something...} } }

and the problem is that no process takes ownership over cell_outer, i.e. the body of the first if statement is never executed. The second loop works fine.

If anyone experienced this sort of problem, or understand what is happening here, I would appreciate any help.

For context: I have source strength (e.g. a charge) at each support point of the FE, and I want to calculate the field induced by these sources at each of the support points. My approach: first loop iterates over the cells to obtain the coordinates of the support points - the process that owns the cell broadcasts the coordinates to all the other processes, second loop calculates the field strength at these support points by integrating over the entire domain.

I am sure there is a better way of doing this. I searched the documentation but did not find anything. Has anyone done something similar and could help me?

Best,
Davit

Wolfgang Bangerth

unread,
Jan 9, 2025, 7:39:14 AM1/9/25
to dea...@googlegroups.com
On 1/9/25 04:56, Davit Gyulamiryan wrote:
>
> and the problem is that no process takes ownership over /cell_outer/, i.e. the
> body of the first /if /statement is never executed. The second loop works fine.

This makes no sense. If the 'if' in the first loop is never entered, how do
you know that the second loop actually works? What happens if inside the 'if'
there is only a print statement that shows where you are?


> For context: I have source strength (e.g. a charge) at each support point of
> the FE, and I want to calculate the field induced by these sources at each of
> the support points. My approach: first loop iterates over the cells to obtain
> the coordinates of the support points - the process that owns the cell
> broadcasts the coordinates to all the other processes, second loop calculates
> the field strength at these support points by integrating over the entire domain.

This can not work as you describe. Broadcasts are collective operations. You
cannot just send on one process and hope that the others magically receive the
data. The others need to *know* that the first process sent them data and
expect it.

Best
W.

--
------------------------------------------------------------------------
Wolfgang Bangerth email: bang...@colostate.edu
www: http://www.math.colostate.edu/~bangerth/


Reply all
Reply to author
Forward
0 new messages