-
Notifications
You must be signed in to change notification settings - Fork 707
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <deal.II/base/index_set.h> | ||
#include <deal.II/base/utilities.h> | ||
|
||
#include <deal.II/lac/trilinos_vector.h> | ||
|
||
#include <iostream> | ||
#include <vector> | ||
|
||
#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(); | ||
} |
2 changes: 2 additions & 0 deletions
2
tests/mpi/trilinos_vector_non_negative.with_trilinos=true.mpirun=2.output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
DEAL:0::OK |