From: Bruno Turcksin Date: Tue, 23 Jul 2019 14:55:13 +0000 (+0000) Subject: Add test for LA::d::Vector::import() X-Git-Tag: v9.2.0-rc1~1350^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c1c1a0638c14ee3b7bef30f21c1e10f279a3d2a9;p=dealii.git Add test for LA::d::Vector::import() --- diff --git a/tests/cuda/parallel_vector_25.cu b/tests/cuda/parallel_vector_25.cu new file mode 100644 index 0000000000..88f3ca0f5e --- /dev/null +++ b/tests/cuda/parallel_vector_25.cu @@ -0,0 +1,97 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2018 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.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + + +// check import from LA::d::Vector to another LA::d::Vector + +#include +#include +#include + +#include + +#include "../tests.h" + +void +test() +{ + unsigned int rank = Utilities::MPI::this_mpi_process(MPI_COMM_WORLD); + const unsigned int size = 100; + const unsigned int local_size = 50; + const unsigned int ghost_size = 75; + + IndexSet locally_owned(size); + if (rank == 0) + locally_owned.add_range(0, local_size); + else + locally_owned.add_range(size - local_size, size); + locally_owned.compress(); + + IndexSet ghost_indices(size); + if (rank == 0) + ghost_indices.add_range(0, ghost_size); + else + ghost_indices.add_range(size - ghost_size, size); + ghost_indices.size(); + + LinearAlgebra::distributed::Vector vec_ref( + locally_owned, ghost_indices, MPI_COMM_WORLD); + for (unsigned int i = 0; i < local_size; ++i) + vec_ref.local_element(i) = i; + vec_ref.compress(VectorOperation::insert); + + auto partitioner = vec_ref.get_partitioner(); + LinearAlgebra::distributed::Vector vec_dev( + partitioner); + LinearAlgebra::distributed::Vector vec_host( + partitioner); + + // Assignment from Host to CUDA + vec_dev.import(vec_ref, VectorOperation::insert); + + // Assignment from CUDA to Host + vec_host.import(vec_dev, VectorOperation::insert); + + for (unsigned int i = 0; i < ghost_size; ++i) + { + AssertThrow(std::fabs(vec_ref.local_element(i) - + vec_host.local_element(i)) < 1e-12, + ExcInternalError()); + } + + if (rank == 0) + deallog << "OK" << std::endl; +} + +int +main(int argc, char **argv) +{ + Utilities::MPI::MPI_InitFinalize mpi_initialization( + argc, argv, testing_max_num_threads()); + + unsigned int myid = Utilities::MPI::this_mpi_process(MPI_COMM_WORLD); + deallog.push(Utilities::int_to_string(myid)); + + init_cuda(true); + + if (myid == 0) + { + initlog(); + + test(); + } + else + test(); +} diff --git a/tests/cuda/parallel_vector_25.mpirun=2.output b/tests/cuda/parallel_vector_25.mpirun=2.output new file mode 100644 index 0000000000..be8d055f86 --- /dev/null +++ b/tests/cuda/parallel_vector_25.mpirun=2.output @@ -0,0 +1,2 @@ + +DEAL:0::OK