Dividing up IteratorRange into chunks

27 views
Skip to first unread message

Kaushik Das

unread,
Jun 10, 2022, 5:11:48 PM6/10/22
to deal.II User Group
Hi all,

I want to divide an IteratorRange into smaller chunks and then run some tasks on those smaller ItegratorRanges. 

I tried to do this as follows:

const auto  LargeRangeOfCells = filter_iterators(m_triangulation.active_cell_iterators(),
                                                           IteratorFilters::LocallyOwnedCell());
size_t total_cell_count = std::distance( LargeRangeOfCells.begin(),  LargeRangeOfCells.end());
auto start_cell =  LargeRangeOfCells.begin();
auto end_cell = start_cell;
for (size_t i = 0; i <  total_cell_count   ; i += chunkSize)
 {
            for (auto j = i; j < std::min(i + chunkSize, total_task_count); j++)
            {
                ++end_cell;
            }
IteratorRange<FilteredIterator<FilteredIterator<TriaActiveIterator<dealii::CellAccessor<3, 3>>>>> SmallRangeOfCells(*start_cell, *end_cell);
AddToTaskQueue(tasksOnCells( SmallRangeOfCells);
start_cell = end_cell;
}

But at one cell inside the method tasksOnCells, this assert fails:

An error occurred in line <996> of file </home/kdas/dealii/include/deal.II/grid/tria_iterator.h> in function
    const Accessor& dealii::TriaRawIterator<Accessor>::operator*() const [with Accessor = dealii::CellAccessor<3, 3>]
The violated condition was:
    Accessor::structure_dimension != Accessor::dimension || state() == IteratorState::valid
Additional information:
    You tried to dereference a cell iterator for which this is not possible. More information on this iterator: level=-1, index=-1, state=past_the_end

What is the correct way to divide a filtered iterator range?

Thanks,
Kaushik  

Wolfgang Bangerth

unread,
Jun 11, 2022, 6:41:27 PM6/11/22
to dea...@googlegroups.com
On 6/10/22 15:11, Kaushik Das wrote:
> for (size_t i = 0; i <  total_cell_count   ; i += chunkSize)
>  {
>             for (auto j = i; j < std::min(i + chunkSize, total_task_count); j++)

The mistake is here: It should have been
std::min(..., total_cell_count)
instead of
std::min(..., total_task_count)

That said, there is also this function that already does what you require:

https://dealii.org/developer/doxygen/deal.II/group__threads.html#ga86c4f26c4dacddd38ee225dd1796d7e1

Best
W.

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

Kaushik Das

unread,
Jun 13, 2022, 6:35:13 PM6/13/22
to deal.II User Group
Thank you very much for catching the mistake. 
It is working now.

As for the  Threads::split_range
I am getting a compilation error. 
Something like std pair cannot be created for FilteredIterator<FilteredIterator<TriaActiveIterator<dealii::CellAccessor<3, 3>>>>

Is these utility methods in the Threads namespace available even if I build deal.ii without TBB support?

Thanks,
Kaushik 

Wolfgang Bangerth

unread,
Jun 13, 2022, 7:23:15 PM6/13/22
to dea...@googlegroups.com
On 6/13/22 16:35, Kaushik Das wrote:
> I am getting a compilation error.
> Something like std pair cannot be created for
> FilteredIterator<FilteredIterator<TriaActiveIterator<dealii::CellAccessor<3, 3>>>>
>
> Is these utility methods in the Threads namespace available even if I build
> deal.ii without TBB support?

I'm not sure. What is the exact piece of code you're using, and what is the
error message?
Reply all
Reply to author
Forward
0 new messages