Page MenuHomec4science

loop_utils.hh
No OneTemporary

File Metadata

Created
Thu, May 9, 10:58

loop_utils.hh

/**
* @file
*
* @author Lucas Frérot <lucas.frerot@epfl.ch>
*
* @section LICENSE
*
* Copyright (©) 2017 EPFL (Ecole Polytechnique Fédérale de
* Lausanne) Laboratory (LSMS - Laboratoire de Simulation en Mécanique des
* Solides)
*
* Tamaas is free software: you can 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 3 of the License, or (at your option) any
* later version.
*
* Tamaas is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Tamaas. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* -------------------------------------------------------------------------- */
#ifndef __LOOP_UTILS_HH__
#define __LOOP_UTILS_HH__
/* -------------------------------------------------------------------------- */
#include "loop.hh"
#include "tamaas.hh"
#include <thrust/functional.h>
#include <limits>
#include <type_traits>
/* -------------------------------------------------------------------------- */
__BEGIN_TAMAAS__
namespace detail {
template <bool only_points = false, typename... Grids>
UInt loopSize(Grids&&... grids) {
return (only_points)
? std::get<0>(std::forward_as_tuple(grids...)).getNbPoints()
: std::get<0>(std::forward_as_tuple(grids...)).dataSize();
}
template <operation op, typename ReturnType>
struct reduction_helper;
template <typename ReturnType>
struct reduction_helper<operation::plus, ReturnType>
: public thrust::plus<ReturnType> {
ReturnType init() const {
return ReturnType(0);
}
};
template <typename ReturnType>
struct reduction_helper<operation::times, ReturnType>
: public thrust::multiplies<ReturnType> {
ReturnType init() const {
return ReturnType(1);
}
};
template <typename ReturnType>
struct reduction_helper<operation::min, ReturnType>
: public thrust::minimum<ReturnType> {
ReturnType init() const {
return std::numeric_limits<ReturnType>::max();
}
};
template <typename ReturnType>
struct reduction_helper<operation::max, ReturnType>
: public thrust::maximum<ReturnType> {
ReturnType init() const {
return std::numeric_limits<ReturnType>::lowest();
}
};
} // namespace detail
__END_TAMAAS__
#endif // __LOOP_UTILS_HH

Event Timeline