# include <deal.II/lac/la_parallel_block_vector.h>
# include <deal.II/lac/la_parallel_vector.h>
# include <deal.II/lac/la_vector.h>
+# include <deal.II/lac/petsc_block_vector.h>
+# include <deal.II/lac/petsc_vector.h>
# include <deal.II/lac/trilinos_parallel_block_vector.h>
# include <deal.II/lac/trilinos_vector.h>
# include <deal.II/lac/vector_memory.h>
realtype
SUNDIALS::internal::NVectorOperations::min_element(N_Vector x)
{
- auto * vector = unwrap_nvector_const<VectorType>(x);
- const auto local_min = *std::min_element(vector->begin(), vector->end());
- return Utilities::MPI::min(local_min, get_communicator<VectorType>(x));
+ auto *vector = unwrap_nvector_const<VectorType>(x);
+
+
+ const auto indexed_less_than = [&](const IndexSet::size_type idxa,
+ const IndexSet::size_type idxb) {
+ return (*vector)[idxa] < (*vector)[idxb];
+ };
+
+ auto local_elements = vector->locally_owned_elements();
+
+ const auto local_min = *std::min_element(local_elements.begin(),
+ local_elements.end(),
+ indexed_less_than);
+ return Utilities::MPI::min((*vector)[local_min],
+ get_communicator<VectorType>(x));
}
for (unsigned i = 0; i < vector->n_blocks(); ++i)
{
+ const auto indexed_less_than = [&](const IndexSet::size_type idxa,
+ const IndexSet::size_type idxb) {
+ return vector->block(i)[idxa] < vector->block(i)[idxb];
+ };
+
+ auto local_elements = vector->block(i).locally_owned_elements();
+
const auto block_local_min_element =
- std::min_element(vector->block(i).begin(), vector->block(i).end());
+ std::min_element(local_elements.begin(),
+ local_elements.end(),
+ indexed_less_than);
// guard against empty blocks on this processor
- if (block_local_min_element != vector->block(i).end())
- proc_local_min = std::min(proc_local_min, *block_local_min_element);
+ if (block_local_min_element != local_elements.end())
+ proc_local_min =
+ std::min(proc_local_min, vector->block(i)[*block_local_min_element]);
}
return Utilities::MPI::min(proc_local_min, get_communicator<VectorType>(x));
AssertDimension(x_dealii->size(), z_dealii->size());
AssertDimension(x_dealii->size(), y_dealii->size());
- std::transform(x_dealii->begin(),
- x_dealii->end(),
- y_dealii->begin(),
- z_dealii->begin(),
- std::divides<>{});
+ auto x_ele = x_dealii->locally_owned_elements();
+ for (const auto idx : x_ele)
+ {
+ (*z_dealii)[idx] = (*x_dealii)[idx] / (*y_dealii)[idx];
+ }
+ z_dealii->compress(VectorOperation::insert);
}
AssertDimension(x_dealii->n_blocks(), y_dealii->n_blocks());
for (unsigned i = 0; i < x_dealii->n_blocks(); ++i)
- std::transform(x_dealii->block(i).begin(),
- x_dealii->block(i).end(),
- y_dealii->block(i).begin(),
- z_dealii->block(i).begin(),
- std::divides<>{});
+ {
+ auto x_ele = x_dealii->block(i).locally_owned_elements();
+ for (const auto idx : x_ele)
+ {
+ z_dealii->block(i)[idx] =
+ x_dealii->block(i)[idx] / y_dealii->block(i)[idx];
+ }
+ }
+ z_dealii->compress(VectorOperation::insert);
}
AssertDimension(x_dealii->size(), z_dealii->size());
- std::transform(x_dealii->begin(),
- x_dealii->end(),
- z_dealii->begin(),
- [](typename VectorType::value_type v) { return 1.0 / v; });
+ auto x_ele = x_dealii->locally_owned_elements();
+ for (const auto idx : x_ele)
+ {
+ (*z_dealii)[idx] = 1.0 / (*x_dealii)[idx];
+ }
+ z_dealii->compress(VectorOperation::insert);
}
AssertDimension(x_dealii->n_blocks(), z_dealii->n_blocks());
for (unsigned i = 0; i < x_dealii->n_blocks(); ++i)
- std::transform(x_dealii->block(i).begin(),
- x_dealii->block(i).end(),
- z_dealii->block(i).begin(),
- [](typename VectorType::value_type v) { return 1.0 / v; });
+ {
+ auto x_ele = x_dealii->block(i).locally_owned_elements();
+ for (const auto idx : x_ele)
+ {
+ z_dealii->block(i)[idx] = 1.0 / x_dealii->block(i)[idx];
+ }
+ }
+
+ z_dealii->compress(VectorOperation::insert);
}
AssertDimension(x_dealii->size(), z_dealii->size());
- std::transform(x_dealii->begin(),
- x_dealii->end(),
- z_dealii->begin(),
- [](typename VectorType::value_type v) {
- return std::fabs(v);
- });
+ auto x_ele = x_dealii->locally_owned_elements();
+ for (const auto idx : x_ele)
+ {
+ (*z_dealii)[idx] = std::fabs((*x_dealii)[idx]);
+ }
+
+ z_dealii->compress(VectorOperation::insert);
}
AssertDimension(x_dealii->n_blocks(), z_dealii->n_blocks());
for (unsigned i = 0; i < x_dealii->n_blocks(); ++i)
- std::transform(x_dealii->block(i).begin(),
- x_dealii->block(i).end(),
- z_dealii->block(i).begin(),
- [](typename VectorType::value_type v) {
- return std::fabs(v);
- });
+ {
+ auto x_ele = x_dealii->block(i).locally_owned_elements();
+ for (const auto idx : x_ele)
+ {
+ z_dealii->block(i)[idx] = std::fabs(x_dealii->block(i)[idx]);
+ }
+ }
+
+ z_dealii->compress(VectorOperation::insert);
}
const TrilinosWrappers::MPI::V>;
}
#endif
+
+#ifdef DEAL_II_WITH_PETSC
+// PETScWrappers Vector and BlockVector
+for (V : DEAL_II_VEC_TEMPLATES)
+ {
+ template SUNDIALS::internal::NVectorView<PETScWrappers::MPI::V>
+ SUNDIALS::internal::make_nvector_view<>(PETScWrappers::MPI::V &);
+ template SUNDIALS::internal::NVectorView<const PETScWrappers::MPI::V>
+ SUNDIALS::internal::make_nvector_view<>(const PETScWrappers::MPI::V &);
+ template PETScWrappers::MPI::V
+ *SUNDIALS::internal::unwrap_nvector<PETScWrappers::MPI::V>(N_Vector);
+ template const PETScWrappers::MPI::V *
+ SUNDIALS::internal::unwrap_nvector_const<PETScWrappers::MPI::V>(N_Vector);
+
+ template class SUNDIALS::internal::NVectorView<PETScWrappers::MPI::V>;
+ template class SUNDIALS::internal::NVectorView<const PETScWrappers::MPI::V>;
+ }
+#endif
\ No newline at end of file
return vector;
}
+ template <>
+ TrilinosWrappers::MPI::BlockVector
+ create_test_vector(double value)
+ {
+ const unsigned n_processes =
+ Utilities::MPI::n_mpi_processes(MPI_COMM_WORLD);
+ const unsigned block_size =
+ ((n_processes - 1) * (n_processes)) / 2 + n_processes;
+ const auto partitioning =
+ create_parallel_index_set().split_by_block({block_size, block_size});
+ TrilinosWrappers::MPI::BlockVector vector(partitioning, MPI_COMM_WORLD);
+ vector = value;
+ return vector;
+ }
+
+ template <>
+ PETScWrappers::MPI::Vector
+ create_test_vector(double value)
+ {
+ IndexSet local_dofs = create_parallel_index_set();
+
+ PETScWrappers::MPI::Vector vector(local_dofs, MPI_COMM_WORLD);
+ vector = value;
+ return vector;
+ }
+
+ template <>
+ PETScWrappers::MPI::BlockVector
+ create_test_vector(double value)
+ {
+ const unsigned n_processes =
+ Utilities::MPI::n_mpi_processes(MPI_COMM_WORLD);
+ const unsigned block_size =
+ ((n_processes - 1) * (n_processes)) / 2 + n_processes;
+ const auto partitioning =
+ create_parallel_index_set().split_by_block({block_size, block_size});
+ PETScWrappers::MPI::BlockVector vector(partitioning, MPI_COMM_WORLD);
+ vector = value;
+ return vector;
+ }
+
template <typename VectorType>
bool
vector_equal(const VectorType &a, const VectorType &b)
auto nv_b = make_nvector_view(vector_b);
auto result = N_VMin(nv_a);
- std::cout << "result: " << result << std::endl;
- vector_a.print(std::cout);
Assert(std::fabs(result - 2.0) < 1e-12, NVectorTestError());
result = N_VMin(nv_b);
run_all_tests<LinearAlgebra::distributed::BlockVector<double>>(
"LinearAlgebra::distributed::BlockVector<double>");
run_all_tests<TrilinosWrappers::MPI::Vector>("TrilinosWrappers::MPI::Vector");
+ run_all_tests<TrilinosWrappers::MPI::BlockVector>(
+ "TrilinosWrappers::MPI::BlockVector");
+ run_all_tests<PETScWrappers::MPI::Vector>("PETScWrappers::MPI::Vector");
+ run_all_tests<PETScWrappers::MPI::BlockVector>(
+ "PETScWrappers::MPI::BlockVector");
+
+ // although the memory would be cleared in ~MPI_InitFinalize it needs to be
+ // done manually to satisfy the PETSc memory check inside ~MPILogInitAll,
+ // which is invoked first
+ GrowingVectorMemory<PETScWrappers::MPI::Vector>::release_unused_memory();
+ GrowingVectorMemory<PETScWrappers::MPI::BlockVector>::release_unused_memory();
}
DEAL:0:TrilinosWrappers::MPI::Vector::test_max_norm OK
DEAL:0:TrilinosWrappers::MPI::Vector::test_min_element OK
DEAL:0:TrilinosWrappers::MPI::Vector::test_scale OK
+DEAL:0:TrilinosWrappers::MPI::BlockVector::test_nvector_view_unwrap OK
+DEAL:0:TrilinosWrappers::MPI::BlockVector::test_get_vector_id OK
+DEAL:0:TrilinosWrappers::MPI::BlockVector::test_clone OK
+DEAL:0:TrilinosWrappers::MPI::BlockVector::test_destroy OK
+DEAL:0:TrilinosWrappers::MPI::BlockVector::test_get_communicator OK
+DEAL:0:TrilinosWrappers::MPI::BlockVector::test_length OK
+DEAL:0:TrilinosWrappers::MPI::BlockVector::test_linear_sum OK
+DEAL:0:TrilinosWrappers::MPI::BlockVector::test_dot_product OK
+DEAL:0:TrilinosWrappers::MPI::BlockVector::test_set_constant OK
+DEAL:0:TrilinosWrappers::MPI::BlockVector::test_add_constant OK
+DEAL:0:TrilinosWrappers::MPI::BlockVector::test_elementwise_product OK
+DEAL:0:TrilinosWrappers::MPI::BlockVector::test_elementwise_div OK
+DEAL:0:TrilinosWrappers::MPI::BlockVector::test_elementwise_inv OK
+DEAL:0:TrilinosWrappers::MPI::BlockVector::test_elementwise_abs OK
+DEAL:0:TrilinosWrappers::MPI::BlockVector::test_weighted_rms_norm OK
+DEAL:0:TrilinosWrappers::MPI::BlockVector::test_max_norm OK
+DEAL:0:TrilinosWrappers::MPI::BlockVector::test_min_element OK
+DEAL:0:TrilinosWrappers::MPI::BlockVector::test_scale OK
+DEAL:0:PETScWrappers::MPI::Vector::test_nvector_view_unwrap OK
+DEAL:0:PETScWrappers::MPI::Vector::test_get_vector_id OK
+DEAL:0:PETScWrappers::MPI::Vector::test_clone OK
+DEAL:0:PETScWrappers::MPI::Vector::test_destroy OK
+DEAL:0:PETScWrappers::MPI::Vector::test_get_communicator OK
+DEAL:0:PETScWrappers::MPI::Vector::test_length OK
+DEAL:0:PETScWrappers::MPI::Vector::test_linear_sum OK
+DEAL:0:PETScWrappers::MPI::Vector::test_dot_product OK
+DEAL:0:PETScWrappers::MPI::Vector::test_set_constant OK
+DEAL:0:PETScWrappers::MPI::Vector::test_add_constant OK
+DEAL:0:PETScWrappers::MPI::Vector::test_elementwise_product OK
+DEAL:0:PETScWrappers::MPI::Vector::test_elementwise_div OK
+DEAL:0:PETScWrappers::MPI::Vector::test_elementwise_inv OK
+DEAL:0:PETScWrappers::MPI::Vector::test_elementwise_abs OK
+DEAL:0:PETScWrappers::MPI::Vector::test_weighted_rms_norm OK
+DEAL:0:PETScWrappers::MPI::Vector::test_max_norm OK
+DEAL:0:PETScWrappers::MPI::Vector::test_min_element OK
+DEAL:0:PETScWrappers::MPI::Vector::test_scale OK
+DEAL:0:PETScWrappers::MPI::BlockVector::test_nvector_view_unwrap OK
+DEAL:0:PETScWrappers::MPI::BlockVector::test_get_vector_id OK
+DEAL:0:PETScWrappers::MPI::BlockVector::test_clone OK
+DEAL:0:PETScWrappers::MPI::BlockVector::test_destroy OK
+DEAL:0:PETScWrappers::MPI::BlockVector::test_get_communicator OK
+DEAL:0:PETScWrappers::MPI::BlockVector::test_length OK
+DEAL:0:PETScWrappers::MPI::BlockVector::test_linear_sum OK
+DEAL:0:PETScWrappers::MPI::BlockVector::test_dot_product OK
+DEAL:0:PETScWrappers::MPI::BlockVector::test_set_constant OK
+DEAL:0:PETScWrappers::MPI::BlockVector::test_add_constant OK
+DEAL:0:PETScWrappers::MPI::BlockVector::test_elementwise_product OK
+DEAL:0:PETScWrappers::MPI::BlockVector::test_elementwise_div OK
+DEAL:0:PETScWrappers::MPI::BlockVector::test_elementwise_inv OK
+DEAL:0:PETScWrappers::MPI::BlockVector::test_elementwise_abs OK
+DEAL:0:PETScWrappers::MPI::BlockVector::test_weighted_rms_norm OK
+DEAL:0:PETScWrappers::MPI::BlockVector::test_max_norm OK
+DEAL:0:PETScWrappers::MPI::BlockVector::test_min_element OK
+DEAL:0:PETScWrappers::MPI::BlockVector::test_scale OK
DEAL:1:Vector<double>::test_nvector_view_unwrap OK
DEAL:1:Vector<double>::test_get_vector_id OK
DEAL:1:TrilinosWrappers::MPI::Vector::test_max_norm OK
DEAL:1:TrilinosWrappers::MPI::Vector::test_min_element OK
DEAL:1:TrilinosWrappers::MPI::Vector::test_scale OK
+DEAL:1:TrilinosWrappers::MPI::BlockVector::test_nvector_view_unwrap OK
+DEAL:1:TrilinosWrappers::MPI::BlockVector::test_get_vector_id OK
+DEAL:1:TrilinosWrappers::MPI::BlockVector::test_clone OK
+DEAL:1:TrilinosWrappers::MPI::BlockVector::test_destroy OK
+DEAL:1:TrilinosWrappers::MPI::BlockVector::test_get_communicator OK
+DEAL:1:TrilinosWrappers::MPI::BlockVector::test_length OK
+DEAL:1:TrilinosWrappers::MPI::BlockVector::test_linear_sum OK
+DEAL:1:TrilinosWrappers::MPI::BlockVector::test_dot_product OK
+DEAL:1:TrilinosWrappers::MPI::BlockVector::test_set_constant OK
+DEAL:1:TrilinosWrappers::MPI::BlockVector::test_add_constant OK
+DEAL:1:TrilinosWrappers::MPI::BlockVector::test_elementwise_product OK
+DEAL:1:TrilinosWrappers::MPI::BlockVector::test_elementwise_div OK
+DEAL:1:TrilinosWrappers::MPI::BlockVector::test_elementwise_inv OK
+DEAL:1:TrilinosWrappers::MPI::BlockVector::test_elementwise_abs OK
+DEAL:1:TrilinosWrappers::MPI::BlockVector::test_weighted_rms_norm OK
+DEAL:1:TrilinosWrappers::MPI::BlockVector::test_max_norm OK
+DEAL:1:TrilinosWrappers::MPI::BlockVector::test_min_element OK
+DEAL:1:TrilinosWrappers::MPI::BlockVector::test_scale OK
+DEAL:1:PETScWrappers::MPI::Vector::test_nvector_view_unwrap OK
+DEAL:1:PETScWrappers::MPI::Vector::test_get_vector_id OK
+DEAL:1:PETScWrappers::MPI::Vector::test_clone OK
+DEAL:1:PETScWrappers::MPI::Vector::test_destroy OK
+DEAL:1:PETScWrappers::MPI::Vector::test_get_communicator OK
+DEAL:1:PETScWrappers::MPI::Vector::test_length OK
+DEAL:1:PETScWrappers::MPI::Vector::test_linear_sum OK
+DEAL:1:PETScWrappers::MPI::Vector::test_dot_product OK
+DEAL:1:PETScWrappers::MPI::Vector::test_set_constant OK
+DEAL:1:PETScWrappers::MPI::Vector::test_add_constant OK
+DEAL:1:PETScWrappers::MPI::Vector::test_elementwise_product OK
+DEAL:1:PETScWrappers::MPI::Vector::test_elementwise_div OK
+DEAL:1:PETScWrappers::MPI::Vector::test_elementwise_inv OK
+DEAL:1:PETScWrappers::MPI::Vector::test_elementwise_abs OK
+DEAL:1:PETScWrappers::MPI::Vector::test_weighted_rms_norm OK
+DEAL:1:PETScWrappers::MPI::Vector::test_max_norm OK
+DEAL:1:PETScWrappers::MPI::Vector::test_min_element OK
+DEAL:1:PETScWrappers::MPI::Vector::test_scale OK
+DEAL:1:PETScWrappers::MPI::BlockVector::test_nvector_view_unwrap OK
+DEAL:1:PETScWrappers::MPI::BlockVector::test_get_vector_id OK
+DEAL:1:PETScWrappers::MPI::BlockVector::test_clone OK
+DEAL:1:PETScWrappers::MPI::BlockVector::test_destroy OK
+DEAL:1:PETScWrappers::MPI::BlockVector::test_get_communicator OK
+DEAL:1:PETScWrappers::MPI::BlockVector::test_length OK
+DEAL:1:PETScWrappers::MPI::BlockVector::test_linear_sum OK
+DEAL:1:PETScWrappers::MPI::BlockVector::test_dot_product OK
+DEAL:1:PETScWrappers::MPI::BlockVector::test_set_constant OK
+DEAL:1:PETScWrappers::MPI::BlockVector::test_add_constant OK
+DEAL:1:PETScWrappers::MPI::BlockVector::test_elementwise_product OK
+DEAL:1:PETScWrappers::MPI::BlockVector::test_elementwise_div OK
+DEAL:1:PETScWrappers::MPI::BlockVector::test_elementwise_inv OK
+DEAL:1:PETScWrappers::MPI::BlockVector::test_elementwise_abs OK
+DEAL:1:PETScWrappers::MPI::BlockVector::test_weighted_rms_norm OK
+DEAL:1:PETScWrappers::MPI::BlockVector::test_max_norm OK
+DEAL:1:PETScWrappers::MPI::BlockVector::test_min_element OK
+DEAL:1:PETScWrappers::MPI::BlockVector::test_scale OK
DEAL:0:TrilinosWrappers::MPI::Vector::test_max_norm OK
DEAL:0:TrilinosWrappers::MPI::Vector::test_min_element OK
DEAL:0:TrilinosWrappers::MPI::Vector::test_scale OK
+DEAL:0:TrilinosWrappers::MPI::BlockVector::test_nvector_view_unwrap OK
+DEAL:0:TrilinosWrappers::MPI::BlockVector::test_get_vector_id OK
+DEAL:0:TrilinosWrappers::MPI::BlockVector::test_clone OK
+DEAL:0:TrilinosWrappers::MPI::BlockVector::test_destroy OK
+DEAL:0:TrilinosWrappers::MPI::BlockVector::test_get_communicator OK
+DEAL:0:TrilinosWrappers::MPI::BlockVector::test_length OK
+DEAL:0:TrilinosWrappers::MPI::BlockVector::test_linear_sum OK
+DEAL:0:TrilinosWrappers::MPI::BlockVector::test_dot_product OK
+DEAL:0:TrilinosWrappers::MPI::BlockVector::test_set_constant OK
+DEAL:0:TrilinosWrappers::MPI::BlockVector::test_add_constant OK
+DEAL:0:TrilinosWrappers::MPI::BlockVector::test_elementwise_product OK
+DEAL:0:TrilinosWrappers::MPI::BlockVector::test_elementwise_div OK
+DEAL:0:TrilinosWrappers::MPI::BlockVector::test_elementwise_inv OK
+DEAL:0:TrilinosWrappers::MPI::BlockVector::test_elementwise_abs OK
+DEAL:0:TrilinosWrappers::MPI::BlockVector::test_weighted_rms_norm OK
+DEAL:0:TrilinosWrappers::MPI::BlockVector::test_max_norm OK
+DEAL:0:TrilinosWrappers::MPI::BlockVector::test_min_element OK
+DEAL:0:TrilinosWrappers::MPI::BlockVector::test_scale OK
+DEAL:0:PETScWrappers::MPI::Vector::test_nvector_view_unwrap OK
+DEAL:0:PETScWrappers::MPI::Vector::test_get_vector_id OK
+DEAL:0:PETScWrappers::MPI::Vector::test_clone OK
+DEAL:0:PETScWrappers::MPI::Vector::test_destroy OK
+DEAL:0:PETScWrappers::MPI::Vector::test_get_communicator OK
+DEAL:0:PETScWrappers::MPI::Vector::test_length OK
+DEAL:0:PETScWrappers::MPI::Vector::test_linear_sum OK
+DEAL:0:PETScWrappers::MPI::Vector::test_dot_product OK
+DEAL:0:PETScWrappers::MPI::Vector::test_set_constant OK
+DEAL:0:PETScWrappers::MPI::Vector::test_add_constant OK
+DEAL:0:PETScWrappers::MPI::Vector::test_elementwise_product OK
+DEAL:0:PETScWrappers::MPI::Vector::test_elementwise_div OK
+DEAL:0:PETScWrappers::MPI::Vector::test_elementwise_inv OK
+DEAL:0:PETScWrappers::MPI::Vector::test_elementwise_abs OK
+DEAL:0:PETScWrappers::MPI::Vector::test_weighted_rms_norm OK
+DEAL:0:PETScWrappers::MPI::Vector::test_max_norm OK
+DEAL:0:PETScWrappers::MPI::Vector::test_min_element OK
+DEAL:0:PETScWrappers::MPI::Vector::test_scale OK
+DEAL:0:PETScWrappers::MPI::BlockVector::test_nvector_view_unwrap OK
+DEAL:0:PETScWrappers::MPI::BlockVector::test_get_vector_id OK
+DEAL:0:PETScWrappers::MPI::BlockVector::test_clone OK
+DEAL:0:PETScWrappers::MPI::BlockVector::test_destroy OK
+DEAL:0:PETScWrappers::MPI::BlockVector::test_get_communicator OK
+DEAL:0:PETScWrappers::MPI::BlockVector::test_length OK
+DEAL:0:PETScWrappers::MPI::BlockVector::test_linear_sum OK
+DEAL:0:PETScWrappers::MPI::BlockVector::test_dot_product OK
+DEAL:0:PETScWrappers::MPI::BlockVector::test_set_constant OK
+DEAL:0:PETScWrappers::MPI::BlockVector::test_add_constant OK
+DEAL:0:PETScWrappers::MPI::BlockVector::test_elementwise_product OK
+DEAL:0:PETScWrappers::MPI::BlockVector::test_elementwise_div OK
+DEAL:0:PETScWrappers::MPI::BlockVector::test_elementwise_inv OK
+DEAL:0:PETScWrappers::MPI::BlockVector::test_elementwise_abs OK
+DEAL:0:PETScWrappers::MPI::BlockVector::test_weighted_rms_norm OK
+DEAL:0:PETScWrappers::MPI::BlockVector::test_max_norm OK
+DEAL:0:PETScWrappers::MPI::BlockVector::test_min_element OK
+DEAL:0:PETScWrappers::MPI::BlockVector::test_scale OK