From 6b4bd3147f5d0565cd62bdc3200077f4aa5c606f Mon Sep 17 00:00:00 2001 From: turcksin Date: Wed, 4 Dec 2013 02:57:48 +0000 Subject: [PATCH] Start ParalutionWrappers::Vector. git-svn-id: https://svn.dealii.org/branches/branch_paralution@31867 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/include/deal.II/base/config.h.in | 10 + .../include/deal.II/lac/paralution_vector.h | 450 ++++++++++++++++++ .../deal.II/lac/trilinos_vector_base.h | 2 +- 3 files changed, 461 insertions(+), 1 deletion(-) create mode 100644 deal.II/include/deal.II/lac/paralution_vector.h diff --git a/deal.II/include/deal.II/base/config.h.in b/deal.II/include/deal.II/base/config.h.in index 571abc27f3..47734d539d 100644 --- a/deal.II/include/deal.II/base/config.h.in +++ b/deal.II/include/deal.II/base/config.h.in @@ -507,6 +507,16 @@ #endif +/********************************************** + * Configured in configure_paralution.cmake: * + **********************************************/ + +#cmakedefine DEAL_II_WITH_PARALUTION +#ifdef DEAL_II_WITH_PARALUTION +# define DEAL_II_USE_PARALUTION +#endif + + #include #include diff --git a/deal.II/include/deal.II/lac/paralution_vector.h b/deal.II/include/deal.II/lac/paralution_vector.h new file mode 100644 index 0000000000..aa106ef1fe --- /dev/null +++ b/deal.II/include/deal.II/lac/paralution_vector.h @@ -0,0 +1,450 @@ +// --------------------------------------------------------------------- +// $Id: paralution_vector.h 30040 2013-07-18 17:06:48Z maier $ +// +// Copyright (C) 2013 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + +#ifndef __deal2__paralution_vector_h +#define __deal2__paralution_vector_h + +#include + +#ifdef DEAL_II_WITH_PARALUTION + +#include +#include + +#include "paralution.hpp" +#include "base/local_vector.hpp" + +DEAL_II_NAMESPACE_OPEN + +/** + * @addtogroup ParalutionWrappers + *@{ + */ +namespace ParalutionWrappers +{ + /** + * This class is a wrapper around the Paralution localized vector. This kind + * of vector is designed for use in either serial implementation or as a + * localized copy on each processor. The implementation of this class is + * based on the Paralution vector class LocalVector. The only requirement + * for this class to work is that Trilinos is installed with the same + * compiler as is used for compilation of deal.II. + * + * The interface of this class is modeled after the existing Vector class in + * deal.II. It has almost the same member functions, and is often + * exchangeable. However, Paralution LocalVector only supports int, float, + * and double. + * + * @ingroup ParalutionWrappers + * @ingroup Vectors + * @author Bruno Turcksin, 2013 + */ + //TODO: lots of functions are missing + template + class Vector : public Subscriptor + { + public : + /** + * Declare some the standard types used in all containers. These types + * parallel those in the C standard libraries + * vector<...> class. + */ + typedef dealii::types::global_dof_index size_type; + typedef Number* iterator; + typedef const Number* const_iterator; + + /** + * @name 1: Basic Object-handling + */ + //@{ + + /** + * Default constructor that generates and empy (zero size) vector. The + * function reinit() will have to give the vector the correct + * size. + */ + Vector(); + + /** + * Copy constructor. Sets the dimension to that of the given vector, and + * copies all the elements. The copied vector stays on the host/device + * where it is create. + */ + //TODO: Look to use choose between CopyFrom and Clone. Difference between + //copy and clone: copy the vector stays on his host/device, with clone + //the vector goes on the same host/device. + Vector(const Vector &v); + + /** + * Constructor. Set dimensionto @p n and initialize all the elements + * with zero. + * + * The constructor is made explicit to avoid accidents like this: + * v=0;. Presumably, the user want to set every element of the + * vector to zero, but instead, what happens is this call: + * v=Vector@(0);, i.e. the vector is replaced by one + * length zero. + */ + explicit Vector(const size_type n); + + /** + * Initialize the vector with a given range of values pointed to by the + * iterators. This function is there in anlogy to the @p std::vector + * class. + */ + //TODO + // template + // Vector (const InputIterator first, + // const InputIterator last); + + /** + * Destructor. + */ + ~Vector(); + + /** + * Change the dimension of the vector to @p N. The vector is filled with + * zeros. + */ + //TODO look to add fast + void reinit(const size_type N); + + /** + * Return dimension of the vector. + */ + std::size_t size() const; + + /** + * Make the @p Vector class a bit loke the vector<> class of + * the C++ standard library by returning iterators to the strat and end + * of the elements of this vector. The iterator is created on the host + * or the device and cannot be moved. + */ + iterator begin(); + + /** + * Return constant iterator to the start of the vectors. The iterator is + * created on the host of the device and cannot be moved. + */ + const_iterator begin() const; + + /** + * Return an iterator pointing to the element past the end of the array. + * The iterator is created on the host or the device and cannot be + * moved. + */ + iterator end(); + + /** + * Return a constant iterator pointing to the element past the end of + * the array. The iterator is created on the host or the device and + * cannot be moved. + */ + const_iterator end() const; + //@} + + /** + * @name 2: Data-Acess + */ + //@{ + /** + * Access the value of the @p ith component. Works only on the host. + */ + Number operator() (const size_type i) const; + + /** + * Access the @p ith component as writeable reference. Works only on the + * host. + */ + Number& operator() (const size_type i); + + /** + * Access the value of the @p ith component. Works only on the host. + * + * Exactly the same as operator(). + */ + Number operator[] (const size_type i) const; + + /** + * Access the @p ith component as a writeable reference. + * + * Exactly thte asame as operator(). + */ + Number& operator[] (const size_type i); + + /** + * Return a constant reference to the underlying Paralution LocalVector + * class. + */ + const paralution::LocalVector& paralution_vector() const; + + /** + * Return a (modifyable) reference to the underlying Paralution + * LocalVector class. + */ + paralution::LocalVector& paralution_vector(); + //@} + + /** + * @name 3: Modification of vectors + */ + //@{ + /** + * Add the given vector to the present one. + */ + Vector& operator+= (const Vector &v); + + /** + * Substract the given vector from the present one. + */ + Vector& operator-= (const Vector &v); + + /** + * Addition of @p s to all components. Note that @p s is a scalar and + * not a vector. + */ + void add(const Number s); + + /** + * Scale each element of the vector by a constant value. + */ + Vector& operator*= (const Number factor); + + /** + * Scale each element of the vector by the inverse of the given value. + */ + Vector& operator/= (const Number factor); + //@} + + private : + /** + * Underlying Paralution LocalVector. + */ + paralution::LocalVector local_vector; + }; + + + + +// ------------------- inline functions -------------- + + template + inline Vector::Vector() {} + + + + template + inline Vector::Vector(const Vector &v) + { + local_vector.CopyFrom(v.paralution_vector()); + } + + + + template + inline Vector::Vector(const size_type n) + { + local_vector.Allocate("deal_ii_vector",n); + } + + + + template + inline Vector::~Vector() + { + local_vector.Clear(); + } + + + + template + void Vector::reinit(const size_type n) + { + local_vector.Clear(); + local_vector.Allocate("deal_ii_vector",n); + } + + + + template + inline size_type Vector::size() const + { + return static_cast(local_vector.get_size()); + } + + + + template + inline typename Vector::iterator Vector::begin() + { + return &(local_vector[0]); + } + + + + template + inline typename Vector::const_iterator Vector::begin() const + { + return &(local_vector[0]); + } + + + + template + inline typename Vector::iterator Vector::end() + { + return &(local_vector[0])+local_vector.get_size(); + } + + + + template + inline typename Vector::const_iterator Vector::end() const + { + return &(local_vector[0])+local_vector.get_size(); + } + + + + template + inline Number Vector::operator() (const size_type i) const + { + AssertIndexRange(i,static_cast(local_vector.get_size())); + + return local_vector[i]; + } + + + + template + inline Number& Vector::operator() (const size_type i) + { + AssertIndexRange(i,static_cast(local_vector.get_size())); + + return local_vector[i]; + } + + + + template + inline Number Vector::operator[] (const size_type i) const + { + AssertIndexRange(i,static_cast(local_vector.get_size())); + + return local_vector[i]; + } + + + + template + inline Number& Vector::operator[] (const size_type i) + { + AssertIndexRange(i,static_cast(local_vector.get_size())); + + return local_vector[i]; + } + + + + template + inline paralution::LocalVector const& Vector::paralution_vector() const + { + return local_vector; + } + + + + template + inline paralution::LocalVector& Vector::paralution_vector() + { + return local_vector; + } + + + + template + inline Vector& Vector::operator+= (Vector const &v) + { + Assert(size()==v.size(),ExcDimensionMismatch(size(),v.size())); + + local_vector.ScaleAdd(1.,v.paralution_vector()); + + return *this; + } + + + + template + inline Vector& Vector::operator-= (Vector const &v) + { + Assert(size()==v.size(),ExcDimensionMismatch(size(),v.size())); + + local_vector.ScaleAdd(-1.,v.paralution_vector()); + + return *this; + } + + + + template + inline void Vector::add(const Number s) + { + Assert(Numbers::is_finite(s),ExcNumberNotFinite()); + + size_type size = local_vector.get_size(); + for (size_type i=0; i + inline Vector& Vector::operator*= (const Number factor) + { + Assert(Numbers::is_finite(factor),ExcNumberNotFinite()); + + local_vector.Scale(factor); + + return *this; + } + + + + template + inline Vector& Vector::operator/= (const Number factor) + { + Assert(Numbers::is_finite(factor),ExcNumberNotFinite()); + + const Number inv_factor(1./factor); + + Assert(Numbers::is_finite(inv_factor),ExcNumberNotFinite()); + + local_vector.Scale(inv_factor); + + return *this; + } +} + +/*@}*/ + +DEAL_II_NAMESPACE_CLOSE + +#endif // DEAL_II_WITH_PARALUTION + +/*---------------------------- paralution_vector.h ---------------------------*/ + +#endif +/*---------------------------- paralution_vector.h ---------------------------*/ diff --git a/deal.II/include/deal.II/lac/trilinos_vector_base.h b/deal.II/include/deal.II/lac/trilinos_vector_base.h index d5e2217ad9..3c7ddb4ead 100644 --- a/deal.II/include/deal.II/lac/trilinos_vector_base.h +++ b/deal.II/include/deal.II/lac/trilinos_vector_base.h @@ -253,7 +253,7 @@ namespace TrilinosWrappers * * The interface of this class is modeled after the existing Vector * class in deal.II. It has almost the same member functions, and is - * often exchangable. However, since Trilinos only supports a single + * often exchangeable. However, since Trilinos only supports a single * scalar type (double), it is not templated, and only works with that * type. * -- 2.39.5