From 4fdd94e12c22a19bf99e3609778a84789a227c91 Mon Sep 17 00:00:00 2001 From: Markus Blatt <mblatt@dune-project.org> Date: Wed, 12 Jan 2005 12:33:07 +0000 Subject: [PATCH] Added test for selection. [[Imported from SVN: r136]] --- istl/test/.gitignore | 3 +- istl/test/Makefile.am | 6 ++- istl/test/selectiontest.cc | 89 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 istl/test/selectiontest.cc diff --git a/istl/test/.gitignore b/istl/test/.gitignore index 77477583b..c87b3d422 100644 --- a/istl/test/.gitignore +++ b/istl/test/.gitignore @@ -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 diff --git a/istl/test/Makefile.am b/istl/test/Makefile.am index 946c92a08..aa62cb3f6 100644 --- a/istl/test/Makefile.am +++ b/istl/test/Makefile.am @@ -1,7 +1,7 @@ # $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) diff --git a/istl/test/selectiontest.cc b/istl/test/selectiontest.cc new file mode 100644 index 000000000..cb5824bcd --- /dev/null +++ b/istl/test/selectiontest.cc @@ -0,0 +1,89 @@ +// -*- 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>(); +} -- GitLab