version GIT relicensing-7278-g091132d5eb 2026-12-02 03:10:01+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
trilinos_vector.cc
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 2008 - 2026 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
14
15#ifdef DEAL_II_WITH_TRILINOS
16
17# include <deal.II/base/mpi.h>
19
24
25# include <boost/io/ios_state.hpp>
26
28# include <Epetra_Export.h>
29# include <Epetra_Import.h>
30# include <Epetra_Vector.h>
32
33# include <cmath>
34# include <memory>
35
36
37
38#endif // DEAL_II_WITH_TRILINOS
39
41
42#ifdef DEAL_II_WITH_TRILINOS
43
44namespace TrilinosWrappers
45{
46# ifndef DOXYGEN
47 namespace internal
48 {
49 VectorReference::
50 operator TrilinosScalar() const
51 {
52 AssertIndexRange(index, vector.size());
53
54 // Trilinos allows for vectors to be referenced by the [] or ()
55 // operators but only () checks index bounds. We check these bounds by
56 // ourselves, so we can use []. Note that we can only get local values.
57
58 const TrilinosWrappers::types::int_type local_index =
59 vector.vector->Map().LID(
60 static_cast<TrilinosWrappers::types::int_type>(index));
61# ifndef DEAL_II_WITH_64BIT_INDICES
62 Assert(local_index >= 0,
64 index,
65 vector.vector->Map().NumMyElements(),
66 vector.vector->Map().MinMyGID(),
67 vector.vector->Map().MaxMyGID()));
68# else
69 Assert(local_index >= 0,
71 index,
72 vector.vector->Map().NumMyElements(),
73 vector.vector->Map().MinMyGID64(),
74 vector.vector->Map().MaxMyGID64()));
75# endif
76
77
78 return (*(vector.vector))[0][local_index];
79 }
80 } // namespace internal
81# endif
82
83 namespace MPI
84 {
86 : last_action(Zero)
87 , compressed(true)
88 , has_ghosts(false)
89 , vector(new Epetra_FEVector(
90 Epetra_Map(0, 0, 0, Utilities::Trilinos::comm_self())))
91 {}
92
93
94
95 Vector::Vector(const IndexSet &parallel_partitioning,
96 const MPI_Comm communicator)
97 : Vector()
98 {
99 reinit(parallel_partitioning, communicator);
100 }
101
102
103
105 : Vector()
106 {
108 vector = std::make_unique<Epetra_FEVector>(*v.vector);
110 }
111
112
113
114 Vector::Vector(Vector &&v) // NOLINT
115 : Vector()
116 {
117 // initialize a minimal, valid object and swap
118 static_cast<EnableObserverPointer &>(*this) =
119 static_cast<EnableObserverPointer &&>(v);
120 swap(v);
121 }
122
123
124
125 Vector::Vector(const IndexSet &parallel_partitioner,
126 const Vector &v,
127 const MPI_Comm communicator)
128 : Vector()
129 {
130 AssertThrow(parallel_partitioner.size() ==
131 static_cast<size_type>(
133 ExcDimensionMismatch(parallel_partitioner.size(),
135 v.vector->Map())));
136
137 vector = std::make_unique<Epetra_FEVector>(
138 parallel_partitioner.make_trilinos_map(communicator, true));
139
141
142 Epetra_Import data_exchange(vector->Map(), v.vector->Map());
143
144 const int ierr = vector->Import(*v.vector, data_exchange, Insert);
145 AssertThrow(ierr == 0, ExcTrilinosError(ierr));
146
147 last_action = Insert;
148 }
149
150
151
153 const IndexSet &ghost,
154 const MPI_Comm communicator)
155 : Vector()
156 {
157 reinit(local, ghost, communicator, false);
158 }
159
160
161
162 void
164 {
165 // When we clear the vector, reset the pointer and generate an empty
166 // vector.
167 Epetra_Map map(0, 0, Epetra_MpiComm(MPI_COMM_SELF));
168
169 has_ghosts = false;
170 vector = std::make_unique<Epetra_FEVector>(map);
171 last_action = Zero;
172 }
173
174
175
176 void
177 Vector::reinit(const IndexSet &parallel_partitioner,
178 const MPI_Comm communicator,
179 const bool /*omit_zeroing_entries*/)
180 {
181 nonlocal_vector.reset();
182
183 const bool overlapping =
184 !parallel_partitioner.is_ascending_and_one_to_one(communicator);
185
186 Epetra_Map map =
187 parallel_partitioner.make_trilinos_map(communicator, overlapping);
188
189 vector = std::make_unique<Epetra_FEVector>(map);
190
191 has_ghosts = vector->Map().UniqueGIDs() == false;
192
193 // If the IndexSets are overlapping, we don't really know
194 // which process owns what. So we decide that no process
195 // owns anything in that case. In particular asking for
196 // the locally owned elements is not allowed.
197 if (has_ghosts)
198 {
201 }
202 else
203 owned_elements = parallel_partitioner;
204
205 if constexpr (running_in_debug_mode())
206 {
207 const size_type n_elements_global =
209
210 Assert(has_ghosts || n_elements_global == size(), ExcInternalError());
211 }
212
213 last_action = Zero;
214 }
215
216
217
218 void
219 Vector::reinit(const Vector &v, const bool omit_zeroing_entries)
220 {
221 nonlocal_vector.reset();
222
223 // check equality for MPI communicators: We can only choose the fast
224 // version in case the underlying Epetra_MpiComm object is the same,
225 // otherwise we might access an MPI_Comm object that has been
226 // deleted
227 const Epetra_MpiComm *my_comm =
228 dynamic_cast<const Epetra_MpiComm *>(&vector->Comm());
229 const Epetra_MpiComm *v_comm =
230 dynamic_cast<const Epetra_MpiComm *>(&v.vector->Comm());
231 const bool same_communicators = my_comm != nullptr && v_comm != nullptr &&
232 my_comm->DataPtr() == v_comm->DataPtr();
233 if (!same_communicators || vector->Map().SameAs(v.vector->Map()) == false)
234 {
235 vector = std::make_unique<Epetra_FEVector>(v.vector->Map());
237 last_action = Zero;
239 }
240 else if (omit_zeroing_entries == false)
241 {
242 // old and new vectors have exactly the same map, i.e. size and
243 // parallel distribution
244 int ierr = vector->GlobalAssemble(last_action);
245 Assert(ierr == 0, ExcTrilinosError(ierr));
246
247 ierr = vector->PutScalar(0.0);
248 Assert(ierr == 0, ExcTrilinosError(ierr));
249
250 last_action = Zero;
251 }
252
253 if constexpr (running_in_debug_mode())
254 {
255 const Epetra_MpiComm *comm_ptr =
256 dynamic_cast<const Epetra_MpiComm *>(&(v.vector->Comm()));
257 Assert(comm_ptr != nullptr, ExcInternalError());
258 const size_type n_elements_global =
259 Utilities::MPI::sum(owned_elements.n_elements(), comm_ptr->Comm());
260 Assert(has_ghosts || n_elements_global == size(), ExcInternalError());
261 }
262 }
263
264
265
266 void
267 Vector::reinit(const MPI::BlockVector &v, const bool import_data)
268 {
269 nonlocal_vector.reset();
272
273 // In case we do not allow to have different maps, this call means that
274 // we have to reset the vector. So clear the vector, initialize our map
275 // with the map in v, and generate the vector.
276 if (v.n_blocks() == 0)
277 return;
278
279 // create a vector that holds all the elements contained in the block
280 // vector. need to manually create an Epetra_Map.
281 size_type n_elements = 0, added_elements = 0, block_offset = 0;
282 for (size_type block = 0; block < v.n_blocks(); ++block)
283 n_elements += v.block(block).vector->Map().NumMyElements();
284 std::vector<TrilinosWrappers::types::int_type> global_ids(n_elements, -1);
285 for (size_type block = 0; block < v.n_blocks(); ++block)
286 {
287 TrilinosWrappers::types::int_type *glob_elements =
289 v.block(block).trilinos_partitioner());
290 size_type vector_size = v.block(block).vector->Map().NumMyElements();
291 for (size_type i = 0; i < vector_size; ++i)
292 global_ids[added_elements++] = glob_elements[i] + block_offset;
293 owned_elements.add_indices(v.block(block).owned_elements,
294 block_offset);
295 block_offset += v.block(block).size();
296 }
297
298 Assert(n_elements == added_elements, ExcInternalError());
299 Epetra_Map new_map(v.size(),
300 n_elements,
301 global_ids.data(),
302 0,
303 v.block(0).trilinos_partitioner().Comm());
304
305 auto actual_vec = std::make_unique<Epetra_FEVector>(new_map);
306
307 TrilinosScalar *entries = (*actual_vec)[0];
308 for (size_type block = 0; block < v.n_blocks(); ++block)
309 {
310 v.block(block).trilinos_vector().ExtractCopy(entries, 0);
311 entries += v.block(block).vector->Map().NumMyElements();
312 }
313
314 if (import_data == true)
315 {
317 *actual_vec)) == v.size(),
319 *actual_vec),
320 v.size()));
321
322 Epetra_Import data_exchange(vector->Map(), actual_vec->Map());
323
324 const int ierr = vector->Import(*actual_vec, data_exchange, Insert);
325 AssertThrow(ierr == 0, ExcTrilinosError(ierr));
326
327 last_action = Insert;
328 }
329 else
330 vector = std::move(actual_vec);
331 if constexpr (running_in_debug_mode())
332 {
333 const Epetra_MpiComm *comm_ptr =
334 dynamic_cast<const Epetra_MpiComm *>(&(vector->Comm()));
335 Assert(comm_ptr != nullptr, ExcInternalError());
336 const size_type n_elements_global =
337 Utilities::MPI::sum(owned_elements.n_elements(), comm_ptr->Comm());
338
339 Assert(has_ghosts || n_elements_global == size(), ExcInternalError());
340 }
341 }
342
343
344
345 void
346 Vector::reinit(const IndexSet &locally_owned_entries,
347 const IndexSet &ghost_entries,
348 const MPI_Comm communicator,
349 const bool vector_writable)
350 {
351 nonlocal_vector.reset();
352 owned_elements = locally_owned_entries;
353 if (vector_writable == false)
354 {
355 IndexSet parallel_partitioner = locally_owned_entries;
356 parallel_partitioner.add_indices(ghost_entries);
357 Epetra_Map map =
358 parallel_partitioner.make_trilinos_map(communicator, true);
359 vector = std::make_unique<Epetra_FEVector>(map);
360 }
361 else
362 {
363 Epetra_Map map =
364 locally_owned_entries.make_trilinos_map(communicator, true);
365 Assert(map.IsOneToOne(),
366 ExcMessage("A writable vector must not have ghost entries in "
367 "its parallel partitioning"));
368
369 if (vector->Map().SameAs(map) == false)
370 vector = std::make_unique<Epetra_FEVector>(map);
371 else
372 {
373 const int ierr = vector->PutScalar(0.);
374 Assert(ierr == 0, ExcTrilinosError(ierr));
375 }
376
377 IndexSet nonlocal_entries(ghost_entries);
378 nonlocal_entries.subtract_set(locally_owned_entries);
379 if (Utilities::MPI::n_mpi_processes(communicator) > 1)
380 {
381 Epetra_Map nonlocal_map =
382 nonlocal_entries.make_trilinos_map(communicator, true);
384 std::make_unique<Epetra_MultiVector>(nonlocal_map, 1);
385 }
386 }
387
388 has_ghosts = vector->Map().UniqueGIDs() == false;
389
390 last_action = Zero;
391
392 if constexpr (running_in_debug_mode())
393 {
394 const size_type n_elements_global =
396
397 Assert(has_ghosts || n_elements_global == size(), ExcInternalError());
398 }
399 }
400
401
402
403 void
405 const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner,
406 const bool make_ghosted,
407 const bool vector_writable)
408 {
409 if (make_ghosted)
410 {
411 Assert(partitioner->ghost_indices_initialized(),
412 ExcMessage("You asked to create a ghosted vector, but the "
413 "partitioner does not provide ghost indices."));
414
415 this->reinit(partitioner->locally_owned_range(),
416 partitioner->ghost_indices(),
417 partitioner->get_mpi_communicator(),
418 vector_writable);
419 }
420 else
421 {
422 this->reinit(partitioner->locally_owned_range(),
423 partitioner->get_mpi_communicator());
424 }
425 }
426
427
428
429 Vector &
431 {
432 Assert(vector.get() != nullptr,
433 ExcMessage("Vector is not constructed properly."));
434
435 // check equality for MPI communicators to avoid accessing a possibly
436 // invalid MPI_Comm object
437 const Epetra_MpiComm *my_comm =
438 dynamic_cast<const Epetra_MpiComm *>(&vector->Comm());
439 const Epetra_MpiComm *v_comm =
440 dynamic_cast<const Epetra_MpiComm *>(&v.vector->Comm());
441 const bool same_communicators = my_comm != nullptr && v_comm != nullptr &&
442 my_comm->DataPtr() == v_comm->DataPtr();
443 // Need to ask MPI whether the communicators are the same. We would like
444 // to use the following checks but currently we cannot make sure the
445 // memory of my_comm is not stale from some MPI_Comm_free
446 // somewhere. This can happen when a vector lives in GrowingVectorMemory
447 // data structures. Thus, the following code is commented out.
448 //
449 // if (my_comm != nullptr &&
450 // v_comm != nullptr &&
451 // my_comm->DataPtr() != v_comm->DataPtr())
452 // {
453 // int communicators_same = 0;
454 // const int ierr = MPI_Comm_compare (my_comm->GetMpiComm(),
455 // v_comm->GetMpiComm(),
456 // &communicators_same);
457 // AssertThrowMPI(ierr);
458 // if (!(communicators_same == MPI_IDENT ||
459 // communicators_same == MPI_CONGRUENT))
460 // same_communicators = false;
461 // else
462 // same_communicators = true;
463 // }
464
465 // distinguish three cases. First case: both vectors have the same
466 // layout (just need to copy the local data, not reset the memory and
467 // the underlying Epetra_Map). The third case means that we have to
468 // rebuild the calling vector.
469 if (same_communicators && v.vector->Map().SameAs(vector->Map()))
470 {
471 *vector = *v.vector;
472 if (v.nonlocal_vector.get() != nullptr)
474 std::make_unique<Epetra_MultiVector>(v.nonlocal_vector->Map(), 1);
475 last_action = Zero;
476 }
477 // Second case: vectors have the same global
478 // size, but different parallel layouts (and
479 // one of them a one-to-one mapping). Then we
480 // can call the import/export functionality.
481 else if (size() == v.size() &&
482 (v.vector->Map().UniqueGIDs() || vector->Map().UniqueGIDs()))
483 {
484 Epetra_Import data_exchange(vector->Map(), v.vector->Map());
485
486 const int ierr = vector->Import(*v.vector, data_exchange, Insert);
487 AssertThrow(ierr == 0, ExcTrilinosError(ierr));
488
489 last_action = Insert;
490 }
491 // Third case: Vectors do not have the same
492 // size.
493 else
494 {
495 vector = std::make_unique<Epetra_FEVector>(*v.vector);
496 last_action = Zero;
499 }
500
501 if (v.nonlocal_vector.get() != nullptr)
503 std::make_unique<Epetra_MultiVector>(v.nonlocal_vector->Map(), 1);
504
505 return *this;
506 }
507
508
509
510 Vector &
512 {
513 static_cast<EnableObserverPointer &>(*this) =
514 static_cast<EnableObserverPointer &&>(v);
515 swap(v);
516 return *this;
517 }
518
519
520
521 template <typename number>
522 Vector &
523 Vector::operator=(const ::Vector<number> &v)
524 {
525 Assert(size() == v.size(), ExcDimensionMismatch(size(), v.size()));
526
527 // this is probably not very efficient but works. in particular, we could
528 // do better if we know that number==TrilinosScalar because then we could
529 // elide the copying of elements
530 //
531 // let's hope this isn't a particularly frequent operation
532 std::pair<size_type, size_type> local_range = this->local_range();
533 for (size_type i = local_range.first; i < local_range.second; ++i)
534 (*vector)[0][i - local_range.first] = v(i);
535
536 return *this;
537 }
538
539
540
541 void
543 const Vector &v)
544 {
545 Assert(m.trilinos_matrix().Filled() == true,
546 ExcMessage("Matrix is not compressed. "
547 "Cannot find exchange information!"));
548 Assert(v.vector->Map().UniqueGIDs() == true,
549 ExcMessage("The input vector has overlapping data, "
550 "which is not allowed."));
551
552 if (vector->Map().SameAs(m.trilinos_matrix().ColMap()) == false)
553 vector =
554 std::make_unique<Epetra_FEVector>(m.trilinos_matrix().ColMap());
555
556 Epetra_Import data_exchange(vector->Map(), v.vector->Map());
557 const int ierr = vector->Import(*v.vector, data_exchange, Insert);
558
559 AssertThrow(ierr == 0, ExcTrilinosError(ierr));
560
561 last_action = Insert;
562 }
563
564
565 void
567 const VectorOperation::values operation)
568 {
569 Assert(
570 this->size() == rwv.size(),
572 "Both vectors need to have the same size for import_elements() to work!"));
573 // TODO: a generic import_elements() function should handle any kind of
574 // data layout in ReadWriteVector, but this function is of limited use as
575 // this class will (hopefully) be retired eventually.
578
579 if (operation == VectorOperation::insert)
580 {
581 for (const auto idx : this->locally_owned_elements())
582 (*this)[idx] = rwv[idx];
583 }
584 else if (operation == VectorOperation::add)
585 {
586 for (const auto idx : this->locally_owned_elements())
587 (*this)[idx] += rwv[idx];
588 }
589 else
591
592 this->compress(operation);
593 }
594
595
596 void
598 {
599 Assert(has_ghost_elements() == false,
601 "Calling compress() is only useful if a vector "
602 "has been written into, but this is a vector with ghost "
603 "elements and consequently is read-only. It does "
604 "not make sense to call compress() for such "
605 "vectors."));
606
607 // Select which mode to send to Trilinos. Note that we use last_action if
608 // available and ignore what the user tells us to detect wrongly mixed
609 // operations. Typically given_last_action is only used on machines that
610 // do not execute an operation (because they have no own cells for
611 // example).
612 Epetra_CombineMode mode = last_action;
613 if (last_action == Zero)
614 {
615 if (given_last_action == VectorOperation::add)
616 mode = Add;
617 else if (given_last_action == VectorOperation::insert)
618 mode = Insert;
619 else
620 Assert(
621 false,
623 "compress() can only be called with VectorOperation add, insert, or unknown"));
624 }
625 else
626 {
627 Assert(
628 ((last_action == Add) &&
629 (given_last_action == VectorOperation::add)) ||
630 ((last_action == Insert) &&
631 (given_last_action == VectorOperation::insert)),
633 "The last operation on the Vector and the given last action in the compress() call do not agree!"));
634 }
635
636
637 if constexpr (running_in_debug_mode())
638 {
639 // check that every process has decided to use the same mode. This
640 // will otherwise result in undefined behavior in the call to
641 // GlobalAssemble().
642 const double double_mode = mode;
643 const Epetra_MpiComm *comm_ptr = dynamic_cast<const Epetra_MpiComm *>(
644 &(trilinos_partitioner().Comm()));
645 Assert(comm_ptr != nullptr, ExcInternalError());
646
647 const Utilities::MPI::MinMaxAvg result =
648 Utilities::MPI::min_max_avg(double_mode, comm_ptr->GetMpiComm());
649 Assert(result.max == result.min,
651 "Not all processors agree whether the last operation on "
652 "this vector was an addition or a set operation. This will "
653 "prevent the compress() operation from succeeding."));
654 }
655
656 // Now pass over the information about what we did last to the vector.
657 if (nonlocal_vector.get() == nullptr || mode != Add)
658 {
659 const auto ierr = vector->GlobalAssemble(mode);
660 AssertThrow(ierr == 0, ExcTrilinosError(ierr));
661 }
662 else
663 {
664 Epetra_Export exporter(nonlocal_vector->Map(), vector->Map());
665
666 int ierr = vector->Export(*nonlocal_vector, exporter, mode);
667 AssertThrow(ierr == 0, ExcTrilinosError(ierr));
668
669 ierr = nonlocal_vector->PutScalar(0.);
670 AssertThrow(ierr == 0, ExcTrilinosError(ierr));
671 }
672 last_action = Zero;
673
674 compressed = true;
675 }
676
677
678
680 Vector::operator()(const size_type index) const
681 {
682 // Extract local indices in the vector.
683 TrilinosWrappers::types::int_type trilinos_i = vector->Map().LID(
684 static_cast<TrilinosWrappers::types::int_type>(index));
685 TrilinosScalar value = 0.;
686
687 // If the element is not present on the current processor, we can't
688 // continue. This is the main difference to the el() function.
689 if (trilinos_i == -1)
690 {
691# ifndef DEAL_II_WITH_64BIT_INDICES
692 Assert(false,
694 vector->Map().NumMyElements(),
695 vector->Map().MinMyGID(),
696 vector->Map().MaxMyGID()));
697# else
698 Assert(false,
700 vector->Map().NumMyElements(),
701 vector->Map().MinMyGID64(),
702 vector->Map().MaxMyGID64()));
703# endif
704 }
705 else
706 value = (*vector)[0][trilinos_i];
707
708 return value;
709 }
710
711
712
713 void
714 Vector::add(const Vector &v, const bool allow_different_maps)
715 {
716 if (allow_different_maps == false)
717 *this += v;
718 else
719 {
721 AssertThrow(size() == v.size(),
723
724 Epetra_Import data_exchange(vector->Map(), v.vector->Map());
725 const int ierr =
726 vector->Import(*v.vector, data_exchange, Epetra_AddLocalAlso);
727 AssertThrow(ierr == 0, ExcTrilinosError(ierr));
728 last_action = Add;
729 }
730 }
731
732
733
734 bool
736 {
737 Assert(size() == v.size(), ExcDimensionMismatch(size(), v.size()));
738 if (vector->Map().NumMyElements() != v.vector->Map().NumMyElements())
739 return false;
740
741 size_type vector_size = vector->Map().NumMyElements();
742 for (size_type i = 0; i < vector_size; ++i)
743 if ((*(v.vector))[0][i] != (*vector)[0][i])
744 return false;
745
746 return true;
747 }
748
749
750
751 bool
753 {
754 Assert(size() == v.size(), ExcDimensionMismatch(size(), v.size()));
755
756 return (!(*this == v));
757 }
758
759
760
761 bool
763 {
764 const TrilinosScalar *start_ptr = (*vector)[0];
765
766 const bool local_all_zero =
767 std::all_of(start_ptr,
768 start_ptr + locally_owned_size(),
769 numbers::value_is_zero<TrilinosScalar>);
770
771 return Utilities::MPI::logical_and(local_all_zero,
773 }
774
775
776
777 bool
779 {
780 const bool has_negative = std::any_of((*vector)[0],
781 (*vector)[0] + locally_owned_size(),
782 [](const TrilinosScalar &v) {
783 return v < TrilinosScalar();
784 });
785
786 return !Utilities::MPI::logical_or(has_negative, get_mpi_communicator());
787 }
788
789
790
791 void
792 Vector::print(std::ostream &out,
793 const unsigned int precision,
794 const bool scientific,
795 const bool across) const
796 {
797 AssertThrow(out.fail() == false, ExcIO());
798 boost::io::ios_flags_saver restore_flags(out);
799
800
801 out.precision(precision);
802 if (scientific)
803 out.setf(std::ios::scientific, std::ios::floatfield);
804 else
805 out.setf(std::ios::fixed, std::ios::floatfield);
806
807 size_type vector_size = vector->Map().NumMyElements();
808 if (size() != vector_size)
809 {
810 auto global_id = [&](const size_type index) {
811 return gid(vector->Map(), index);
812 };
813 out << "size:" << size()
814 << " locally_stored_size:" << vector->Map().NumMyElements()
815 << " :" << std::endl;
816 for (size_type i = 0; i < vector_size; ++i)
817 out << "[" << global_id(i) << "]: " << (*(vector))[0][i]
818 << std::endl;
819 }
820 else
821 {
822 TrilinosScalar *val;
823 int leading_dimension;
824 int ierr = vector->ExtractView(&val, &leading_dimension);
825
826 AssertThrow(ierr == 0, ExcTrilinosError(ierr));
827 if (across)
828 for (size_type i = 0; i < size(); ++i)
829 out << static_cast<double>(val[i]) << ' ';
830 else
831 for (size_type i = 0; i < size(); ++i)
832 out << static_cast<double>(val[i]) << std::endl;
833 out << std::endl;
834 }
835
836 AssertThrow(out.fail() == false, ExcIO());
837 }
838
839
840
841 void
842 Vector::swap(Vector &v) noexcept
843 {
844 std::swap(last_action, v.last_action);
845 std::swap(compressed, v.compressed);
846 std::swap(has_ghosts, v.has_ghosts);
847 std::swap(vector, v.vector);
848 std::swap(nonlocal_vector, v.nonlocal_vector);
849 std::swap(owned_elements, v.owned_elements);
850 }
851
852
853
854 std::size_t
856 {
857 // TODO[TH]: No accurate memory
858 // consumption for Trilinos vectors
859 // yet. This is a rough approximation with
860 // one index and the value per local
861 // entry.
862 return sizeof(*this) +
863 this->vector->Map().NumMyElements() *
864 (sizeof(double) + sizeof(TrilinosWrappers::types::int_type));
865 }
866
867 // explicit instantiations
868# ifndef DOXYGEN
869# include "lac/trilinos_vector.inst"
870# endif
871 } // namespace MPI
872} // namespace TrilinosWrappers
873
874
875#endif // DEAL_II_WITH_TRILINOS
virtual size_type size() const override
unsigned int n_blocks() const
BlockType & block(const unsigned int i)
bool is_ascending_and_one_to_one(const MPI_Comm communicator) const
size_type size() const
Definition index_set.h:1759
size_type n_elements() const
Definition index_set.h:1917
void set_size(const size_type size)
Definition index_set.h:1747
Epetra_Map make_trilinos_map(const MPI_Comm communicator=MPI_COMM_WORLD, const bool overlapping=false) const
void clear()
Definition index_set.h:1735
void subtract_set(const IndexSet &other)
Definition index_set.cc:496
void add_indices(const ForwardIterator &begin, const ForwardIterator &end)
Definition index_set.h:1814
size_type size() const override
const IndexSet & get_stored_elements() const
void compress(VectorOperation::values operation)
void add(const std::vector< size_type > &indices, const std::vector< TrilinosScalar > &values)
std::unique_ptr< Epetra_MultiVector > nonlocal_vector
void import_elements(const LinearAlgebra::ReadWriteVector< double > &rwv, const VectorOperation::values operation)
MPI_Comm get_mpi_communicator() const
void swap(Vector &v) noexcept
void reinit(const Vector &v, const bool omit_zeroing_entries=false)
const Epetra_BlockMap & trilinos_partitioner() const
reference operator()(const size_type index)
void import_nonlocal_data_for_fe(const ::TrilinosWrappers::SparseMatrix &matrix, const Vector &vector)
std::unique_ptr< Epetra_FEVector > vector
size_type size() const override
void print(std::ostream &out, const unsigned int precision=3, const bool scientific=true, const bool across=true) const
IndexSet locally_owned_elements() const
std::pair< size_type, size_type > local_range() const
bool operator!=(const Vector &v) const
bool operator==(const Vector &v) const
size_type locally_owned_size() const
Vector & operator=(const TrilinosScalar s)
std::size_t memory_consumption() const
const Epetra_CrsMatrix & trilinos_matrix() const
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_DISABLE_EXTRA_DIAGNOSTICS
Definition config.h:636
constexpr bool running_in_debug_mode()
Definition config.h:76
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
#define DEAL_II_ENABLE_EXTRA_DIAGNOSTICS
Definition config.h:680
static ::ExceptionBase & ExcIO()
static ::ExceptionBase & ExcGhostsPresent()
static ::ExceptionBase & ExcNotImplemented()
static ::ExceptionBase & ExcAccessToNonLocalElement(size_type arg1, size_type arg2, size_type arg3, size_type arg4)
#define Assert(cond, exc)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcTrilinosError(int arg1)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
void swap(BlockVector &u, BlockVector &v) noexcept
TrilinosWrappers::types::int_type global_length(const Epetra_MultiVector &vector)
int gid(const Epetra_BlockMap &map, int i)
TrilinosWrappers::types::int_type * my_global_elements(const Epetra_BlockMap &map)
TrilinosWrappers::types::int64_type n_global_elements(const Epetra_BlockMap &map)
T sum(const T &t, const MPI_Comm mpi_communicator)
bool logical_and(const bool t, const MPI_Comm mpi_communicator)
T logical_or(const T &t, const MPI_Comm mpi_communicator)
unsigned int n_mpi_processes(const MPI_Comm mpi_communicator)
Definition mpi.cc:103
MinMaxAvg min_max_avg(const double my_value, const MPI_Comm mpi_communicator)
Definition mpi.cc:77
double TrilinosScalar
Definition types.h:188