# PhasicFlow: src/phasicFlow/Kokkos/baseAlgorithms_.hpp Source File
PhasicFlow is an open-source parallel DEM (discrete element method) package for simulating granular flow. It is developed in C++ and can be exectued on both GPU (like CUDA) and CPU.

baseAlgorithms_.hpp
Go to the documentation of this file.
/*------------------------------- phasicFlow ---------------------------------
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-----------------------------------------------------------------------------*/
#ifndef __baseAlgorithms_hpp__
#define __baseAlgorithms_hpp__
#include "KokkosUtilities.hpp"
#include "numericConstants.hpp"
inline const size_t sizeToSerial__ = 64;
namespace pFlow
{
// counts the number of elements that matches val
// the execution space is selected based on the View::execution_spcae
/*template<typename T, typename... properties>
INLINE_FUNCTION_H
size_t count(
const ViewType1D<T, properties...>& view,
size_t start,
size_t end,
const T& val
)
{
auto RP = Kokkos::RangePolicy<
Kokkos::IndexType<size_t>,
typename ViewType1D<T, properties...>::execution_space >(start, end);
size_t totalNum=0;
Kokkos::parallel_reduce(
"baseAlgorithms-count",
RP,
LAMBDA_HD(label i, size_t & valueToUpdate){
if( equal(view[i], val) ) valueToUpdate += 1;
}, totalNum );
return totalNum;
}*/
template<typename T, typename... properties>
INLINE_FUNCTION_H T
min(const ViewType1D<T, properties...>& view, size_t start, size_t end)
{
T minValue = largestPositive<T>();
auto RP = Kokkos::RangePolicy<
Kokkos::IndexType<size_t>,
typename ViewType1D<T, properties...>::execution_space>(start, end);
Kokkos::parallel_reduce(
"baseAlgorithms-min",
RP,
LAMBDA_HD(label i, T & valueToUpdate) {
valueToUpdate = min(view[i], valueToUpdate);
},
Kokkos ::Min<T>(minValue)
);
return minValue;
}
template<typename T, typename... properties>
INLINE_FUNCTION_H T
max(const ViewType1D<T, properties...>& view, size_t start, size_t end)
{
T maxValue = largestNegative<T>();
auto RP = Kokkos::RangePolicy<
Kokkos::IndexType<size_t>,
typename ViewType1D<T, properties...>::execution_space>(start, end);
Kokkos::parallel_reduce(
"baseAlgorithms-max",
RP,
LAMBDA_HD(label i, T & valueToUpdate) {
valueToUpdate = max(view[i], valueToUpdate);
},
Kokkos::Max<T>(maxValue)
);
return maxValue;
}
template<typename T, typename... properties>
INLINE_FUNCTION_H T
min_serial(const ViewType1D<T, properties...>& view, size_t start, size_t end)
{
T minValue = largestPositive<T>();
for (label i = start; i < end; ++i)
{
minValue = min(minValue, view[i]);
}
return minValue;
}
template<typename T, typename... properties>
INLINE_FUNCTION_H T
max_serial(const ViewType1D<T, properties...>& view, size_t start, size_t end)
{
T maxValue = largestNegative<T>();
for (label i = start; i < end; ++i)
{
maxValue = max(maxValue, view[i]);
}
return maxValue;
}
template<typename UnaryFunction, typename T, typename... properties>
void
apply_to_each(
const ViewType1D<T, properties...>& view,
size_t start,
size_t end,
UnaryFunction func
)
{
auto RP = Kokkos::RangePolicy<
Kokkos::IndexType<size_t>,
typename ViewType1D<T, properties...>::execution_space>(start, end);
Kokkos::parallel_for(
"baseAlgorithms-for_each", RP, LAMBDA_HD(label i) { view[i] = func(i); }
);
}
template<typename T, typename... properties>
void
insertSetElementH(
ViewType1D<T, properties...>& view,
hostViewType1D<label>& selected,
T val
)
{
for (auto i = 0; i < selected.size(); ++i)
{
view[selected[i]] = val;
}
}
template<typename T, typename... properties>
void
insertSetElementH(
ViewType1D<T, properties...>& view,
hostViewType1D<label>& selected,
hostViewType1D<T>& vals
)
{
for (auto i = 0; i < selected.size(); ++i)
{
view[selected[i]] = static_cast<const T&>(vals[i]);
}
}
template<typename T, typename... properties>
void
insertSetElementD(
ViewType1D<T, properties...>& view,
deviceViewType1D<label>& selected,
T val
)
{
auto RP = Kokkos::RangePolicy<
Kokkos::IndexType<size_t>,
typename ViewType1D<T, properties...>::execution_space>(
0, selected.size()
);
Kokkos::parallel_for(
"baseAlgorithms-insertSetElementD",
RP,
LAMBDA_D(size_t i) { view[selected[i]] = val; }
);
}
template<typename T, typename... properties>
void
insertSetElementD(
ViewType1D<T, properties...>& view,
deviceViewType1D<label>& selected,
deviceViewType1D<T>& vals
)
{
auto RP = Kokkos::RangePolicy<
Kokkos::IndexType<size_t>,
typename ViewType1D<T, properties...>::execution_space>(
0, selected.size()
);
Kokkos::parallel_for(
"baseAlgorithms-insertSetElementD",
RP,
LAMBDA_D(size_t i) { view[selected[i]] = vals[i]; }
);
}
template<typename T, typename... properties>
void
fill(
ViewType3D<T, properties...>& view,
range range1,
range range2,
range range3,
T val
)
{
auto subV = Kokkos::subview(view, range1, range2, range3);
Kokkos::deep_copy(subV, val);
}
}
#endif // __VectorSingleMath_hpp__
pFlow::fill
void fill(Vector< T, Allocator > &vec, const T &val)
Definition: VectorAlgorithm.hpp:44
KokkosUtilities.hpp
sizeToSerial__
const size_t sizeToSerial__
Definition: baseAlgorithms_.hpp:27
LAMBDA_D
#define LAMBDA_D
Definition: pFlowMacros.hpp:59
pFlow::max
T max(const internalField< T, MemorySpace > &iField)
Definition: internalFieldAlgorithms.hpp:79
pFlow::deviceViewType1D
Kokkos::View< T * > deviceViewType1D
1D array (vector) with default device (memory space and execution space)
Definition: KokkosTypes.hpp:121
pFlow
Definition: demGeometry.hpp:27
pFlow::apply_to_each
void apply_to_each(const ViewType1D< T, properties... > &view, size_t start, size_t end, UnaryFunction func)
Definition: baseAlgorithms_.hpp:127
pFlow::min_serial
INLINE_FUNCTION_H T min_serial(const ViewType1D< T, properties... > &view, size_t start, size_t end)
Definition: baseAlgorithms_.hpp:103
pFlow::insertSetElementH
void insertSetElementH(ViewType1D< T, properties... > &view, hostViewType1D< label > &selected, T val)
Definition: baseAlgorithms_.hpp:145
pFlow::insertSetElementD
void insertSetElementD(ViewType1D< T, properties... > &view, deviceViewType1D< label > &selected, T val)
Definition: baseAlgorithms_.hpp:173
INLINE_FUNCTION_H
#define INLINE_FUNCTION_H
Definition: pFlowMacros.hpp:57
pFlow::min
T min(const internalField< T, MemorySpace > &iField)
Definition: internalFieldAlgorithms.hpp:28
pFlow::ViewType1D
Kokkos::View< T *, properties... > ViewType1D
1D veiw as a vector
Definition: KokkosTypes.hpp:93
pFlow::ViewType3D
Kokkos::View< T ***, properties... > ViewType3D
3D view as an array
Definition: KokkosTypes.hpp:101
pFlow::hostViewType1D
Kokkos::View< T *, Kokkos::HostSpace > hostViewType1D
1D array (vector with host memeory space)
Definition: KokkosTypes.hpp:136
pFlow::max_serial
INLINE_FUNCTION_H T max_serial(const ViewType1D< T, properties... > &view, size_t start, size_t end)
Definition: baseAlgorithms_.hpp:115
LAMBDA_HD
#define LAMBDA_HD
Definition: pFlowMacros.hpp:58
numericConstants.hpp