Difference between MeshWorker::mesh_loop and WorkStream::run

60 views
Skip to first unread message

Maxi Miller

unread,
Jan 22, 2019, 9:49:11 AM1/22/19
to deal.II User Group
I was wondering about the difference between calling mesh_loop (from MeshWorker) and run (from WorkStream). According to the documentation it is possible to simply replace run() with mesh_loop() when only looping about own cells, while still having the possibility to extend the program later to also loop over faces. Thus, is there any advantage of using WorkStream over MeshWorker?

Bruno Turcksin

unread,
Jan 22, 2019, 10:40:42 AM1/22/19
to deal.II User Group
Hi,

WorkStream can work using any iterator, i.e., you are not limited to cells. MeshWorker is built on top of WorkStream and it is there to help you with the assembly of your system. So if you want to use multithreading to assemble your system, you probably want to use MeshWorker otherwise you want to use WorkStream.

Best,

Bruno

Maxi Miller

unread,
Jan 22, 2019, 10:48:12 AM1/22/19
to deal.II User Group
I. e. if I would like to calculate f. ex. the L2-norm of a vector (while neglecting that there already is a function for that), I can use WorkStream for parallelization of that, but not MeshWorker, is that correct?

Bruno Turcksin

unread,
Jan 22, 2019, 10:56:28 AM1/22/19
to dea...@googlegroups.com
Le mar. 22 janv. 2019 à 10:48, 'Maxi Miller' via deal.II User Group
<dea...@googlegroups.com> a écrit :
> I. e. if I would like to calculate f. ex. the L2-norm of a vector (while neglecting that there already is a function for that), I can use WorkStream for parallelization of that, but not MeshWorker, is that correct?
That's right. You can use WorkStream using the iterators for the
vector but MeshWorker won't work because it expects cell iterators.

Best,

Bruno

Maxi Miller

unread,
Jan 22, 2019, 10:58:50 AM1/22/19
to deal.II User Group
Perfect, thanks!

Maxi Miller

unread,
Mar 18, 2019, 12:46:12 PM3/18/19
to deal.II User Group
Similar question: How are the different loop-functions differentiated, i.e. MeshWorker::integration_loop and MeshWorker::mesh_loop? Both are able to loop over faces, boundaries and cells, but what are the differences here?
Thanks!

Am Dienstag, 22. Januar 2019 16:56:28 UTC+1 schrieb Bruno Turcksin:

luca.heltai

unread,
Mar 18, 2019, 2:46:41 PM3/18/19
to Deal.II Users
Take a look at this PR for a few examples of usage of mesh_loop:

https://github.com/dealii/dealii/pull/7806

The function WorkStream::run

takes (a minimum of) 5 arguments:

WorkStream::run(cell, endc, cell_worker, copier, scratch, copy);

initial and final iterator, a worker function, a copier function, a scratch object, and a copy object.

Logically, WorkStream::run does the following:

for(it = cell; it != endc; ++it) {
cell_worker(cell, scratch, copy);
copier(copy);
}

and is agnostic about what type of iterator you pass to it.

MeshWorker::mesh_loop is a specific implementation of the above in which the iterator is a cell iterator, and the loop is thought to run also on each face of each cell as well, in order to assemble DG type contributions, i.e., it allows you to specify two additional functions, a boundary_worker and a face_worker:

WorkStream::mesh_loop(cell, endc, cell_worker, copier, scratch, copy, flags, boundary_worker, face_worker);

This is logically identical to

for(it = cell; it != endc; ++it) {
cell_worker(cell, scratch, copy);
for(unsigned int f=0; f<NFaces; ++f) {
if(cell->face(f)->at_boundary() {
boundary_worker(cell, f, scratch, copy);
} else {
// Get subface, neighbor face index, and neighbor subface index
const auto [sf, nf, nsf] = get_neighbor_info(cell, f);
// Run the face worker
face_worker(cell, f, sf, cell->neighbor(f), nf, nsf);
}
}
copier(copy);
}

What mesh_loop does is controlled in a finer way by the assembly flags. For example it is possible to visit each face only once, or to assemble first faces and then cells, etc.

MeshWorker::integration_loop

is a specific implementation of MeshWorker::mesh_loop where you use the DoFInfo and DoFInfoBox objects, that contain scratch and copy data with a different structure. The two behave in a substantially identical way, but with different data structures.

In particular, you could implement MeshWorker::integration_loop using MeshWorker::mesh_loop, and some wrapping around DoFInfo and DoFInfoBox objects.

I hope this clarifies a little the scope of run (agnostic about iterators) and mesh_loop (actually expecting cell iterators, and taking care of subface/face/neighbor matching when looping over faces).

Best,
Luca.
> --
> The deal.II project is located at http://www.dealii.org/
> For mailing list/forum options, see https://groups.google.com/d/forum/dealii?hl=en
> ---
> You received this message because you are subscribed to the Google Groups "deal.II User Group" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to dealii+un...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Maxi Miller

unread,
Mar 19, 2019, 5:08:19 AM3/19/19
to deal.II User Group
Is there a reason then that there are several examples using integration_loop(), but (afaik) only one using mesh_loop?

luca.heltai

unread,
Mar 19, 2019, 5:59:32 AM3/19/19
to Deal.II Users
> Is there a reason then that there are several examples using integration_loop(), but (afaik) only one using mesh_loop?

Yes. mesh_loop is more recent w.r.t. integration_loop.

mesh_loop was introduced to address some of the oddities that are in integration_loop, that make its use somewhat less intuitive w.r.t. WorkStream::run, and was originally thought as the “kernel” of integration_loop.

The original idea was to replace the internals of integration_loop with mesh_loop, but this stage of the project is not yet completed (for lack of time of the original developers of mesh_loop… cough cough… :) …).

The examples in

https://github.com/dealii/dealii/pull/7806

show you a few more ways to use mesh_loop, for DG methods, or using Automatic Differentiation.

Hopefully there will be more examples soon on using mesh_loop.

L.


Maxi Miller

unread,
Mar 19, 2019, 6:11:08 AM3/19/19
to deal.II User Group
Will take a look at it, thanks!

Maxi Miller

unread,
Mar 21, 2019, 10:35:19 AM3/21/19
to deal.II User Group
I tested the implementations with the example from step 12, but refinement after one step ist not allowed (else I will get the error "ou are trying to access the matrix entry with index <>", which means that either my code is wrong, or something else is not working correctly. The question is: What is not working correctly here...
main.cc
Reply all
Reply to author
Forward
0 new messages