2 #ifndef DUNE_INTERFACE_HH
3 #define DUNE_INTERFACE_HH
84 template<
class R,
class T1,
class T2,
class Op,
bool send>
86 const T1& sourceFlags,
const T2& destFlags,
133 indices_ =
new std::size_t[
size];
151 void add(std::size_t index)
153 assert(size_<maxSize_);
154 indices_[size_++]=index;
158 : size_(0), maxSize_(0), indices_(0)
174 for(std::size_t i=0; i< size_; ++i)
175 if(indices_[i]!=o.indices_[i])
192 std::size_t* indices_;
230 template<
typename R,
typename T1,
typename T2>
231 void build(
const R& remoteIndices,
const T1& sourceFlags,
232 const T2& destFlags);
276 if(interfaces_.size()!=o.interfaces_.size())
278 typedef InformationMap::const_iterator MIter;
280 for(MIter m=interfaces_.begin(), om=o.interfaces_.begin();
281 m!=interfaces_.end(); ++m, ++om)
283 if(om->first!=m->first)
285 if(om->second.first!=om->second.first)
287 if(om->second.second!=om->second.second)
325 class InformationBuilder
329 : interfaces_(interfaces)
332 void reserve(
int proc,
int size)
335 interfaces_[proc].first.reserve(size);
337 interfaces_[proc].second.reserve(size);
339 void add(
int proc, std::size_t local)
342 interfaces_[proc].first.add(local);
344 interfaces_[proc].second.add(local);
353 template<
class R,
class T1,
class T2,
class Op,
bool send>
357 if(!remoteIndices.isSynced())
361 typedef typename RemoteIndices::RemoteIndexMap::const_iterator const_iterator;
363 const const_iterator end=remoteIndices.
end();
367 MPI_Comm_rank(remoteIndices.communicator(), &rank);
370 for(const_iterator process=remoteIndices.begin(); process != end; ++process){
374 const RemoteIterator remoteEnd = send ? process->second.first->end() :
375 process->second.second->end();
376 RemoteIterator remote = send ? process->second.first->begin() : process->second.second->begin();
378 while(remote!=remoteEnd){
379 if( send ? destFlags.contains(remote->attribute()) :
380 sourceFlags.contains(remote->attribute())){
383 if( send ? sourceFlags.contains(remote->localIndexPair().local().attribute()) :
384 destFlags.contains(remote->localIndexPair().local().attribute()))
389 interfaceInformation.reserve(process->first, size);
394 for(const_iterator process=remoteIndices.begin(); process != end; ++process){
396 const RemoteIterator remoteEnd = send ? process->second.first->end() :
397 process->second.second->end();
398 RemoteIterator remote = send ? process->second.first->begin() : process->second.second->begin();
400 while(remote!=remoteEnd){
401 if( send ? destFlags.contains(remote->attribute()) :
402 sourceFlags.contains(remote->attribute())){
404 if( send ? sourceFlags.contains(remote->localIndexPair().local().attribute()) :
405 destFlags.contains(remote->localIndexPair().local().attribute()))
406 interfaceInformation.add(process->first,remote->localIndexPair().local().local());
432 typedef InformationMap::const_iterator const_iterator;
433 const const_iterator end=interfaces_.end();
437 for(const_iterator infoPair=interfaces_.begin(); infoPair!=end; ++infoPair){
439 std::cout<<rank<<
": send for process "<<infoPair->first<<
": ";
441 for(
size_t i=0; i < info.
size(); i++)
442 std::cout<<info[i]<<
" ";
443 std::cout<<std::endl;
446 std::cout<<rank<<
": receive for process "<<infoPair->first<<
": ";
448 for(
size_t i=0; i < info.
size(); i++)
449 std::cout<<info[i]<<
" ";
450 std::cout<<std::endl;
456 template<
typename R,
typename T1,
typename T2>
462 assert(interfaces_.empty());
465 InformationBuilder<true> sendInformation(interfaces_);
466 this->
template buildInterface<R,T1,T2,InformationBuilder<true>,
true>(remoteIndices, sourceFlags,
467 destFlags, sendInformation);
470 InformationBuilder<false> recvInformation(interfaces_);
471 this->
template buildInterface<R,T1,T2,InformationBuilder<false>,
false>(remoteIndices,sourceFlags,
472 destFlags, recvInformation);
477 typedef InformationMap::iterator const_iterator;
478 for(const_iterator interfacePair = interfaces_.begin(); interfacePair != interfaces_.end();)
479 if(interfacePair->second.first.size()==0 && interfacePair->second.second.size()==0){
480 interfacePair->second.first.free();
481 interfacePair->second.second.free();
482 const_iterator toerase=interfacePair++;
483 interfaces_.erase(toerase);
490 typedef InformationMap::iterator iterator;
491 typedef InformationMap::const_iterator const_iterator;
492 const const_iterator end = interfaces_.end();
493 for(iterator interfacePair = interfaces_.begin(); interfacePair != end; ++interfacePair){
494 interfacePair->second.first.free();
495 interfacePair->second.second.free();
512 typedef InfoMap::const_iterator Iter;
516 os<<i->first<<
": [ source=[";
517 for(std::size_t j=0; j < i->second.first.size(); ++j)
518 os<<i->second.first[j]<<
" ";
519 os<<
"] size="<<i->second.first.size()<<
", target=[";
520 for(std::size_t j=0; j < i->second.second.size(); ++j)
521 os<<i->second.second[j]<<
" ";
522 os<<
"] size="<<i->second.second.size()<<
"\n";