<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
Hi.
<div>That is one reason why the loadbalance method takes a callback object with gather and scatter like communicate. The grid then makes sure that these methods are called on the right entities. So while gathering the data on one processor its local idset can
be used and the same holds on the receiving process. In the grid-howto there is an example showing a possible way to use this with the persistent containers. </div>
<div>Andreas </div>
<br>
Bernd Flemisch <bernd@iws.uni-stuttgart.de> wrote:<br>
<font size="2"><span style="font-size:10pt;">
<div class="PlainText">Hi Martin,<br>
<br>
thank you for your answer. This indeed sounds a lot earlier sier and like the <br>
solution I originally wanted to achieve. Nevertheless, I am a bit <br>
puzzled now. I deliberately preferred global over local Ids, since<br>
"A local id set provides ids that are unique within one process but two <br>
entities in different processes may have the same id," see<br>
<a href="http://www.dune-project.org/doc/doxygen/dune-grid-html/class_dune_1_1_id_set.html#_details" target="_BLANK">http://www.dune-project.org/doc/doxygen/dune-grid-html/class_dune_1_1_id_set.html#_details</a><br>
<br>
So I thought that with local Ids it could happen that an entity is moved <br>
from one process to another, where another entity with the same Id <br>
already exists. And then this would not work out. Or am I missing <br>
something?<br>
<br>
Kind regards<br>
Bernd<br>
<br>
On 02/22/2013 09:13 AM, Martin Nolte wrote:<br>
> Hi Bernd,<br>
><br>
> I guess you are the first to use global ids during load balancing and <br>
> it seems you hit on a bug in ALUGrid (please file a complete bug <br>
> report on this).<br>
><br>
> Actually, the solution we use is far simpler. Store your data in a <br>
> std::map using the LocalIdSet (or use a PersistentContainer). This <br>
> way, your data will always be accessible, even during load balancing. <br>
> Then you write a data handle (warning: you communicate on the entire <br>
> hierarchy). That's it.<br>
><br>
> Let me give a bit of explaination: Behind the scenes, ALUGrid will <br>
> pack data for a macro element to be sent to another process. To this <br>
> end, it will traverse the tree and pack the element information and <br>
> your data (calling gather). When all macro elements have been packed, <br>
> the data is sent to the new processes. Here, they are unpacked, i.e., <br>
> the element is constructed and all scatter is called. During scatter, <br>
> the ids will already be valid, so you can use them to access your data <br>
> container (though the global id might be buggy, as you stated).<br>
><br>
> One final opinion: GlobalIds are an artificial DUNE construct. <br>
> Implementing them might be quite complicated and expensive. This is <br>
> the case for ALUGrid, where they are generated in the DUNE bindings. <br>
> Hence, they have to communicated during load balancing (expensive). <br>
> So, if you ask ALUGrid for the global id set once, you got to pay this <br>
> price. There is no way of telling how long this id set is to be used <br>
> (because it is returned by reference).<br>
><br>
> Best,<br>
><br>
> Martin<br>
><br>
><br>
><br>
><br>
><br>
> On 02/22/2013 07:35 AM, Bernd Flemisch wrote:<br>
>> Hi,<br>
>><br>
>> sorry for the noise again, but I found a working solution. So if you <br>
>> already<br>
>> started to brood over the problem, you may relax.<br>
>><br>
>> I assume that the Ids are still valid during gather and will become <br>
>> valid<br>
>> again and with the same values after load balance. I simply gather <br>
>> the Ids<br>
>> together with the data and scatter both of them. In a postprocess <br>
>> after load<br>
>> balance, I use this (now valid) information to write the values into the<br>
>> corresponding vector.<br>
>><br>
>> This works for several grids and numbers of processes, so I hope for <br>
>> all of<br>
>> them. I attach the file.<br>
>><br>
>> If you think this is important enough to become a test in <br>
>> dune/grid/test and<br>
>> feel responsible for evaluating and committing it, I am happy to <br>
>> provide a<br>
>> patch and to improve it together with you.<br>
>><br>
>> Thanks to Andreas and Martin for the hints which helped to achieve <br>
>> this. Kind<br>
>> regards<br>
>> Bernd<br>
>><br>
>> On Thu, 21 Feb 2013 19:12:44 +0100<br>
>> Bernd Flemisch <bernd@iws.uni-stuttgart.de> wrote:<br>
>>> Actually, the Ids are the same again after the load balancing step <br>
>>> is over.<br>
>>> But apparently not during scatter, where I would need it. Hmmm...<br>
>>><br>
>>> On Thu, 21 Feb 2013 17:55:51 +0100<br>
>>> Bernd Flemisch <bernd@iws.uni-stuttgart.de> wrote:<br>
>>>> Hi,<br>
>>>><br>
>>>> only a few months have passed and I found the time to look at this <br>
>>>> again. I<br>
>>>> tried to follow Andreas' suggestion and work with Ids rather than <br>
>>>> indices,<br>
>>>> since they should be persistent. I was hoping that "persistent" <br>
>>>> means that,<br>
>>>> if an element is moved from one process to another, it keeps its <br>
>>>> global Id.<br>
>>>> Looking at<br>
>>>> <a href="http://www.dune-project.org/doc/doxygen/dune-grid-html/class_dune_1_1_id_set.html#_details" target="_BLANK">
http://www.dune-project.org/doc/doxygen/dune-grid-html/class_dune_1_1_id_set.html#_details</a>
<br>
>>>><br>
>>>><br>
>>>> does not necessarily say that (I think).<br>
>>>><br>
>>>> I set up a test for my efforts, see the attached file. The coarse <br>
>>>> grid is<br>
>>>> 5x1x1. The two left elements are interior on process 1, the three <br>
>>>> right<br>
>>>> ones interior on process 2. The two left elements get refined. After<br>
>>>> adaption, loadBalance with my DataHandle is called. The three right<br>
>>>> elements are all moved to process 1, so that after the balancing step,<br>
>>>> process 1 holds all elements, while process 0 has none.<br>
>>>><br>
>>>> During load balance, I print the cell centers, global Ids, and<br>
>>>> gathered/scattered values on each process. This gives the following:<br>
>>>> Process 0:<br>
>>>> 0: 0.5 0.5 0.5, ([2,3,8,14],8,0): gather 0<br>
>>>> 0: 0.7 0.5 0.5, ([3,4,9,15],8,0): gather 1<br>
>>>> 0: 0.9 0.5 0.5, ([4,5,10,16],8,0): gather 2<br>
>>>> Process 1:<br>
>>>> 1: 0.5 0.5 0.5, ([2,3,8,14],71,0): scatter 0<br>
>>>> 1: 0.7 0.5 0.5, ([2,3,8,14],70,0): scatter 1<br>
>>>> 1: 0.9 0.5 0.5, ([2,3,8,14],69,0): scatter 2<br>
>>>> It seems to be correct that information from three elements is sent <br>
>>>> from<br>
>>>> process 0 and received for the corresponding elements by process 1.<br>
>>>> However, the global Ids are changed. Is this correct? Then how tf <br>
>>>> can I<br>
>>>> find out which elements correspond to each other? Or am I still doing<br>
>>>> something wrong?<br>
>>>><br>
>>>> Thank you for having another look. Kind regards<br>
>>>> Bernd<br>
>>>><br>
>>>> On Sat, 27 Oct 2012 07:43:48 +0000<br>
>>>> "Dedner, Andreas" <A.S.Dedner@warwick.ac.uk> wrote:<br>
>>>>> Is it not even so that one can not use an undexset at all? Load <br>
>>>>> balancing<br>
>>>>> changes the grid so the indexsets are not valid. You need to use id<br>
>>>>> containers.<br>
>>>>> Andreas<br>
>>>>><br>
>>>>> Martin Nolte <nolte@mathematik.uni-freiburg.de> wrote:<br>
>>>>> Hi Bernd,<br>
>>>>><br>
>>>>> I have an educated guess for you (don't blame me, if I'm wrong):<br>
>>>>><br>
>>>>> In normal communication, you only communicate data on a certain <br>
>>>>> grid view.<br>
>>>>> Hence<br>
>>>>> you can use the index set to address data stored on that grid view.<br>
>>>>><br>
>>>>> When doing load balancing, you rather communicate data on the entire<br>
>>>>> hierarchy.<br>
>>>>> Therefore, your entity might not be contained an index set <br>
>>>>> (leading to this<br>
>>>>> cryptic assertion). So, if you want to communicate data only on a <br>
>>>>> certain<br>
>>>>> grid<br>
>>>>> view, you have to add a call to indexSet.contains to the gather / <br>
>>>>> scatter<br>
>>>>> / size<br>
>>>>> methods. Usually, fixedSize will be false in such situations (I <br>
>>>>> think ALUGrid<br>
>>>>> ignores this anyway, so it should not matter, here).<br>
>>>>><br>
>>>>> Just a side note: In my opionion, a normal communicate method <br>
>>>>> exchanging<br>
>>>>> data on<br>
>>>>> the entire hierarchy would be nice, too. But alas, this method would<br>
>>>>> naturally<br>
>>>>> be "grid().communicate( dataHandle, interface, direction )".<br>
>>>>><br>
>>>>> Best,<br>
>>>>><br>
>>>>> Martin<br>
>>>>><br>
>>>>> On 10/26/2012 01:32 PM, Bernd Flemisch wrote:<br>
>>>>>> Hey Andreas,<br>
>>>>>><br>
>>>>>> thank you for your fast answer. This indeed solves my second issue.<br>
>>>>>> However, the<br>
>>>>>> first one remains. I attach an updated test file.<br>
>>>>>><br>
>>>>>> Kind regards<br>
>>>>>> Bernd<br>
>>>>>><br>
>>>>>> On 10/26/2012 01:08 PM, Dedner, Andreas wrote:<br>
>>>>>>> Hi Bernd<br>
>>>>>>><br>
>>>>>>> You should be able to cast the derived class onto the interface <br>
>>>>>>> class<br>
>>>>>>> and that triggers the call to the correct method.<br>
>>>>>>><br>
>>>>>>> Andreas<br>
>>>>>>><br>
>>>>>>> ________________________________________<br>
>>>>>>> From: dune-bounces+a.s.dedner=warwick.ac.uk@dune-project.org<br>
>>>>>>> [dune-bounces+a.s.dedner=warwick.ac.uk@dune-project.org] on <br>
>>>>>>> behalf of Bernd<br>
>>>>>>> Flemisch [bernd@iws.uni-stuttgart.de]<br>
>>>>>>> Sent: 26 October 2012 11:53<br>
>>>>>>> To: Dune<br>
>>>>>>> Subject: [Dune] Dynamic load balancing with ALUGrid<br>
>>>>>>><br>
>>>>>>> Dear Dune,<br>
>>>>>>><br>
>>>>>>> I try to use dynamic load balancing with ALUGrid. The grid <br>
>>>>>>> itself gets<br>
>>>>>>> balanced nicely, but I don't succeed in getting data balanced.<br>
>>>>>>><br>
>>>>>>> From dune/grid/alugrid/3d/grid.hh lines 701ff, I guess that I <br>
>>>>>>> can pack<br>
>>>>>>> a "usual" data handle which is used for communication into a<br>
>>>>>>> ALUGridLoadBalanceDataHandle and call loadBalance with that <br>
>>>>>>> handle. My<br>
>>>>>>> initial attempt to do this fails with<br>
>>>>>>> test-dynamiclb:<br>
>>>>>>> ../../../dune/grid/alugrid/common/defaultindexsets.hh:218:<br>
>>>>>>> Dune::DefaultIndexSet<GridImp, IteratorImp>::IndexType<br>
>>>>>>> Dune::DefaultIndexSet<GridImp, IteratorImp>::index(const typename<br>
>>>>>>> GridImp::Codim<cd>::Entity&) const [with int cd = 0; GridImp =<br>
>>>>>>> Dune::ALU3dGrid<(Dune::ALU3dGridElementType)7u>; IteratorImp =<br>
>>>>>>> Dune::EntityIterator<0, const<br>
>>>>>>> Dune::ALU3dGrid<(Dune::ALU3dGridElementType)7u>,<br>
>>>>>>> Dune::ALU3dGridLeafIterator<0, (Dune::PartitionIteratorType)4u, <br>
>>>>>>> const<br>
>>>>>>> Dune::ALU3dGrid<(Dune::ALU3dGridElementType)7u> > >;<br>
>>>>>>> Dune::DefaultIndexSet<GridImp, IteratorImp>::IndexType = <br>
>>>>>>> unsigned int;<br>
>>>>>>> typename GridImp::Codim<cd>::Entity = Dune::Entity<0, 3, const<br>
>>>>>>> Dune::ALU3dGrid<(Dune::ALU3dGridElementType)7u>,<br>
>>>>>>> Dune::ALU3dGridEntity>]: Assertion `indexContainer( cd )[ en <br>
>>>>>>> ].index()<br>
>>>>>>> >= 0' failed.<br>
>>>>>>><br>
>>>>>>> I attach my effort, where I use a data handle copied from the<br>
>>>>>>> grid-howto. It would be great if you could take a look.<br>
>>>>>>><br>
>>>>>>> I have a second issue: I guess that I should be able to call <br>
>>>>>>> loadBalance<br>
>>>>>>> directly with a usual data handle, so that grid.hh lines 701ff <br>
>>>>>>> takes<br>
>>>>>>> care of it and packs it for me into a ALUGridLoadBalanceDataHandle<br>
>>>>>>> before sending it to the real loadBalance method. However, since <br>
>>>>>>> my data<br>
>>>>>>> handle is only inherited from CommDataHandleIF, the packing <br>
>>>>>>> routine is<br>
>>>>>>> not triggered but the real loadBalance method is called directly <br>
>>>>>>> leading<br>
>>>>>>> to a compilation error. How can I trigger the execution of the <br>
>>>>>>> packing<br>
>>>>>>> routine for such a derived data handle?<br>
>>>>>>><br>
>>>>>>> Thank you for having a look. Kind regards<br>
>>>>>>> Bernd<br>
>>>>>>><br>
>>>>>>> -- <br>
>>>>>>> _____________________________________________________________________ <br>
>>>>>>><br>
>>>>>>><br>
>>>>>>> Bernd Flemisch phone: +49 711 685 69162<br>
>>>>>>> IWS, Universität Stuttgart fax: +49 711 685 60430<br>
>>>>>>> Pfaffenwaldring 61 email: bernd@iws.uni-stuttgart.de<br>
>>>>>>> D-70569 Stuttgart url:<br>
>>>>>>> <a href=" ">www.hydrosys.uni-stuttgart.de<http://www.hydrosys.uni-stuttgart.de</a>><br>
>>>>>>> _____________________________________________________________________ <br>
>>>>>>><br>
>>>>>><br>
>>>>>><br>
>>>>>><br>
>>>>>><br>
>>>>>> _______________________________________________<br>
>>>>>> Dune mailing list<br>
>>>>>> Dune@dune-project.org<br>
>>>>>> <a href="http://lists.dune-project.org/mailman/listinfo/dune" target="_BLANK">
http://lists.dune-project.org/mailman/listinfo/dune</a><br>
>>>>><br>
>>>>> -- <br>
>>>>> Dr. Martin Nolte <nolte@mathematik.uni-freiburg.de><br>
>>>>><br>
>>>>> Universität Freiburg phone: <br>
>>>>> +49-761-203-5630<br>
>>>>> Abteilung für angewandte Mathematik fax: <br>
>>>>> +49-761-203-5632<br>
>>>>> Hermann-Herder-Straße 10<br>
>>>>> 79104 Freiburg, Germany<br>
>>>>><br>
>>>>> _______________________________________________<br>
>>>>> Dune mailing list<br>
>>>>> Dune@dune-project.org<br>
>>>>> <a href="http://lists.dune-project.org/mailman/listinfo/dune" target="_BLANK">
http://lists.dune-project.org/mailman/listinfo/dune</a><br>
>>>>><br>
>>>><br>
>>>> ___________________________________________________________<br>
>>>><br>
>>>> Bernd Flemisch phone: +49 711 685 69162<br>
>>>> IWS, Universitaet Stuttgart fax: +49 711 685 67020<br>
>>>> Pfaffenwaldring 61 email: bernd@iws.uni-stuttgart.de<br>
>>>> D-70569 Stuttgart url: <a href="http://www.hydrosys.uni-stuttgart.de" target="_BLANK">
www.hydrosys.uni-stuttgart.de</a><br>
>>>> ___________________________________________________________<br>
>>><br>
>>> ___________________________________________________________<br>
>>><br>
>>> Bernd Flemisch phone: +49 711 685 69162<br>
>>> IWS, Universitaet Stuttgart fax: +49 711 685 67020<br>
>>> Pfaffenwaldring 61 email: bernd@iws.uni-stuttgart.de<br>
>>> D-70569 Stuttgart url: <a href="http://www.hydrosys.uni-stuttgart.de" target="_BLANK">
www.hydrosys.uni-stuttgart.de</a><br>
>>> ___________________________________________________________<br>
>>><br>
>>> _______________________________________________<br>
>>> Dune mailing list<br>
>>> Dune@dune-project.org<br>
>>> <a href="http://lists.dune-project.org/mailman/listinfo/dune" target="_BLANK">
http://lists.dune-project.org/mailman/listinfo/dune</a><br>
>><br>
>> ___________________________________________________________<br>
>><br>
>> Bernd Flemisch phone: +49 711 685 69162<br>
>> IWS, Universitaet Stuttgart fax: +49 711 685 67020<br>
>> Pfaffenwaldring 61 email: bernd@iws.uni-stuttgart.de<br>
>> D-70569 Stuttgart url: <a href="http://www.hydrosys.uni-stuttgart.de" target="_BLANK">
www.hydrosys.uni-stuttgart.de</a><br>
>> ___________________________________________________________<br>
>><br>
>><br>
>> _______________________________________________<br>
>> Dune mailing list<br>
>> Dune@dune-project.org<br>
>> <a href="http://lists.dune-project.org/mailman/listinfo/dune" target="_BLANK">
http://lists.dune-project.org/mailman/listinfo/dune</a><br>
>><br>
><br>
<br>
<br>
-- <br>
_____________________________________________________________________<br>
<br>
Bernd Flemisch phone: +49 711 685 69162<br>
IWS, Universität Stuttgart fax: +49 711 685 60430<br>
Pfaffenwaldring 61 email: bernd@iws.uni-stuttgart.de<br>
D-70569 Stuttgart url: <a href="http://www.hydrosys.uni-stuttgart.de" target="_BLANK">
www.hydrosys.uni-stuttgart.de</a><br>
_____________________________________________________________________<br>
<br>
<br>
_______________________________________________<br>
Dune mailing list<br>
Dune@dune-project.org<br>
<a href="http://lists.dune-project.org/mailman/listinfo/dune" target="_BLANK">http://lists.dune-project.org/mailman/listinfo/dune</a><br>
<br>
</div>
</span></font>
</body>
</html>