Skip to content
Snippets Groups Projects
Commit 4fdd94e1 authored by Markus Blatt's avatar Markus Blatt
Browse files

Added test for selection.

[[Imported from SVN: r136]]
parent 7a29bbea
No related branches found
No related tags found
No related merge requests found
......@@ -3,4 +3,5 @@ Makefile.in
.deps
.libs
semantic.cache
indicestest
\ No newline at end of file
indicestest
selectiontest
\ No newline at end of file
# $Id $
if MPI
TESTPROGS = indicestest
TESTPROGS = indicestest selectiontest
endif
# which tests to run
......@@ -17,3 +17,7 @@ indicestest_SOURCES = indicestest.cc
indicestest_CXXFLAGS = $(MPI_CPPFLAGS)
indicestest_LDFLAGS = $(MPI_LDFLAGS) $(MPI_LIBS)
selectiontest_SOURCES = selectiontest.cc
selectiontest_CXXFLAGS = $(MPI_CPPFLAGS)
selectiontest_LDFLAGS = $(MPI_LDFLAGS) $(MPI_LIBS)
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#include <iostream>
#include <dune/istl/selection.hh>
#include <dune/common/timer.hh>
#include <dune/common/enumset.hh>
#include <dune/istl/remoteindices.hh>
enum GridFlags {
owner, overlap, border
};
template<class T>
int meassure(const T& selection)
{
/*
return meassure<1>(selection);
}
template<int LOOPS, class T>
int meassure(const T& selection)
{*/
typedef typename T::const_iterator iterator;
const iterator end = selection.end();
int count=0;
Dune::Timer timer;
timer.reset();
for(int i=0; i<100; i++)
for(iterator iter = selection.begin(); iter != end; ++iter)
count+=*iter;
std::cout<<" took "<< timer.elapsed()<<" seconds"<<std::endl;
return count;
}
template<int SIZE>
void test()
{
const int Nx = SIZE;
const int Ny = SIZE;
// Process configuration
Dune::IndexSet<int,Dune::ParallelLocalIndex<GridFlags> > distIndexSet;
distIndexSet.beginResize();
for(int y=0, i=0; y < Ny; y++)
for(int x=0; x < Nx; x++, i++) {
GridFlags flag = owner;
if(x==0 || x == Nx-1 || y ==0 || y==Ny-1)
flag = overlap;
distIndexSet.add(i, Dune::ParallelLocalIndex<GridFlags> (i, flag, true));
}
distIndexSet.endResize();
Dune::UncachedSelection<Dune::EnumItem<GridFlags,owner>,int,Dune::ParallelLocalIndex<GridFlags> >
ownerUncached(distIndexSet);
Dune::Selection<Dune::EnumItem<GridFlags,owner>,int,Dune::ParallelLocalIndex<GridFlags> >
ownerCached(distIndexSet);
Dune::UncachedSelection<Dune::EnumItem<GridFlags,overlap>,int,Dune::ParallelLocalIndex<GridFlags> >
overlapUncached(distIndexSet);
Dune::Selection<Dune::EnumItem<GridFlags,overlap>,int,Dune::ParallelLocalIndex<GridFlags> >
overlapCached(distIndexSet);
int count=0;
std::cout<<" Owner selection uncached:";
count+=meassure(ownerUncached);
std::cout<<" Owner selection cached:";
count+=meassure(ownerCached);
std::cout<<" Overlap selection uncached:";
count+=meassure(overlapUncached);
std::cout<<" Overlap selection cached:";
count+=meassure(overlapCached);
std::cout<<count<<std::endl;
}
int main()
{
test<1000>();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment