From: Timo Heister Date: Thu, 31 Aug 2017 19:52:11 +0000 (-0400) Subject: Catch ReadWriteVector::import errors from Trilinos X-Git-Tag: v9.0.0-rc1~1127^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F4998%2Fhead;p=dealii.git Catch ReadWriteVector::import errors from Trilinos - check return value of Epetra import - document that ghosted vectors are not allowed - add test for that - cleanup --- diff --git a/include/deal.II/lac/read_write_vector.h b/include/deal.II/lac/read_write_vector.h index 73284dea64..d8a53ac8e5 100644 --- a/include/deal.II/lac/read_write_vector.h +++ b/include/deal.II/lac/read_write_vector.h @@ -291,6 +291,8 @@ namespace LinearAlgebra * replace the current elements. The last parameter can be used if the same * communication pattern is used multiple times. This can be used to improve * performance. + * + * @note: The @p trilinos_vec is not allowed to have ghost entries. */ void import(const TrilinosWrappers::MPI::Vector &trilinos_vec, VectorOperation::values operation, diff --git a/include/deal.II/lac/read_write_vector.templates.h b/include/deal.II/lac/read_write_vector.templates.h index 7938f76efa..cd1602698a 100644 --- a/include/deal.II/lac/read_write_vector.templates.h +++ b/include/deal.II/lac/read_write_vector.templates.h @@ -338,20 +338,32 @@ namespace LinearAlgebra if (operation==VectorOperation::insert) { - target_vector.Import(multivector, import, Insert); - double *values = target_vector.Values(); + const int err = target_vector.Import(multivector, import, Insert); + AssertThrow(err == 0, ExcMessage("Epetra Import() failed with error code: " + + Utilities::to_string(err))); + + const double *values = target_vector.Values(); const int size = target_vector.MyLength(); + Assert(size==0 || values != nullptr, ExcInternalError("Import failed.")); + for (int i=0; i RWV + +#include "../tests.h" +#include +#include +#include +#include + +#include + +void test() +{ + IndexSet is(8); + unsigned int rank = Utilities::MPI::this_mpi_process(MPI_COMM_WORLD); + if (rank==0) + is.add_range(0,4); + if (rank==1) + is.add_range(4,8); + is.compress(); + + deallog << "IS: "; + is.print(deallog); + + IndexSet is_ghosted(8); + is_ghosted.add_range(2,6); + deallog << "IS_ghosted: "; + is_ghosted.print(deallog); + + TrilinosWrappers::MPI::Vector tril_vector(is); + TrilinosWrappers::MPI::Vector tril_vector_ghosted; + tril_vector_ghosted.reinit(is, is_ghosted, MPI_COMM_WORLD); + for (unsigned int i=0; i<8; ++i) + tril_vector[i] = i; + + tril_vector.compress(VectorOperation::insert); + deallog << "trilinos vec:" << std::endl; + tril_vector.print(deallog.get_file_stream()); + + tril_vector_ghosted = tril_vector; + + deallog << "trilinos vec ghosted:" << std::endl; + tril_vector_ghosted.print(deallog.get_file_stream()); + + + IndexSet readwrite_is (tril_vector_ghosted.vector_partitioner()); + deallog << "ghosted IS: "; + readwrite_is.print(deallog); + + deallog << "tril_vector_ghosted.owned_elements() "; + tril_vector_ghosted.locally_owned_elements().print(deallog); + + { + deallog << "import of ghosted vector should fail:" << std::endl; + LinearAlgebra::ReadWriteVector readwrite(readwrite_is); + try + { + readwrite.import(tril_vector_ghosted, VectorOperation::insert); + deallog << "RWVector contents:" << std::endl; + readwrite.print(deallog.get_file_stream()); + } + catch (ExceptionBase &exc) + { + deallog << exc.get_exc_name() << std::endl; + } + } + { + deallog << "import of distributed vector should work:" << std::endl; + LinearAlgebra::ReadWriteVector readwrite(readwrite_is); + readwrite.import(tril_vector, VectorOperation::insert); + deallog << "RWVector contents:" << std::endl; + readwrite.print(deallog.get_file_stream()); + } + + deallog << "OK" <