From: wolf Date: Thu, 25 Mar 2004 04:42:20 +0000 (+0000) Subject: Unify interfaces for parallel objects. Fix a bug where passed the wrong communicator. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c34518a18c98ce36e923ad31bcda227f7a80028a;p=dealii-svn.git Unify interfaces for parallel objects. Fix a bug where passed the wrong communicator. git-svn-id: https://svn.dealii.org/trunk@8871 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/lac/include/lac/petsc_parallel_sparse_matrix.h b/deal.II/lac/include/lac/petsc_parallel_sparse_matrix.h index cbdb05b9ca..b2fb281a07 100644 --- a/deal.II/lac/include/lac/petsc_parallel_sparse_matrix.h +++ b/deal.II/lac/include/lac/petsc_parallel_sparse_matrix.h @@ -24,7 +24,6 @@ #include -//TODO: How does a matrix or vector get its communicator if zero-initialized and later reinit'ed? namespace PETScWrappers { @@ -75,12 +74,12 @@ namespace PETScWrappers * this flag has been set. The default * value of this flag is @p{false}. */ - SparseMatrix (const MPI_Comm &communicator, - const unsigned int m, - const unsigned int n, - const unsigned int local_rows, - const unsigned int n_nonzero_per_row, - const bool is_symmetric = false); + SparseMatrix (const MPI_Comm &communicator, + const unsigned int m, + const unsigned int n, + const unsigned int local_rows, + const unsigned int n_nonzero_per_row, + const bool is_symmetric = false); /** * Initialize a rectangular matrix with @@ -111,7 +110,7 @@ namespace PETScWrappers SparseMatrix (const MPI_Comm &communicator, const unsigned int m, const unsigned int n, - const unsigned int local_rows, + const unsigned int local_rows, const std::vector &row_lengths, const bool is_symmetric = false); @@ -131,12 +130,12 @@ namespace PETScWrappers * the same argument list as the * present function. */ - void reinit (const MPI_Comm &communicator, - const unsigned int m, - const unsigned int n, - const unsigned int local_rows, - const unsigned int n_nonzero_per_row, - const bool is_symmetric = false); + void reinit (const MPI_Comm &communicator, + const unsigned int m, + const unsigned int n, + const unsigned int local_rows, + const unsigned int n_nonzero_per_row, + const bool is_symmetric = false); /** * Throw away the present matrix and @@ -173,7 +172,7 @@ namespace PETScWrappers */ void do_reinit (const unsigned int m, const unsigned int n, - const unsigned int local_rows, + const unsigned int local_rows, const std::vector &row_lengths, const bool is_symmetric = false); diff --git a/deal.II/lac/include/lac/petsc_parallel_vector.h b/deal.II/lac/include/lac/petsc_parallel_vector.h index 8dd0bc41eb..2c3f9bd774 100644 --- a/deal.II/lac/include/lac/petsc_parallel_vector.h +++ b/deal.II/lac/include/lac/petsc_parallel_vector.h @@ -58,9 +58,18 @@ namespace PETScWrappers /** * Constructor. Set dimension to - * @p{n} and initialize all + * @p n and initialize all * elements with zero. * + * @arg local_size denotes the size + * of the chunk that shall be stored + * on the present process. + * + * @arg communicator denotes the MPI + * communicator over which the + * different parts of the vector + * shall communicate + * * The constructor is made explicit * to avoid accidents like this: * @p{v=0;}. Presumably, the user @@ -71,29 +80,47 @@ namespace PETScWrappers * vector is replaced by one of * length zero. */ - explicit Vector (const unsigned int n, - const unsigned int local_size, - const MPI_Comm &communicator); + explicit Vector (const MPI_Comm &communicator, + const unsigned int n, + const unsigned int local_size); /** * Copy-constructor from deal.II * vectors. Sets the dimension to that * of the given vector, and copies all * elements. + * + * @arg local_size denotes the size + * of the chunk that shall be stored + * on the present process. + * + * @arg communicator denotes the MPI + * communicator over which the + * different parts of the vector + * shall communicate */ template - explicit Vector (const ::Vector &v, - const unsigned int local_size, - const MPI_Comm &communicator); + explicit Vector (const MPI_Comm &communicator, + const ::Vector &v, + const unsigned int local_size); /** * Copy-constructor the * values from a PETSc wrapper vector * class. + * + * @arg local_size denotes the size + * of the chunk that shall be stored + * on the present process. + * + * @arg communicator denotes the MPI + * communicator over which the + * different parts of the vector + * shall communicate */ - explicit Vector (const VectorBase &v, - const unsigned int local_size, - const MPI_Comm &communicator); + explicit Vector (const MPI_Comm &communicator, + const VectorBase &v, + const unsigned int local_size); /** * Copy the given vector. Resize the @@ -158,10 +185,10 @@ namespace PETScWrappers * elements are left an unspecified * state. */ - void reinit (const unsigned int N, - const unsigned int local_size, - const MPI_Comm &communicator, - const bool fast = false); + void reinit (const MPI_Comm &communicator, + const unsigned int N, + const unsigned int local_size, + const bool fast = false); /** * Change the dimension to that of @@ -207,9 +234,9 @@ namespace PETScWrappers template - Vector::Vector (const ::Vector &v, - const unsigned int local_size, - const MPI_Comm &communicator) + Vector::Vector (const MPI_Comm &communicator, + const ::Vector &v, + const unsigned int local_size) : communicator (communicator) { diff --git a/deal.II/lac/source/petsc_parallel_vector.cc b/deal.II/lac/source/petsc_parallel_vector.cc index 89e24bb5d7..733190a246 100644 --- a/deal.II/lac/source/petsc_parallel_vector.cc +++ b/deal.II/lac/source/petsc_parallel_vector.cc @@ -38,9 +38,9 @@ namespace PETScWrappers - Vector::Vector (const unsigned int n, - const unsigned int local_size, - const MPI_Comm &communicator) + Vector::Vector (const MPI_Comm &communicator, + const unsigned int n, + const unsigned int local_size) : communicator (communicator) { @@ -49,9 +49,9 @@ namespace PETScWrappers - Vector::Vector (const VectorBase &v, - const unsigned int local_size, - const MPI_Comm &communicator) + Vector::Vector (const MPI_Comm &communicator, + const VectorBase &v, + const unsigned int local_size) : communicator (communicator) { @@ -63,9 +63,9 @@ namespace PETScWrappers void - Vector::reinit (const unsigned int n, + Vector::reinit (const MPI_Comm &comm, + const unsigned int n, const unsigned int local_sz, - const MPI_Comm &comm, const bool fast) { communicator = comm; @@ -115,8 +115,11 @@ namespace PETScWrappers Assert (local_size <= n, ExcIndexRange (local_size, 0, n)); const int ierr - = VecCreateMPI (PETSC_COMM_SELF, local_size, n, &vector); + = VecCreateMPI (communicator, local_size, PETSC_DETERMINE, + &vector); AssertThrow (ierr == 0, ExcPETScError(ierr)); + + Assert (size() == n, ExcInternalError()); } }