From: Justin O'Connor Date: Thu, 2 Dec 2021 20:35:22 +0000 (-0700) Subject: Add test. X-Git-Tag: v9.4.0-rc1~672^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4f700171287c495cddeda6bc70356f04ad21db96;p=dealii.git Add test. --- diff --git a/tests/mpi/trilinos_vector_non_negative.cc b/tests/mpi/trilinos_vector_non_negative.cc new file mode 100644 index 0000000000..8a24f9d8f0 --- /dev/null +++ b/tests/mpi/trilinos_vector_non_negative.cc @@ -0,0 +1,92 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2011 - 2020 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 correct behavior of checking all Trilinos vector entries are non-negative +// works for distributed vectors + +#include +#include + +#include + +#include +#include + +#include "../tests.h" + + +void +test() +{ + const unsigned int myid = Utilities::MPI::this_mpi_process(MPI_COMM_WORLD); + const unsigned int n_processes = + Utilities::MPI::n_mpi_processes(MPI_COMM_WORLD); + + // create a vector that consists of elements indexed from 0 to n + TrilinosWrappers::MPI::Vector vec; + { + IndexSet is(100 * n_processes); + is.add_range(100 * myid, 100 * myid + 100); + vec.reinit(is, MPI_COMM_WORLD); + } + AssertThrow(vec.local_size() == 100, ExcInternalError()); + AssertThrow(vec.local_range().first == 100 * myid, ExcInternalError()); + AssertThrow(vec.local_range().second == 100 * myid + 100, ExcInternalError()); + for (unsigned int i = vec.local_range().first; i < vec.local_range().second; + ++i) + vec(i) = i; + vec.compress(VectorOperation::insert); + + // verify correctness so far + { + bool exact_non_negative = true; + AssertThrow(vec.is_non_negative() == exact_non_negative, + ExcInternalError()); + } + + if (vec.in_local_range(vec.size() / 2)) + vec[vec.size() / 2] = -1; + { + bool exact_non_negative = false; + AssertThrow(vec.is_non_negative() == exact_non_negative, + ExcInternalError()); + } + + deallog << "OK" << std::endl; +} + + + +int +main(int argc, char **argv) +{ + Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1); + + unsigned int myid = Utilities::MPI::this_mpi_process(MPI_COMM_WORLD); + + + deallog.push(Utilities::int_to_string(myid)); + + if (myid == 0) + { + initlog(); + + test(); + } + else + test(); +} diff --git a/tests/mpi/trilinos_vector_non_negative.with_trilinos=true.mpirun=2.output b/tests/mpi/trilinos_vector_non_negative.with_trilinos=true.mpirun=2.output new file mode 100644 index 0000000000..be8d055f86 --- /dev/null +++ b/tests/mpi/trilinos_vector_non_negative.with_trilinos=true.mpirun=2.output @@ -0,0 +1,2 @@ + +DEAL:0::OK