21 #ifndef SELDON_FILE_VECTOR_PETSCVECTOR_INLINE_CXX
24 #include "PetscVector.hxx"
40 template <
class T,
class Allocator>
54 template <
class T,
class Allocator>
67 template <
class T,
class Allocator>
71 petsc_vector_deallocated_ =
true;
80 template <
class T,
class Allocator>
94 template <
class T,
class Allocator>
105 template <
class T,
class Allocator>
108 return petsc_vector_;
116 template <
class T,
class Allocator>
119 return petsc_vector_;
127 template <
class T,
class Allocator>
130 mpi_communicator_ = mpi_communicator;
144 template <
class T,
class Allocator>
147 if (petsc_vector_deallocated_)
150 ierr = VecDestroy(&petsc_vector_);
151 CHKERRABORT(mpi_communicator_, ierr);
152 petsc_vector_deallocated_ =
true;
161 template <
class T,
class Allocator>
164 throw Undefined(
"PETScVector<T, Allocator>::Resize(int n)");
182 template <
class T,
class Allocator>
184 ::SetData(
int i,
typename PETScVector<T, Allocator>::pointer data)
186 throw Undefined(
"PETScVector<T, Allocator>::SetData(int i, "
187 "typename PETScVector<T, Allocator>::pointer data)");
197 template <
class T,
class Allocator>
200 throw Undefined(
"PETScVector<T, Allocator>::Nullify()");
214 template <
class T,
class Allocator>
215 inline typename PETScVector<T, Allocator>::value_type
218 #ifdef SELDON_CHECK_BOUNDS
219 if (i < 0 || i >= this->m_)
221 string(
"Index should be in [0, ") +
to_str(this->m_-1)
222 +
"], but is equal to " +
to_str(i) +
".");
228 ierr = VecGetValues(petsc_vector_, 1, index, ret);
229 CHKERRABORT(mpi_communicator_, ierr);
243 template <
class T,
class Allocator>
250 ierr = VecSetValues(petsc_vector_, 1, ix,
251 data, INSERT_VALUES);
252 CHKERRABORT(mpi_communicator_, ierr);
257 template <
class T,
class Allocator>
262 ierr = VecAssemblyBegin(petsc_vector_);
263 CHKERRABORT(mpi_communicator_, ierr);
264 ierr = VecAssemblyEnd(petsc_vector_);
265 CHKERRABORT(mpi_communicator_, ierr);
278 template <
class T,
class Allocator>
283 ierr = VecGetOwnershipRange(petsc_vector_, &i, &j);
284 CHKERRABORT(mpi_communicator_, ierr);
294 template <
class T,
class Allocator>
308 template <
class T,
class Allocator>
311 throw Undefined(
"PETScVector<T, Allocator>::Append(const T& x)");
324 template <
class T,
class Allocator>
335 template <
class T,
class Allocator>
339 VecGetLocalSize(petsc_vector_, &size);
358 template <
class T,
class Allocator>
362 this->mpi_communicator_ = MPI_COMM_WORLD;
365 ierr = VecCreateSeq(PETSC_COMM_SELF, 0, &this->petsc_vector_);
366 this->petsc_vector_deallocated_ =
false;
375 template <
class T,
class Allocator>
380 this->mpi_communicator_ = mpi_communicator;
382 ierr = VecCreateSeq(PETSC_COMM_SELF, i, &this->petsc_vector_);
383 CHKERRABORT(this->mpi_communicator_, ierr);
384 ierr = VecSet(this->petsc_vector_, 0.);
385 CHKERRABORT(this->mpi_communicator_, ierr);
394 template <
class T,
class Allocator>
405 template <
class T,
class Allocator>
419 template <
class T,
class Allocator>
431 template <
class T,
class Allocator>
445 template <
class T,
class Allocator>
460 template <
class T,
class Allocator>
467 ierr = VecCreateSeq(PETSC_COMM_SELF, i, &this->petsc_vector_);
468 CHKERRABORT(this->mpi_communicator_, ierr);
471 this->petsc_vector_deallocated_ =
false;
481 template <
class T,
class Allocator>
494 template <
class T,
class Allocator>
508 template <
class T,
class Allocator>
514 ierr = VecScale(this->petsc_vector_, alpha);
515 CHKERRABORT(this->mpi_communicator_, ierr);
521 template <
class T,
class Allocator>
525 ierr = VecView(this->petsc_vector_, PETSC_VIEWER_STDOUT_SELF);
543 template <
class T,
class Allocator>
547 this->mpi_communicator_ = MPI_COMM_WORLD;
549 ierr = VecCreateMPI(this->mpi_communicator_,
550 PETSC_DECIDE, 0, &this->petsc_vector_);
551 CHKERRABORT(this->mpi_communicator_, ierr);
560 template <
class T,
class Allocator>
565 this->mpi_communicator_ = mpi_communicator;
566 ierr = VecCreateMPI(this->mpi_communicator_, PETSC_DECIDE, i,
567 &this->petsc_vector_);
568 CHKERRABORT(this->mpi_communicator_, ierr);
569 ierr = VecSet(this->petsc_vector_, 0.);
570 CHKERRABORT(this->mpi_communicator_, ierr);
581 template <
class T,
class Allocator>
583 MPI_Comm mpi_communicator):
587 this->mpi_communicator_ = mpi_communicator;
588 ierr = VecCreateMPI(this->mpi_communicator_, Nlocal,
589 i, &this->petsc_vector_);
590 CHKERRABORT(this->mpi_communicator_, ierr);
591 ierr = VecSet(this->petsc_vector_, 0.);
592 CHKERRABORT(this->mpi_communicator_, ierr);
601 template <
class T,
class Allocator>
612 template <
class T,
class Allocator>
626 template <
class T,
class Allocator>
638 template <
class T,
class Allocator>
653 template <
class T,
class Allocator>
667 template <
class T,
class Allocator>
680 template <
class T,
class Allocator>
694 template <
class T,
class Allocator>
700 ierr = VecScale(this->petsc_vector_, alpha);
701 CHKERRABORT(this->mpi_communicator_, ierr);
707 template <
class T,
class Allocator>
711 ierr = VecView(this->petsc_vector_, PETSC_VIEWER_STDOUT_WORLD);
722 template <
class T,
class Allocator>
729 ierr = VecCreateMPI(this->mpi_communicator_, local_size, i,
730 &this->petsc_vector_);
731 CHKERRABORT(this->mpi_communicator_, ierr);
734 this->petsc_vector_deallocated_ =
false;
741 #define SELDON_FILE_PETSCVECTOR_INLINE_CXX