Skip to content
Snippets Groups Projects
Commit a9561274 authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Improve NodeByCellData class

- performances seem correct
- use connectivity to access data
parent dc65a299
Branches
Tags
1 merge request!6Feature/crs
......@@ -86,86 +86,24 @@ private:
const Kokkos::View<const double**>& ljr,
const Kokkos::View<const Rd**>& njr)
{
int cpt0 = 0;
Kokkos::parallel_for("T new Ajr (raw vector)", m_Ajr_new.numberOfValues(), [&](const int& j) {
m_Ajr_new.value(j) = tensorProduct(Rd(zero), Rd(zero));
cpt0 ++;
});
int cpt1 = 0;
Kokkos::parallel_for("T new Ajr", m_mesh.numberOfCells(), [&](const int& j) {
auto Aj = m_Ajr_new.myCellValues(j);
const size_t nb_nodes = Aj.size();
for (size_t r=0; r<nb_nodes; ++r) {
Aj[r] = tensorProduct(Rd(zero), Rd(zero));
cpt1++;
}
});
const Kokkos::View<const Rd**> Cjr = m_mesh_data.Cjr();
int cpt2 = 0;
Kokkos::parallel_for("T old Ajr", m_mesh.numberOfCells(), [&](const int& j) {
Kokkos::parallel_for("old Ajr", m_mesh.numberOfCells(), KOKKOS_LAMBDA(const int& j) {
const auto& cell_nodes = m_mesh.connectivity().m_cell_to_node_matrix.rowConst(j);
const double& rho_c = rhocj(j);
for (size_t r=0; r<cell_nodes.length; ++r) {
m_Ajr(j,r) = tensorProduct(Rd(zero), Rd(zero));
cpt2++;
m_Ajr(j,r) = tensorProduct(rho_c*Cjr(j,r), njr(j,r));
}
});
int cpt3 = 0;
Kokkos::parallel_for("new Ajr", m_mesh.numberOfCells(), [&](const int& j) {
auto Aj = m_Ajr_new.myCellValues(j);
const size_t nb_nodes = Aj.size();
Kokkos::parallel_for("new nested Ajr", m_mesh.numberOfCells(), KOKKOS_LAMBDA(const int& j) {
const size_t& nb_nodes =m_Ajr_new.numberOfSubValues(j);
const double& rho_c = rhocj(j);
for (size_t r=0; r<nb_nodes; ++r) {
Aj[r] = tensorProduct((rhocj(j)*ljr(j,r))*njr(j,r), njr(j,r));
cpt3++;
}
});
int cpt4 = 0;
Kokkos::parallel_for("old Ajr", m_mesh.numberOfCells(), [&](const int& j) {
const auto& cell_nodes = m_mesh.connectivity().m_cell_to_node_matrix.rowConst(j);
for (size_t r=0; r<cell_nodes.length; ++r) {
m_Ajr(j,r) = tensorProduct((rhocj(j)*ljr(j,r))*njr(j,r), njr(j,r));
cpt4++;
}
});
int cpt5 = 0;
Kokkos::View<Rdd*> simple_view("simpleview", m_Ajr_new.numberOfValues());
Kokkos::parallel_for("T new Ajr (simple View)", simple_view.extent(0), [&](const int& j) {
simple_view(j) = tensorProduct(Rd(zero), Rd(zero));
cpt5 ++;
});
Kokkos::View<unsigned int*> shift ("shift", m_mesh.numberOfCells());
shift(0)=0;
for (unsigned int j=1; j<m_mesh.numberOfCells(); ++j) {
shift[j] = shift[j-1]+m_mesh.connectivity().m_cell_to_node_matrix.rowConst(j-1).length;
}
int cpt6 = 0;
Kokkos::View<Rdd*> simple_view2("simpleview2", m_Ajr_new.numberOfValues());
Kokkos::parallel_for("T new Ajr (simple View2)", m_mesh.numberOfCells(),
[&] (const int& j) {
for (unsigned r=0; r<m_mesh.connectivity().m_cell_to_node_matrix.rowConst(j).length; ++r) {
simple_view2(shift[j]+r) = tensorProduct(Rd(zero), Rd(zero));
cpt6 ++;
m_Ajr_new(j,r) = tensorProduct(rho_c*Cjr(j,r), njr(j,r));
}
});
std::cout << cpt0 << ' ' << cpt1 << ' ' << cpt2 << ' ' << cpt3 << ' ' << cpt4 << ' ' << cpt5 << ' ' << cpt6 << '\n';
// for (unsigned int j=0; j<m_mesh.numberOfCells(); ++j) {
// const auto& Aj = m_Ajr_new.cellValues(j);
// const auto& cell_nodes = m_mesh.connectivity().m_cell_to_node_matrix.rowConst(j);
// for (size_t r=0; r<<cell_nodes.length; ++r) {
// if (Aj[r] != m_Ajr(j,r)) {
// std::cerr << "viens !\n";
// }
// }
// }
return m_Ajr;
}
......
......@@ -12,117 +12,107 @@ class NodeByCellData
private:
ConnectivityMatrix m_node_id_per_cell_matrix;
Kokkos::View<unsigned int*> m_begin;
Kokkos::View<unsigned int*> m_end;
Kokkos::View<DataType*> m_values;
public:
class SubView
{
private:
DataType* const m_values;
KOKKOS_RESTRICT DataType* const m_sub_values;
const size_t m_size;
public:
KOKKOS_FORCEINLINE_FUNCTION
KOKKOS_INLINE_FUNCTION
const DataType& operator[](const size_t& i) const
{
return m_values[i];
Assert(i<m_size);
return m_sub_values[i];
}
KOKKOS_FORCEINLINE_FUNCTION
KOKKOS_INLINE_FUNCTION
DataType& operator[](const size_t& i)
{
return m_values[i];
Assert(i<m_size);
return m_sub_values[i];
}
KOKKOS_FORCEINLINE_FUNCTION
KOKKOS_INLINE_FUNCTION
const size_t& size() const
{
return m_size;
}
KOKKOS_FORCEINLINE_FUNCTION
SubView(const SubView&) = delete;
KOKKOS_FORCEINLINE_FUNCTION
KOKKOS_INLINE_FUNCTION
SubView(SubView&&) = default;
KOKKOS_FORCEINLINE_FUNCTION
SubView(Kokkos::View<DataType*> values,
const unsigned int& begin,
const unsigned int& end)
: m_values(&(values[begin])),
KOKKOS_INLINE_FUNCTION
SubView(const Kokkos::View<DataType*>& values,
const size_t& begin,
const size_t& end)
: m_sub_values(&(values[begin])),
m_size(end-begin)
{
Assert(begin<=end);
Assert(end<=values.extent(0));
}
};
KOKKOS_FORCEINLINE_FUNCTION
KOKKOS_INLINE_FUNCTION
DataType& operator()(const size_t& j, const size_t& r)
{
return m_values[m_node_id_per_cell_matrix.row_map[j]+r];
}
KOKKOS_INLINE_FUNCTION
const DataType& operator()(const size_t& j, const size_t& r) const
{
return m_values[m_node_id_per_cell_matrix.row_map[j]+r];
}
KOKKOS_INLINE_FUNCTION
size_t numberOfValues() const
{
return m_values.extent(0);
}
KOKKOS_FORCEINLINE_FUNCTION
KOKKOS_INLINE_FUNCTION
DataType& value(const size_t& i)
{
return m_values[i];
}
KOKKOS_FORCEINLINE_FUNCTION
KOKKOS_INLINE_FUNCTION
const DataType& value(const size_t & i) const
{
return m_values[i];
}
KOKKOS_FORCEINLINE_FUNCTION
KOKKOS_INLINE_FUNCTION
size_t numberOfEntities() const
{
return m_node_id_per_cell_matrix.numRows();
}
KOKKOS_FORCEINLINE_FUNCTION
SubView&& myCellValues(const size_t& i_cell)
KOKKOS_INLINE_FUNCTION
size_t numberOfSubValues(const size_t& i_cell) const
{
ConnectivityMatrix::size_type cell_begin = m_begin[i_cell];
ConnectivityMatrix::size_type cell_end = m_begin[i_cell+1];
return std::move(SubView(m_values, cell_begin, cell_end));
return m_node_id_per_cell_matrix.row_map[i_cell+1]-m_node_id_per_cell_matrix.row_map[i_cell];
}
KOKKOS_FORCEINLINE_FUNCTION
Kokkos::View<DataType*>
cellValues(const size_t& i_cell)
KOKKOS_INLINE_FUNCTION
SubView cellValues(const size_t& i_cell)
{
ConnectivityMatrix::size_type cell_begin = m_begin[i_cell];
ConnectivityMatrix::size_type cell_end = m_begin[i_cell+1];
// ConnectivityMatrix::size_type cell_begin = m_node_id_per_cell_matrix.row_map(i_cell);
// ConnectivityMatrix::size_type cell_end = m_node_id_per_cell_matrix.row_map(i_cell+1);
return Kokkos::subview(m_values, std::make_pair(cell_begin, cell_end));
}
KOKKOS_FORCEINLINE_FUNCTION
Kokkos::View<const DataType*>
cellValues(const size_t& i_cell) const
{
ConnectivityMatrix::size_type cell_begin = m_begin[i_cell];
ConnectivityMatrix::size_type cell_end = m_end[i_cell+1];
// ConnectivityMatrix::size_type cell_begin = m_node_id_per_cell_matrix.row_map(i_cell);
// ConnectivityMatrix::size_type cell_end = m_node_id_per_cell_matrix.row_map(i_cell+1);
return Kokkos::subview(m_values, std::make_pair(cell_begin, cell_end));
const ConnectivityMatrix::size_type& cell_begin = m_node_id_per_cell_matrix.row_map[i_cell];
const ConnectivityMatrix::size_type& cell_end = m_node_id_per_cell_matrix.row_map[i_cell+1];
return SubView(m_values, cell_begin, cell_end);
}
NodeByCellData(const ConnectivityMatrix& node_id_per_cell_matrix)
: m_node_id_per_cell_matrix(node_id_per_cell_matrix),
m_begin("begin", m_node_id_per_cell_matrix.numRows()+1),
// m_end("end", m_node_id_per_cell_matrix.numRows()),
m_values("values", m_node_id_per_cell_matrix.entries.extent(0))
{
for (unsigned int j=0; j<m_node_id_per_cell_matrix.numRows()+1; ++j) {
m_begin[j] = m_node_id_per_cell_matrix.row_map(j);
// m_end[j] = m_node_id_per_cell_matrix.row_map(j+1);
}
;
}
~NodeByCellData() = default;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment