FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
alg_dof_parti_system.hpp
1// FEAT3: Finite Element Analysis Toolbox, Version 3
2// Copyright (C) 2010 by Stefan Turek & the FEAT group
3// FEAT3 is released under the GNU General Public License version 3,
4// see the file 'copyright.txt' in the top level directory for details.
5
6#pragma once
7
8#include <kernel/adjacency/dynamic_graph.hpp>
9#include <kernel/global/alg_dof_parti.hpp>
10#include <kernel/global/filter.hpp>
11#include <kernel/global/matrix.hpp>
12#include <kernel/lafem/null_matrix.hpp>
13#include <kernel/lafem/sparse_matrix_csr.hpp>
14#include <kernel/lafem/sparse_matrix_bcsr.hpp>
15#include <kernel/lafem/saddle_point_matrix.hpp>
16#include <kernel/lafem/tuple_matrix.hpp>
17#include <kernel/lafem/unit_filter.hpp>
18#include <kernel/lafem/unit_filter_blocked.hpp>
19#include <kernel/lafem/mean_filter.hpp>
20#include <kernel/lafem/mean_filter_blocked.hpp>
21#include <kernel/lafem/none_filter.hpp>
22#include <kernel/lafem/slip_filter.hpp>
23#include <kernel/lafem/filter_chain.hpp>
24#include <kernel/lafem/filter_sequence.hpp>
25#include <kernel/lafem/sparse_vector_factory.hpp>
26#include <kernel/lafem/tuple_filter.hpp>
27#include <kernel/global/mean_filter.hpp>
28#include <kernel/lafem/matrix_mirror.hpp>
29
30#include <algorithm>
31
32namespace FEAT
33{
34 namespace Global
35 {
37 namespace Intern
38 {
40 template<typename Matrix_>
41 class ADPDOMM;
42
44 template<typename Matrix_>
45 class ADPMatAux;
46
48 template<typename Filter_>
49 class ADPFilAux;
50 }
52
134 template<typename LocalMatrix_, typename LocalFilter_, typename Mirror_>
136 {
137 public:
139 typedef typename LocalMatrix_::DataType DataType;
141 typedef typename LocalMatrix_::IndexType IndexType;
142
144 typedef LocalMatrix_ LocalMatrixType;
146 typedef Mirror_ MirrorType;
149
151 typedef typename LocalMatrixType::VectorTypeR LocalVectorType;
152
154 typedef LocalFilter_ LocalFilterType;
155
158
163
166
169
172
176 typedef Intern::ADPDOMM<LocalMatrixType> OwnerMirrorType;
177
178 typedef Intern::ADPMatAux<LocalMatrixType> ADPMatAuxType;
179 typedef Intern::ADPFilAux<LocalFilterType> ADPFilAuxType;
180
181 //protected:
186
188 std::shared_ptr<AlgDofPartiType> _alg_dof_parti;
189
191 std::shared_ptr<Adjacency::Graph> _owned_graph;
192
195
198
200 std::vector<BufferMatrixType> _donee_bufs;
201 std::vector<BufferMatrixType> _owner_bufs;
202
204 std::vector<DoneeMirrorType> _donee_data_mirs;
205 std::vector<OwnerMirrorType> _owner_data_mirs;
206
209
212
213 public:
223 explicit AlgDofPartiSystem(const GlobalMatrixType& matrix, const GlobalFilterType& filter) :
224 _global_matrix(matrix),
225 _global_filter(filter),
227 _owned_graph(),
230 {
231 }
232
245 explicit AlgDofPartiSystem(const GlobalMatrixType& matrix, const GlobalFilterType& filter,
246 std::shared_ptr<AlgDofPartiType> adp) :
247 _global_matrix(matrix),
248 _global_filter(filter),
249 _alg_dof_parti(adp),
250 _owned_graph(),
253 {
254 }
255
260
262 std::size_t bytes() const
263 {
264 std::size_t r = 0u;
265 if(this->_alg_dof_parti)
266 r += this->_alg_dof_parti->bytes();
267 if(this->_owned_graph)
268 r += this->_owned_graph->bytes();
269 for(const auto& x : this->_donee_bufs)
270 r += x.bytes();
271 for(const auto& x : this->_owner_bufs)
272 r += x.bytes();
273 for(const auto& x : this->_donee_data_mirs)
274 r += x.bytes();
275 for(const auto& x : this->_owner_data_mirs)
276 r += x.bytes();
277 r += _owned_data_mir.bytes();
279 return r;
280 }
281
289 std::shared_ptr<AlgDofPartiType> get_alg_dof_parti()
290 {
291 return this->_alg_dof_parti;
292 }
293
296 {
297 return this->_alg_dof_parti->get_num_owned_dofs();
298 }
299
302 {
303 return this->_alg_dof_parti->get_num_global_dofs();
304 }
305
308 {
309 return this->_alg_dof_parti->get_global_dof_offset();
310 }
311
314 {
315 return this->_alg_dof_parti->get_num_owned_dofs();
316 }
317
320 {
321 return this->_alg_dof_parti->get_num_owned_dofs();
322 }
323
326 {
327 return this->_alg_dof_parti->get_num_global_dofs();
328 }
329
332 {
333 return this->_num_owned_non_zeros;
334 }
335
338 {
339 return this->_num_global_non_zeros;
340 }
341
343 const Dist::Comm* get_comm() const
344 {
345 XASSERT(this->_alg_dof_parti != nullptr);
346 return this->_alg_dof_parti->get_comm();
347 }
348
359 template<typename DTV_>
360 void upload_vector(DTV_* val, const LocalVectorType& vector)
361 {
362 XASSERT(this->_alg_dof_parti != nullptr);
363 this->_alg_dof_parti->upload_vector(val, vector);
364 }
365
377 template<typename DTV_>
378 void download_vector(LocalVectorType& vector, const DTV_* val)
379 {
380 XASSERT(this->_alg_dof_parti != nullptr);
381 this->_alg_dof_parti->download_vector(val, vector);
382 }
383
404 template<typename DTX_, typename RPT_, typename CIT_>
405 void apply(DTX_* vec_r, const DTX_* vec_x, const DTX_* val_a, const RPT_* row_ptr, const CIT_* col_idx) const
406 {
407 XASSERTM(!this->_alg_dof_parti->get_all_global_dof_counts().empty(),
408 "You did not ask to assemble the required AlgDofParti allgather data");
409
410 // create and gather full multiplicand vector
411 std::vector<DTX_> vec_full(this->_alg_dof_parti->get_num_global_dofs());
412 this->get_comm()->allgatherv(vec_x,
413 this->_alg_dof_parti->get_num_owned_dofs(),
414 vec_full.data(),
415 this->_alg_dof_parti->get_all_global_dof_counts().data(),
416 this->_alg_dof_parti->get_all_global_dof_offsets().data());
417
418 // apply our owned matrix
419 LAFEM::Arch::MatVecMultCSRDense::exec_generic_impl(vec_r, DTX_(1), vec_full.data(), (DTX_*)nullptr, val_a, col_idx, row_ptr,
420 this->get_adp_matrix_rows(), this->get_adp_matrix_cols(), this->get_adp_matrix_nzes(), false);
421 }
422
431 {
432 if(this->_alg_dof_parti == nullptr)
433 {
434 this->_alg_dof_parti = std::make_shared<AlgDofPartiType>();
435 this->_alg_dof_parti->assemble_by_gate(*this->_global_matrix.get_row_gate());
436 }
437
438 this->_assemble_buffers();
439 this->_assemble_structure();
441 }
442
467 template<typename RPT_, typename CIT_>
468 void upload_matrix_symbolic(RPT_* row_ptr, CIT_* col_idx, bool keep_graph = false)
469 {
470 XASSERT(row_ptr != nullptr);
471 XASSERT(col_idx != nullptr);
472 XASSERT(this->_owned_graph != nullptr);
473
474 // maximum allowed row-pointer/column index values assuming signed int types
475 static constexpr std::uint64_t max_rpt = 1ull << (8*sizeof(RPT_) - 1);
476 static constexpr std::uint64_t max_cit = 1ull << (8*sizeof(CIT_) - 1);
477
478 // prevent "unused variable" warnings in non-debug builds
479 (void)max_rpt;
480 (void)max_cit;
481
482 const Index* dom_ptr = this->_owned_graph->get_domain_ptr();
483 const Index* img_idx = this->_owned_graph->get_image_idx();
484
485 const Index n = this->_owned_graph->get_num_nodes_domain();
486 FEAT_PRAGMA_OMP(parallel for)
487 for(Index i = 0u; i <= n; ++i)
488 {
489 ASSERTM(std::uint64_t(dom_ptr[i]) < max_rpt, "row-pointer exceeds RPT_ type range!");
490 row_ptr[i] = RPT_(dom_ptr[i]);
491 }
492
493 const Index m = this->_owned_graph->get_num_indices();
494 FEAT_PRAGMA_OMP(parallel for)
495 for(Index j = 0; j < m; ++j)
496 {
497 ASSERTM(std::uint64_t(img_idx[j]) < max_cit, "column-index exceeds CIT_ type range!");
498 col_idx[j] = CIT_(img_idx[j]);
499 }
500
501 // release owned graph
502 if(!keep_graph)
503 this->_owned_graph.reset();
504 }
505
523 template<typename DTA_, typename RPT_, typename CIT_>
524 void upload_matrix_numeric(DTA_* val, const RPT_* row_ptr, const CIT_* col_idx)
525 {
526 this->upload_matrix_numeric(val, row_ptr, col_idx, this->_global_matrix.local());
527 }
528
552 template<typename DTA_, typename RPT_, typename CIT_>
553 void upload_matrix_numeric(DTA_* val, const RPT_* DOXY(row_ptr), const CIT_* DOXY(col_idx), const LocalMatrixType& matrix)
554 {
555 XASSERT(this->_alg_dof_parti != nullptr);
556
557 // get our partitioning
558 const AlgDofPartiType& adp = *this->_alg_dof_parti;
559
560 // get our communicator
561 const Dist::Comm& comm = *this->get_comm();
562
563 // format our internal matrix
564 Memory::memset_main(val, 0, sizeof(DTA_)*this->_num_owned_non_zeros);
565
566 const Index num_neigh_owner = adp.get_num_owner_neighbors();
567 const Index num_neigh_donee = adp.get_num_donee_neighbors();
568
569 Dist::RequestVector recv_reqs(num_neigh_donee);
570 Dist::RequestVector send_reqs(num_neigh_owner);
571
572 std::vector<BufferVectorType> donee_vbufs(num_neigh_donee);
573 std::vector<BufferVectorType> owner_vbufs(num_neigh_owner);
574
575 std::vector<Memory::TypedView<DataType>> donee_views(num_neigh_donee);
576 std::vector<Memory::TypedView<DataType>> owner_views(num_neigh_owner);
577
578 // create receive buffers and post receives
579 for(Index i(0); i < num_neigh_donee; ++i)
580 {
581 // create buffer
582 BufferVectorType& buf = donee_vbufs.at(i);
583 buf = BufferVectorType(this->_donee_data_mirs.at(i).num_indices());
584 donee_views.at(i) = buf.elements_view_w();
585
586 // post receive
587 recv_reqs[i] = comm.irecv(donee_views.at(i).get_w(), buf.size(), adp.get_donee_rank(i));
588 }
589
590 // post sends
591 for(Index i(0); i < num_neigh_owner; ++i)
592 {
593 // create buffer
594 BufferVectorType& buf = owner_vbufs.at(i);
595 buf = BufferVectorType(this->_owner_data_mirs.at(i).num_indices(), DataType(0));
596
597 // gather from mirror
598 this->_owner_data_mirs.at(i).gather_owner_data(buf, matrix);
599 owner_views.at(i) = buf.elements_view_r();
600
601 // post send
602 send_reqs[i] = comm.isend(owner_views.at(i).get_r(), buf.size(), adp.get_owner_rank(i));
603 }
604
605 // upload our own data
606 this->_owned_data_mir.upload_owned_data(val, matrix);
607
608 // process all pending receives
609 for(std::size_t idx(0u); recv_reqs.wait_any(idx); )
610 {
611 // scatter from buffer
612 donee_views.at(idx).release();
613 this->_scatter_donee_data(val, donee_vbufs.at(idx), this->_donee_data_mirs.at(idx));
614 }
615
616 // wait for all sends to finish
617 send_reqs.wait_all();
618 }
619
622 {
623 upload_filter(this->_global_filter.local());
624 }
625
632 void upload_filter(const LocalFilterType& filter)
633 {
635 ADPFilAuxType::upload_filter(factory, filter, _alg_dof_parti->get_owned_mirror() ,0u);
636 _unit_filter_rows.get_filter_vector() = factory.make_sv();
637 }
638
645 template<typename DTV_>
646 void filter_vec_def(DTV_* vec_def)//, Memory::Location mem_loc)
647 {
649 return;
650
651 XASSERT(vec_def != nullptr);
652
653 LAFEM::Arch::UnitFilterDenseVec::exec_generic_impl(vec_def, (DTV_*)nullptr,
654 _unit_filter_rows.get_filter_vector().indices_view_r(Memory::Location::main).get_r(),
656 }
657
664 template<typename DTV_>
665 void filter_vec_cor(DTV_* vec_cor)
666 {
668 return;
669
670 XASSERT(vec_cor != nullptr);
671
672 LAFEM::Arch::UnitFilterDenseVec::exec_generic_impl(vec_cor, (DTV_*)nullptr,
673 _unit_filter_rows.get_filter_vector().indices_view_r(Memory::Location::main).get_r(),
675 }
676
691 template<typename DTA_, typename RPT_, typename CIT_>
692 void filter_matrix(DTA_* val, const RPT_* row_ptr, const CIT_* col_idx)
693 {
695 return;
696
697 XASSERT(val != nullptr);
698 XASSERT(row_ptr != nullptr);
699 XASSERT(col_idx != nullptr);
700
701 const Index row_off = this->get_alg_dof_parti()->get_global_dof_offset();
702 const Memory::TypedView<IndexType> row_idx = this->_unit_filter_rows.get_filter_vector().indices_view_r();
703 const Index n = this->_unit_filter_rows.num_nzes();
704
705 // process all filtered rows
706 for(Index i = 0; i < n; ++i)
707 {
708 const Index row = row_off + row_idx[i];
709 RPT_ j = row_ptr[row_idx[i]];
710 const RPT_ j_end = row_ptr[row_idx[i]+1];
711 for(; j < j_end; ++j)
712 {
713 val[j] = DTA_(row == Index(col_idx[j]) ? 1 : 0);
714 }
715 }
716 }
717
721
722 protected:
727 const LocalMatrixType& local_matrix,
728 const MirrorType& row_mirror,
729 const IndexVectorType& global_dof_idx,
730 const Index num_global_dofs)
731 {
732 // compute number of rows of matrix buffers
733 Index num_buf_rows = ADPMatAuxType::calc_mat_buf_num_rows(local_matrix, row_mirror);
734
735 // allocate a temporary array
736 std::vector<IndexType> aux_row(std::size_t(num_buf_rows+1u), IndexType(0));
737
738 // count number of non-zeros per row
739 ADPMatAuxType::calc_mat_buf_row_nze(aux_row.data(), local_matrix, row_mirror);
740
741 // build buffer row pointer by exclusive scan
742 feat_omp_ex_scan(std::size_t(num_buf_rows+1u), aux_row.data(), aux_row.data());
743 IndexType num_buf_nze = aux_row.back();
744
745 // allocate buffer
746 BufferMatrixType buffer(num_buf_rows, num_global_dofs, num_buf_nze, 1);
747 Memory::TypedView<IndexType> buf_row_ptr = buffer.row_ptr_view_w();
748 Memory::TypedView<IndexType> buf_col_idx = buffer.col_idx_view_w();
749
750 // copy buffer row pointer because we need a disposable copy for the next operation
751 for(Index i = 0u; i <= num_buf_rows; ++i)
752 buf_row_ptr[i] = aux_row[i];
753
754 // gather the column indices
755 // we have to use the auxiliary row pointer here because it is overwritten by the following call
756 ADPMatAuxType::gather_mat_buf_col_idx(aux_row.data(), buf_col_idx.get_w(), local_matrix, row_mirror, global_dof_idx);
757
758 // sort the buffer column indices; this will make things a lot easier and more efficient later on
759 for(Index i = 0u; i < num_buf_rows; ++i)
760 {
761 std::sort(&buf_col_idx[buf_row_ptr[i]], &buf_col_idx[buf_row_ptr[i+1]]);
762 }
763
764 // okay
765 return buffer;
766 }
767
769
774 {
775 // get our partitioning
776 const AlgDofPartiType& adp = *this->_alg_dof_parti;
777
778 // get out communicator
779 const Dist::Comm& comm = *this->get_comm();
780
781 // get number of neighbors and allocate buffer vectors
782 const Index num_neigh_owner = adp.get_num_owner_neighbors();
783 const Index num_neigh_donee = adp.get_num_donee_neighbors();
784 _owner_bufs.resize(num_neigh_owner);
785 _donee_bufs.resize(num_neigh_donee);
786
787 // allocate owner views
788 std::vector<Memory::TypedView<IndexType>> owner_row_ptr_views(num_neigh_owner);
789 std::vector<Memory::TypedView<IndexType>> owner_col_idx_views(num_neigh_owner);
790
791 // create the owner buffers by using the auxiliary helper function.
792 for(Index i(0); i < num_neigh_owner; ++i)
793 {
794 // allocate matrix buffer
795 this->_owner_bufs.at(i) = _asm_mat_buf(this->_global_matrix.local(),
797
798 // create views for row-pointer and column-indices
799 owner_row_ptr_views.at(i) = this->_owner_bufs.at(i).row_ptr_view_r();
800 owner_col_idx_views.at(i) = this->_owner_bufs.at(i).col_idx_view_r();
801 }
802
803 // We have assembled our owner-neighbor matrix buffers, however, we cannot
804 // assemble the donee-neighbor matrix buffers on our own. Instead, each owner
805 // neighbor has to receive its donee-buffers from its donee-neighbors, because
806 // only the donee knows the matrix layout of those buffers.
807 // Yes, this is brain-twisting, but believe me, it cannot be realized otherwise.
808
809 // Note:
810 // The following code is effectively just copy-&-paste from the SynchMatrix::init()
811 // function, as the same buffer problem also arises when converting global type-0
812 // matrices to local type-1 matrices.
813
814 Dist::RequestVector send_reqs(num_neigh_owner);
815 Dist::RequestVector recv_reqs(num_neigh_donee);
816
817 // receive buffer dimensions vector
818 std::vector<std::array<Index,4>> send_dims(num_neigh_owner);
819 std::vector<std::array<Index,4>> recv_dims(num_neigh_donee);
820
821 // post send-buffer dimension receives
822 for(Index i(0); i < num_neigh_donee; ++i)
823 {
824 recv_reqs[i] = comm.irecv(recv_dims.at(i).data(), std::size_t(4), adp.get_donee_rank(i));
825 }
826
827 // send owner-buffer dimensions
828 for(Index i(0); i < num_neigh_owner; ++i)
829 {
830 const BufferMatrixType& sbuf = this->_owner_bufs.at(i);
831 send_dims.at(i)[0] = Index(sbuf.num_rows());
832 send_dims.at(i)[1] = Index(sbuf.num_cols());
833 send_dims.at(i)[2] = Index(sbuf.entries_per_nonzero());
834 send_dims.at(i)[3] = Index(sbuf.num_nzes());
835 send_reqs[i] = comm.isend(send_dims.at(i).data(), std::size_t(4), adp.get_owner_rank(i));
836 }
837
838 // wait for all receives to finish
839 recv_reqs.wait_all();
840
841 // allocate donee views
842 std::vector<Memory::TypedView<IndexType>> donee_row_ptr_views(num_neigh_donee);
843 std::vector<Memory::TypedView<IndexType>> donee_col_idx_views(num_neigh_donee);
844
845 // allocate donee-buffers
846 for(Index i(0); i < num_neigh_donee; ++i)
847 {
848 // get the receive buffer dimensions
849 Index nrows = recv_dims.at(i)[0];
850 Index ncols = recv_dims.at(i)[1];
851 Index nepnz = recv_dims.at(i)[2];
852 Index nnze = recv_dims.at(i)[3];
853
854 // allocate receive buffer
855 this->_donee_bufs.at(i) = BufferMatrixType(nrows, ncols, nnze, nepnz);
856
857 // create views for row-pointer and column-indices
858 donee_row_ptr_views.at(i) = this->_donee_bufs.at(i).row_ptr_view_w();
859 donee_col_idx_views.at(i) = this->_donee_bufs.at(i).col_idx_view_w();
860 }
861
862 // post donee-buffer row-pointer array receives
863 for(Index i(0); i < num_neigh_donee; ++i)
864 {
865 recv_reqs[i] = comm.irecv(donee_row_ptr_views.at(i).get_w(),
866 this->_donee_bufs.at(i).num_rows()+std::size_t(1), adp.get_donee_rank(i));
867 }
868
869 // wait for all previous sends to finish
870 send_reqs.wait_all();
871
872 // post owner-buffer row-pointer array sends
873 for(Index i(0); i < num_neigh_owner; ++i)
874 {
875 send_reqs[i] = comm.isend(owner_row_ptr_views.at(i).get_r(),
876 this->_owner_bufs.at(i).num_rows()+std::size_t(1), adp.get_owner_rank(i));
877 }
878
879 // wait for all previous receives to finish
880 recv_reqs.wait_all();
881
882 // post donee-buffer column-index array receives
883 for(Index i(0); i < num_neigh_donee; ++i)
884 {
885 recv_reqs[i] = comm.irecv(donee_col_idx_views.at(i).get_w(),
886 this->_donee_bufs.at(i).num_nzes(), adp.get_donee_rank(i));
887 }
888
889 // wait for all previous sends to finish
890 send_reqs.wait_all();
891
892 // post owner-buffer column-index array sends
893 for(Index i(0); i < num_neigh_owner; ++i)
894 {
895 send_reqs[i] = comm.isend(owner_col_idx_views.at(i).get_r(),
896 this->_owner_bufs.at(i).num_nzes(), adp.get_owner_rank(i));
897 }
898
899 // wait for all receives and sends to finish
900 recv_reqs.wait_all();
901 send_reqs.wait_all();
902 }
903
908 {
909 // get our partitioning
910 const AlgDofPartiType& adp = *this->_alg_dof_parti;
911
912 // get our matrix dimensions:
913 // * each row of our matrix corresponds to one owned DOF
914 // * each column corresponds to one global DOF
915 const Index num_rows = adp.get_num_owned_dofs();
916 const Index num_cols = adp.get_num_global_dofs();
917
918 // Unfortunately, assembling the matrix structure is not that easy,
919 // because it is a union of our owned matrix structure and all of
920 // our donee matrix buffers. We don't have a chance to determine how
921 // many duplicate (i,j) pairs we will encounter here, so we use the
922 // DynamicGraph class here to keep things simple.
923
924 // create a dynamic graph for our matrix
925 Adjacency::DynamicGraph dynamic_graph(num_rows, num_cols);
926
927 // gather the owned rows for to obtain the initial structure
928 ADPMatAuxType::gather_owned_struct(dynamic_graph, this->_global_matrix.local(),
930
931 // process all donee-neighbor buffers
932 const Index num_neigh_donee = adp.get_num_donee_neighbors();
933 for(Index ineigh(0); ineigh < num_neigh_donee; ++ineigh)
934 {
935 // get the mirror and the matrix buffer of that donee neighbor
936 // note: the donee mirror indices are owned DOF indices
937 const auto& mir = adp.get_donee_mirror(ineigh);
938 const BufferMatrixType& buf = this->_donee_bufs.at(ineigh);
939 XASSERT(mir.num_indices() == buf.num_rows());
940 const Index num_idx = mir.num_indices();
941 const Memory::TypedView<IndexType> mir_idx = mir.indices_view_r();
942 const Memory::TypedView<IndexType> buf_ptr = buf.row_ptr_view_r();
943 const Memory::TypedView<IndexType> buf_idx = buf.col_idx_view_r();
944
945 // loop over all matrix buffer rows
946 for(Index i(0); i < num_idx; ++i)
947 {
948 // the owned DOF index of our the buffer matrix row
949 const IndexType row = mir_idx[i];
950
951 // loop over all buffer indices
952 for(IndexType j(buf_ptr[i]); j < buf_ptr[i + 1]; ++j)
953 {
954 // insert entry into our local matrix
955 dynamic_graph.insert(row, buf_idx[j]);
956 }
957 }
958 }
959
960 // store number of non-zero entries
961 this->_num_owned_non_zeros = dynamic_graph.get_num_indices();
962 this->get_comm()->allreduce(&this->_num_owned_non_zeros, &this->_num_global_non_zeros, std::size_t(1), Dist::op_sum);
963
964 // render into a standard graph
965 this->_owned_graph = std::make_shared<Adjacency::Graph>(Adjacency::RenderType::as_is, dynamic_graph);
966 dynamic_graph.clear();
967 }
968
973 DoneeMirrorType& data_mirror,
974 const Adjacency::Graph& owned_graph,
975 const DoneeMirrorType& mirror,
976 const BufferMatrixType& buffer)
977 {
978 const Index buf_rows = buffer.num_rows();
979 const Index num_idx = buffer.num_nzes();
980 const Memory::TypedView<IndexType> row_idx = mirror.indices_view_r();
981 const Memory::TypedView<IndexType> buf_ptr = buffer.row_ptr_view_r();
982 const Memory::TypedView<IndexType> buf_idx = buffer.col_idx_view_r();
983 const Index* row_ptr = owned_graph.get_domain_ptr();
984 const Index* col_idx = owned_graph.get_image_idx();
985
986 // allocate data mirror
987 data_mirror = DoneeMirrorType(owned_graph.get_num_indices(), num_idx);
988 Memory::TypedView<IndexType> dat_idx = data_mirror.indices_view_w();
989
990 // loop over all buffer matrix rows
991 for(Index i(0); i < buf_rows; ++i)
992 {
993 IndexType j = buf_ptr[i];
994 const IndexType j_end = buf_ptr[i + 1];
995 Index k = row_ptr[row_idx[i]];
996 const Index k_end = row_ptr[row_idx[i] + 1];
997
998 // loop over local matrix and buffer matrix row in a merge-style fashion
999 while((j < j_end) && (k < k_end))
1000 {
1001 if(buf_idx[j] < col_idx[k])
1002 ++j;
1003 else if(buf_idx[j] > col_idx[k])
1004 ++k;
1005 else
1006 {
1007 dat_idx[j] = IndexType(k);
1008 ++j;
1009 ++k;
1010 }
1011 }
1012 }
1013 }
1014
1024 {
1025 // get our partitioning
1026 const AlgDofPartiType& adp = *this->_alg_dof_parti;
1027
1028 // assemble donee data mirrors
1029 this->_donee_data_mirs.resize(this->_donee_bufs.size());
1030 for(Index i(0); i < this->_donee_bufs.size(); ++i)
1031 _asm_neighbor_donee_data_mir(this->_donee_data_mirs.at(i), *this->_owned_graph,
1032 adp.get_donee_mirror(i), this->_donee_bufs.at(i));
1033
1034 // assemble owner data mirrors
1035 this->_owner_data_mirs.resize(this->_owner_bufs.size());
1036 for(Index i(0); i < this->_owner_bufs.size(); ++i)
1037 this->_owner_data_mirs.at(i).asm_neighbor_owner_data_mir(this->_global_matrix.local(),
1038 adp.get_owner_mirror(i), this->_owner_bufs.at(i),
1039 adp.get_global_dof_indices(), Index(0));
1040
1041 // assemble our owned data mirror
1042 this->_owned_data_mir.asm_owned_data_mir(this->_global_matrix.local(), *this->_owned_graph,
1044 }
1045
1049 template<typename DTA_>
1050 static void _scatter_donee_data(DTA_* adp_val, const BufferVectorType& buffer,
1051 const DoneeMirrorType& data_mirror)
1052 {
1053 XASSERT(buffer.size() == data_mirror.num_indices());
1054
1055 const Memory::TypedView<DataType> buf_val = buffer.elements_view_r();
1056 const Memory::TypedView<IndexType> mir_idx = data_mirror.indices_view_r();
1057 const Index n = buffer.size();
1058 for(Index i(0); i < n; ++i)
1059 {
1060 adp_val[mir_idx[i]] += DTA_(buf_val[i]);
1061 }
1062 }
1063 }; // class AlgDofPartiSystem<...>
1064
1070
1072 namespace Intern
1073 {
1074 template<typename DT_, typename IT_>
1075 class ADPDOMM<LAFEM::SparseMatrixCSR<DT_, IT_>>
1076 {
1077 public:
1078 LAFEM::VectorMirror<DT_, IT_> _buf_mir, _loc_mir;
1079
1080 Index num_indices() const
1081 {
1082 return _buf_mir.num_indices();
1083 }
1084
1085 Index buf_size() const
1086 {
1087 return _buf_mir.size();
1088 }
1089
1090 Index loc_size() const
1091 {
1092 return _loc_mir.size();
1093 }
1094
1095 String dump() const
1096 {
1097 String s;
1098 XASSERT(_buf_mir.num_indices() == _loc_mir.num_indices());
1099 const Memory::TypedView<IT_> buf_idx = _buf_mir.indices_view_r();
1100 const Memory::TypedView<IT_> loc_idx = _loc_mir.indices_view_r();
1101 for(Index i = 0; i < _buf_mir.num_indices(); ++i)
1102 s += " " + stringify(buf_idx[i]) + ":" + stringify(loc_idx[i]);
1103 return "[" + s + "]*" + stringify(_buf_mir.num_indices());
1104 }
1105
1122 Index asm_neighbor_owner_data_mir(
1123 const LAFEM::SparseMatrixCSR<DT_, IT_>& local_matrix,
1124 const LAFEM::VectorMirror<DT_, IT_>& row_mirror,
1125 const LAFEM::MatrixMirrorBuffer<DT_, IT_>& buffer,
1126 const LAFEM::DenseVector<IT_, IT_>& global_dof_idx,
1127 Index row_offset)
1128 {
1129 // get our mirror and matrix arrays
1130 const Memory::TypedView<IT_> row_idx = row_mirror.indices_view_r();
1131 const Memory::TypedView<IT_> row_ptr = local_matrix.row_ptr_view_r();
1132 const Memory::TypedView<IT_> col_idx = local_matrix.col_idx_view_r();
1133 const Memory::TypedView<IT_> buf_ptr = buffer.row_ptr_view_r();
1134 const Memory::TypedView<IT_> buf_idx = buffer.col_idx_view_r();
1135 const Memory::TypedView<IT_> glob_dof_idx = global_dof_idx.elements_view_r();
1136 const Index row_mir_num_idx = row_mirror.num_indices();
1137
1138 // count the number of non-zeros that this matrix contributes to the buffer
1139 Index data_mir_num_idx = 0u;
1140 for(Index i = 0; i < row_mir_num_idx; ++i)
1141 data_mir_num_idx += row_ptr[row_idx[i]+1u] - row_ptr[row_idx[i]];
1142
1143 XASSERT(data_mir_num_idx <= buffer.num_nzes());
1144
1145 // allocate data mirror
1146 std::vector<std::pair<IT_, IT_>> aux_data_mir;
1147 aux_data_mir.reserve(data_mir_num_idx);
1148
1149 // vector for row pointers sorted by global indices
1150 std::vector<IT_> loc_it;
1151 loc_it.reserve(local_matrix.num_cols());
1152
1153 // declare a lambda that sorts row pointers by global column indices
1154 auto sort_rel_loc = [&glob_dof_idx, &col_idx] (IT_ a, IT_ b)
1155 {
1156 return glob_dof_idx[col_idx[a]] < glob_dof_idx[col_idx[b]];
1157 };
1158
1159 // loop over all buffer matrix rows
1160 for(Index i(0); i < row_mir_num_idx; ++i)
1161 {
1162 // get local matrix row index
1163 IT_ j = buf_ptr[row_offset + i];
1164 const IT_ j_end = buf_ptr[row_offset + i + 1];
1165 const IT_ k_beg = row_ptr[row_idx[i]];
1166 const IT_ k_end = row_ptr[row_idx[i] + 1];
1167 loc_it.clear();
1168 for(IT_ k = k_beg; k < k_end; ++k)
1169 loc_it.push_back(k);
1170 std::sort(loc_it.begin(), loc_it.end(), sort_rel_loc);
1171
1172 auto kit = loc_it.begin();
1173
1174 // loop over local matrix and buffer matrix row in a merge-style fashion
1175 while((j < j_end) && (kit != loc_it.end()))
1176 {
1177 if(buf_idx[j] < glob_dof_idx[col_idx[*kit]])
1178 ++j;
1179 else if(buf_idx[j] > glob_dof_idx[col_idx[*kit]])
1180 ++kit;
1181 else
1182 {
1183 aux_data_mir.push_back(std::make_pair(j, *kit));
1184 ++j;
1185 ++kit;
1186 }
1187 }
1188 }
1189
1190 // create data mirrors
1191 Index num_idx = Index(aux_data_mir.size());
1192 this->_buf_mir = LAFEM::VectorMirror<DT_, IT_>(buffer.num_nzes(), num_idx);
1193 this->_loc_mir = LAFEM::VectorMirror<DT_, IT_>(
1194 local_matrix.num_nzes_raw(), num_idx);
1195
1196 Memory::TypedView<IT_> bm_idx = this->_buf_mir.indices_view_w();
1197 Memory::TypedView<IT_> lm_idx = this->_loc_mir.indices_view_w();
1198 for(Index i = 0; i < num_idx; ++i)
1199 {
1200 bm_idx[i] = aux_data_mir[i].first;
1201 lm_idx[i] = aux_data_mir[i].second;
1202 }
1203
1204 return row_mir_num_idx;
1205 }
1206
1220 Index asm_owned_data_mir(
1221 const LAFEM::SparseMatrixCSR<DT_, IT_>& local_matrix,
1222 const Adjacency::Graph& owned_graph,
1223 const LAFEM::VectorMirror<DT_, IT_>& row_mirror,
1224 const LAFEM::DenseVector<IT_, IT_>& global_dof_idx,
1225 Index row_offset)
1226 {
1227 // get matrix arrays
1228 const Index* own_row_ptr = owned_graph.get_domain_ptr();
1229 const Index* own_col_idx = owned_graph.get_image_idx();
1230 const Memory::TypedView<IT_> loc_row_ptr = local_matrix.row_ptr_view_r();
1231 const Memory::TypedView<IT_> loc_col_idx = local_matrix.col_idx_view_r();
1232
1233 // allocate data mirror
1234 std::vector<std::pair<IT_, IT_>> aux_data_mir;
1235 aux_data_mir.reserve(owned_graph.get_num_indices());
1236
1237 const Index num_owned_dofs = row_mirror.num_indices();
1238 const Memory::TypedView<IT_> loc_dof_idx = row_mirror.indices_view_r();
1239 const Memory::TypedView<IT_> glob_dof_idx = global_dof_idx.elements_view_r();
1240
1241 //XASSERT(num_owned_dofs == adp_matrix.num_rows());
1242
1243 // row iterator deque
1244 std::deque<IT_> row_it;
1245
1246 // declare a lambda that sorts row pointers by global column indices
1247 auto sort_rel = [&glob_dof_idx, &loc_col_idx] (IT_ a, IT_ b)
1248 {
1249 return glob_dof_idx[loc_col_idx[a]] < glob_dof_idx[loc_col_idx[b]];
1250 };
1251
1252 // loop over all our owned DOFS
1253 for(Index own_dof(0); own_dof < num_owned_dofs; ++own_dof)
1254 {
1255 const IT_ k_beg = loc_row_ptr[loc_dof_idx[own_dof]];
1256 const IT_ k_end = loc_row_ptr[loc_dof_idx[own_dof] + 1];
1257 row_it.clear();
1258 for(IT_ k = k_beg; k < k_end; ++k)
1259 row_it.push_back(k);
1260 std::sort(row_it.begin(), row_it.end(), sort_rel);
1261
1262 // get the local DOF index for this owned DOF
1263 IT_ j = IT_(own_row_ptr[row_offset + own_dof]);
1264 const IT_ j_end = IT_(own_row_ptr[row_offset + own_dof + 1]);
1265 auto kit = row_it.begin();
1266
1267 // loop over local matrix and owned matrix row in a merge-style fashion
1268 while((j < j_end) && (kit != row_it.end()))
1269 {
1270 if(own_col_idx[j] < glob_dof_idx[loc_col_idx[*kit]])
1271 ++j;
1272 else if(own_col_idx[j] > glob_dof_idx[loc_col_idx[*kit]])
1273 ++kit;
1274 else
1275 {
1276 aux_data_mir.push_back(std::make_pair(j, *kit));
1277 ++j;
1278 ++kit;
1279 }
1280 }
1281 }
1282
1283 // create data mirrors
1284 Index num_idx = Index(aux_data_mir.size());
1285 this->_buf_mir = LAFEM::VectorMirror<DT_, IT_>(local_matrix.num_nzes(), num_idx);
1286 this->_loc_mir = LAFEM::VectorMirror<DT_, IT_>(local_matrix.num_nzes(), num_idx);
1287
1288 Memory::TypedView<IT_> bm_idx = this->_buf_mir.indices_view_w();
1289 Memory::TypedView<IT_> lm_idx = this->_loc_mir.indices_view_w();
1290 for(Index i = 0; i < num_idx; ++i)
1291 {
1292 bm_idx[i] = aux_data_mir[i].first;
1293 lm_idx[i] = aux_data_mir[i].second;
1294 }
1295
1296 return num_owned_dofs;
1297 }
1298
1299 template<typename DTA_>
1300 void upload_owned_data(DTA_* adp_val, const LAFEM::SparseMatrixCSR<DT_, IT_>& local_matrix) const
1301 {
1302 const Memory::TypedView<DT_> loc_val = local_matrix.val_view_r();
1303 const Memory::TypedView<IT_> adp_idx = _buf_mir.indices_view_r();
1304 const Memory::TypedView<IT_> loc_idx = _loc_mir.indices_view_r();
1305 XASSERT(_buf_mir.num_indices() == _loc_mir.num_indices());
1306 Index n = _buf_mir.num_indices();
1307 for(Index i = 0; i < n; ++i)
1308 {
1309 ASSERT(loc_idx[i] < local_matrix.num_nzes());
1310 adp_val[adp_idx[i]] = DTA_(loc_val[loc_idx[i]]);
1311 }
1312 }
1313
1326 void gather_owner_data(LAFEM::DenseVector<DT_, IT_>& buffer, const LAFEM::SparseMatrixCSR<DT_, IT_>& local_matrix) const
1327 {
1328 Memory::TypedView<DT_> buf_val = buffer.elements_view_rw();
1329 const Memory::TypedView<DT_> loc_val = local_matrix.val_view_r();
1330 const Memory::TypedView<IT_> buf_idx = this->_buf_mir.indices_view_r();
1331 const Memory::TypedView<IT_> loc_idx = this->_loc_mir.indices_view_r();
1332 XASSERT(this->_buf_mir.num_indices() == this->_loc_mir.num_indices());
1333 Index n = this->_buf_mir.num_indices();
1334 for(Index i = 0; i < n; ++i)
1335 {
1336 ASSERT(buf_idx[i] < buffer.size());
1337 ASSERT(loc_idx[i] < local_matrix.num_nzes());
1338 buf_val[buf_idx[i]] = loc_val[loc_idx[i]];
1339 }
1340 }
1341
1342 }; // class ADPDOMM<LAFEM::SparseMatrixCSR<DT_, IT_>>
1343
1345
1346 template<typename DT_, typename IT_, int bh_, int bw_>
1347 class ADPDOMM<LAFEM::SparseMatrixBCSR<DT_, IT_, bh_, bw_>>
1348 {
1349 public:
1350 LAFEM::VectorMirror<DT_, IT_> _buf_mir, _loc_mir;
1351
1352 Index num_indices() const
1353 {
1354 return _buf_mir.num_indices();
1355 }
1356
1357 Index buf_size() const
1358 {
1359 return _buf_mir.size();
1360 }
1361
1362 Index loc_size() const
1363 {
1364 return _loc_mir.size();
1365 }
1366
1367 String dump() const
1368 {
1369 String s;
1370 XASSERT(_buf_mir.num_indices() == _loc_mir.num_indices());
1371 const Memory::TypedView<IT_> buf_idx = _buf_mir.indices_view_r();
1372 const Memory::TypedView<IT_> loc_idx = _loc_mir.indices_view_r();
1373 for(Index i = 0; i < _buf_mir.num_indices(); ++i)
1374 s += " " + stringify(buf_idx[i]) + ":" + stringify(loc_idx[i]);
1375 return "[" + s + "]*" + stringify(_buf_mir.num_indices());
1376 }
1377
1378 Index asm_neighbor_owner_data_mir(
1379 const LAFEM::SparseMatrixBCSR<DT_, IT_, bh_, bw_>& local_matrix,
1380 const LAFEM::VectorMirror<DT_, IT_>& row_mirror,
1381 const LAFEM::MatrixMirrorBuffer<DT_, IT_>& buffer,
1382 const LAFEM::DenseVectorBlocked<IT_, IT_, bw_>& global_dof_idx,
1383 Index row_offset)
1384 {
1385 // get our mirror and matrix arrays
1386 const Memory::TypedView<IT_> row_idx = row_mirror.indices_view_r();
1387 const Memory::TypedView<IT_> row_ptr = local_matrix.row_ptr_view_r();
1388 const Memory::TypedView<IT_> col_idx = local_matrix.col_idx_view_r();
1389 const Memory::TypedView<IT_> buf_ptr = buffer.row_ptr_view_r();
1390 const Memory::TypedView<IT_> buf_idx = buffer.col_idx_view_r();
1391 const Memory::TypedView<Tiny::Vector<IT_,bw_>> glob_dof_idx = global_dof_idx.elements_view_r();
1392 const Index row_mir_num_idx = row_mirror.num_indices();
1393
1394 // count the number of non-zeros that this matrix contributes to the buffer
1395 Index data_mir_num_idx = 0u;
1396 for(Index i = 0; i < row_mir_num_idx; ++i)
1397 data_mir_num_idx += row_ptr[row_idx[i]+1u] - row_ptr[row_idx[i]];
1398 data_mir_num_idx *= Index(bh_*bw_);
1399
1400 XASSERT(data_mir_num_idx <= buffer.num_nzes());
1401
1402 // allocate data mirror
1403 std::vector<std::pair<IT_, IT_>> aux_data_mir;
1404 aux_data_mir.reserve(data_mir_num_idx);
1405
1406 // vector for row pointers sorted by global indices
1407 std::vector<IT_> loc_it;
1408 loc_it.reserve(local_matrix.num_cols() * std::size_t(bh_*bw_));
1409
1410 // declare a lambda that sorts row pointers by global column indices
1411 auto sort_rel_loc = [&glob_dof_idx, &col_idx] (IT_ a, IT_ b)
1412 {
1413 return glob_dof_idx[col_idx[a]][0] < glob_dof_idx[col_idx[b]][0];
1414 };
1415
1416 // loop over all buffer matrix rows
1417 for(Index i(0); i < row_mir_num_idx; ++i)
1418 {
1419 const IT_ k_beg = row_ptr[row_idx[i]];
1420 const IT_ k_end = row_ptr[row_idx[i] + 1];
1421 loc_it.clear();
1422 for(IT_ k = k_beg; k < k_end; ++k)
1423 loc_it.push_back(k);
1424 std::sort(loc_it.begin(), loc_it.end(), sort_rel_loc);
1425
1426 // loop over the block height
1427 for(int bi = 0; bi < bh_; ++bi)
1428 {
1429 // get local matrix row index
1430 IT_ j = buf_ptr[row_offset + i*IT_(bh_) + IT_(bi)];
1431 const IT_ j_end = buf_ptr[row_offset + i*IT_(bh_) + IT_(bi) + 1];
1432
1433 auto kit = loc_it.begin();
1434
1435 // loop over local matrix and buffer matrix row in a merge-style fashion
1436 while((j < j_end) && (kit != loc_it.end()))
1437 {
1438 if(buf_idx[j] < glob_dof_idx[col_idx[*kit]][0])
1439 ++j;
1440 else if(buf_idx[j] > glob_dof_idx[col_idx[*kit]][0])
1441 ++kit;
1442 else
1443 {
1444 // global column indices match
1445 for(int bj = 0; bj < bw_; ++bj)
1446 {
1447 aux_data_mir.push_back(std::make_pair(j, (*kit)*IT_(bh_*bw_) + IT_(bi*bw_) + IT_(bj)));
1448 ++j;
1449 }
1450 ++kit;
1451 }
1452 }
1453 }
1454 }
1455
1456 // create data mirrors
1457 Index num_idx = Index(aux_data_mir.size());
1458 this->_buf_mir = LAFEM::VectorMirror<DT_, IT_>(buffer.num_nzes(), num_idx);
1459 this->_loc_mir = LAFEM::VectorMirror<DT_, IT_>(
1460 local_matrix.num_nzes_raw(), num_idx);
1461
1462 Memory::TypedView<IT_> bm_idx = this->_buf_mir.indices_view_w();
1463 Memory::TypedView<IT_> lm_idx = this->_loc_mir.indices_view_w();
1464 for(Index i = 0; i < num_idx; ++i)
1465 {
1466 bm_idx[i] = aux_data_mir[i].first;
1467 lm_idx[i] = aux_data_mir[i].second;
1468 }
1469
1470 return row_mir_num_idx * Index(bh_);
1471 }
1472
1473 Index asm_neighbor_owner_data_mir(
1474 const LAFEM::SparseMatrixBCSR<DT_, IT_, bh_, 1>& local_matrix,
1475 const LAFEM::VectorMirror<DT_, IT_>& row_mirror,
1476 const LAFEM::MatrixMirrorBuffer<DT_, IT_>& buffer,
1477 const LAFEM::DenseVector<IT_, IT_>& global_dof_idx,
1478 Index row_offset)
1479 {
1480 // get our mirror and matrix arrays
1481 const Memory::TypedView<IT_> row_idx = row_mirror.indices_view_r();
1482 const Memory::TypedView<IT_> row_ptr = local_matrix.row_ptr_view_r();
1483 const Memory::TypedView<IT_> col_idx = local_matrix.col_idx_view_r();
1484 const Memory::TypedView<IT_> buf_ptr = buffer.row_ptr_view_r();
1485 const Memory::TypedView<IT_> buf_idx = buffer.col_idx_view_r();
1486 const Memory::TypedView<IT_> glob_dof_idx = global_dof_idx.elements_view_r();
1487 const Index row_mir_num_idx = row_mirror.num_indices();
1488
1489 // count the number of non-zeros that this matrix contributes to the buffer
1490 Index data_mir_num_idx = 0u;
1491 for(Index i = 0; i < row_mir_num_idx; ++i)
1492 data_mir_num_idx += row_ptr[row_idx[i]+1u] - row_ptr[row_idx[i]];
1493 data_mir_num_idx *= Index(bh_);
1494
1495 XASSERT(data_mir_num_idx <= buffer.num_nzes());
1496
1497 // allocate data mirror
1498 std::vector<std::pair<IT_, IT_>> aux_data_mir;
1499 aux_data_mir.reserve(data_mir_num_idx);
1500
1501 // vector for row pointers sorted by global indices
1502 std::vector<IT_> loc_it;
1503 loc_it.reserve(local_matrix.num_cols() * std::size_t(bh_));
1504
1505 // declare a lambda that sorts row pointers by global column indices
1506 auto sort_rel_loc = [&glob_dof_idx, &col_idx] (IT_ a, IT_ b)
1507 {
1508 return glob_dof_idx[col_idx[a]] < glob_dof_idx[col_idx[b]];
1509 };
1510
1511 // loop over all buffer matrix rows
1512 for(Index i(0); i < row_mir_num_idx; ++i)
1513 {
1514 const IT_ k_beg = row_ptr[row_idx[i]];
1515 const IT_ k_end = row_ptr[row_idx[i] + 1];
1516 loc_it.clear();
1517 for(IT_ k = k_beg; k < k_end; ++k)
1518 loc_it.push_back(k);
1519 std::sort(loc_it.begin(), loc_it.end(), sort_rel_loc);
1520
1521 // loop over the block height
1522 for(int bi = 0; bi < bh_; ++bi)
1523 {
1524 // get local matrix row index
1525 IT_ j = buf_ptr[row_offset + i*IT_(bh_) + IT_(bi)];
1526 const IT_ j_end = buf_ptr[row_offset + i*IT_(bh_) + IT_(bi) + 1];
1527 auto kit = loc_it.begin();
1528
1529 // loop over local matrix and buffer matrix row in a merge-style fashion
1530 while((j < j_end) && (kit != loc_it.end()))
1531 {
1532 if(buf_idx[j] < glob_dof_idx[col_idx[*kit]])
1533 ++j;
1534 else if(buf_idx[j] > glob_dof_idx[col_idx[*kit]])
1535 ++kit;
1536 else
1537 {
1538 // global column indices match
1539 aux_data_mir.push_back(std::make_pair(j, (*kit)*IT_(bh_) + IT_(bi)));
1540 ++j;
1541 ++kit;
1542 }
1543 }
1544 }
1545 }
1546
1547 // create data mirrors
1548 Index num_idx = Index(aux_data_mir.size());
1549 this->_buf_mir = LAFEM::VectorMirror<DT_, IT_>(buffer.num_nzes(), num_idx);
1550 this->_loc_mir = LAFEM::VectorMirror<DT_, IT_>(local_matrix.num_nzes_raw(), num_idx);
1551
1552 Memory::TypedView<IT_> bm_idx = this->_buf_mir.indices_view_w();
1553 Memory::TypedView<IT_> lm_idx = this->_loc_mir.indices_view_w();
1554 for(Index i = 0; i < num_idx; ++i)
1555 {
1556 bm_idx[i] = aux_data_mir[i].first;
1557 lm_idx[i] = aux_data_mir[i].second;
1558 }
1559
1560 return row_mir_num_idx * Index(bh_);
1561 }
1562
1563 Index asm_owned_data_mir(
1564 const LAFEM::SparseMatrixBCSR<DT_, IT_, bh_, bw_>& local_matrix,
1565 const Adjacency::Graph& owned_graph,
1566 const LAFEM::VectorMirror<DT_, IT_>& row_mirror,
1567 const LAFEM::DenseVectorBlocked<IT_, IT_, bw_>& global_dof_idx,
1568 Index row_offset)
1569 {
1570 // get matrix arrays
1571 const Index* own_row_ptr = owned_graph.get_domain_ptr();
1572 const Index* own_col_idx = owned_graph.get_image_idx();
1573 const Memory::TypedView<IT_> loc_row_ptr = local_matrix.row_ptr_view_r();
1574 const Memory::TypedView<IT_> loc_col_idx = local_matrix.col_idx_view_r();
1575
1576 // allocate data mirror
1577 std::vector<std::pair<IT_, IT_>> aux_data_mir;
1578 aux_data_mir.reserve(owned_graph.get_num_indices() * std::size_t(bh_*bw_));
1579
1580 const Index num_owned_dofs = row_mirror.num_indices();
1581 const Memory::TypedView<IT_> loc_dof_idx = row_mirror.indices_view_r();
1582 const Memory::TypedView<Tiny::Vector<IT_,bw_>> glob_dof_idx = global_dof_idx.elements_view_r();
1583
1584 //XASSERT(num_owned_dofs == adp_matrix.num_rows());
1585
1586 // row iterator deque
1587 std::deque<IT_> row_it;
1588
1589 // declare a lambda that sorts row pointers by global column indices
1590 auto sort_rel = [&glob_dof_idx, &loc_col_idx] (IT_ a, IT_ b)
1591 {
1592 return glob_dof_idx[loc_col_idx[a]][0] < glob_dof_idx[loc_col_idx[b]][0];
1593 };
1594
1595 // loop over all our owned DOFS
1596 for(Index own_dof(0); own_dof < num_owned_dofs; ++own_dof)
1597 {
1598 const IT_ k_beg = loc_row_ptr[loc_dof_idx[own_dof]];
1599 const IT_ k_end = loc_row_ptr[loc_dof_idx[own_dof] + 1];
1600 row_it.clear();
1601 for(IT_ k = k_beg; k < k_end; ++k)
1602 row_it.push_back(k);
1603 std::sort(row_it.begin(), row_it.end(), sort_rel);
1604
1605 // loop over the block height
1606 for(int bi = 0; bi < bh_; ++bi)
1607 {
1608 IT_ j = IT_(own_row_ptr[row_offset + own_dof*IT_(bh_) + IT_(bi)]);
1609 const IT_ j_end = IT_(own_row_ptr[row_offset + own_dof*IT_(bh_) + IT_(bi) + 1]);
1610 auto kit = row_it.begin();
1611
1612 // loop over local matrix and owned matrix row in a merge-style fashion
1613 while((j < j_end) && (kit != row_it.end()))
1614 {
1615 if(own_col_idx[j] < glob_dof_idx[loc_col_idx[*kit]][0])
1616 ++j;
1617 else if(own_col_idx[j] > glob_dof_idx[loc_col_idx[*kit]][0])
1618 ++kit;
1619 else
1620 {
1621 // global column indices match
1622 for(int bj = 0; bj < bw_; ++bj)
1623 {
1624 aux_data_mir.push_back(std::make_pair(j, (*kit)*IT_(bh_*bw_) + IT_(bi*bw_) + IT_(bj)));
1625 ++j;
1626 }
1627 ++kit;
1628 }
1629 }
1630 }
1631 }
1632
1633 // create data mirrors
1634 Index num_idx = Index(aux_data_mir.size());
1635 this->_buf_mir = LAFEM::VectorMirror<DT_, IT_>(owned_graph.get_num_indices(), num_idx);
1636 this->_loc_mir = LAFEM::VectorMirror<DT_, IT_>(
1637 local_matrix.num_nzes_raw(), num_idx);
1638
1639 Memory::TypedView<IT_> bm_idx = this->_buf_mir.indices_view_w();
1640 Memory::TypedView<IT_> lm_idx = this->_loc_mir.indices_view_w();
1641 for(Index i = 0; i < num_idx; ++i)
1642 {
1643 bm_idx[i] = aux_data_mir[i].first;
1644 lm_idx[i] = aux_data_mir[i].second;
1645 }
1646
1647 return num_owned_dofs * Index(bh_);
1648 }
1649
1650 Index asm_owned_data_mir(
1651 const LAFEM::SparseMatrixBCSR<DT_, IT_, bh_, 1>& local_matrix,
1652 const Adjacency::Graph& owned_graph,
1653 const LAFEM::VectorMirror<DT_, IT_>& row_mirror,
1654 const LAFEM::DenseVector<IT_, IT_>& global_dof_idx,
1655 Index row_offset)
1656 {
1657 // get matrix arrays
1658 const Index* own_row_ptr = owned_graph.get_domain_ptr();
1659 const Index* own_col_idx = owned_graph.get_image_idx();
1660 const Memory::TypedView<IT_> loc_row_ptr = local_matrix.row_ptr_view_r();
1661 const Memory::TypedView<IT_> loc_col_idx = local_matrix.col_idx_view_r();
1662
1663 // allocate data mirror
1664 std::vector<std::pair<IT_, IT_>> aux_data_mir;
1665 aux_data_mir.reserve(owned_graph.get_num_indices() * std::size_t(bh_));
1666
1667 const Index num_owned_dofs = row_mirror.num_indices();
1668 const Memory::TypedView<IT_> loc_dof_idx = row_mirror.indices_view_r();
1669 const Memory::TypedView<IT_> glob_dof_idx = global_dof_idx.elements_view_r();
1670
1671 //XASSERT(num_owned_dofs == adp_matrix.num_rows());
1672
1673 // row iterator deque
1674 std::deque<IT_> row_it;
1675
1676 // declare a lambda that sorts row pointers by global column indices
1677 auto sort_rel = [&glob_dof_idx, &loc_col_idx] (IT_ a, IT_ b)
1678 {
1679 return glob_dof_idx[loc_col_idx[a]] < glob_dof_idx[loc_col_idx[b]];
1680 };
1681
1682 // loop over all our owned DOFS
1683 for(Index own_dof(0); own_dof < num_owned_dofs; ++own_dof)
1684 {
1685 const IT_ k_beg = loc_row_ptr[loc_dof_idx[own_dof]];
1686 const IT_ k_end = loc_row_ptr[loc_dof_idx[own_dof] + 1];
1687 row_it.clear();
1688 for(IT_ k = k_beg; k < k_end; ++k)
1689 row_it.push_back(k);
1690 std::sort(row_it.begin(), row_it.end(), sort_rel);
1691
1692 // loop over the block height
1693 for(int bi = 0; bi < bh_; ++bi)
1694 {
1695 IT_ j = IT_(own_row_ptr[row_offset + own_dof*IT_(bh_) + IT_(bi)]);
1696 const IT_ j_end = IT_(own_row_ptr[row_offset + own_dof*IT_(bh_) + IT_(bi) + 1]);
1697 auto kit = row_it.begin();
1698
1699 // loop over local matrix and owned matrix row in a merge-style fashion
1700 while((j < j_end) && (kit != row_it.end()))
1701 {
1702 if(own_col_idx[j] < glob_dof_idx[loc_col_idx[*kit]])
1703 ++j;
1704 else if(own_col_idx[j] > glob_dof_idx[loc_col_idx[*kit]])
1705 ++kit;
1706 else
1707 {
1708 // global column indices match
1709 aux_data_mir.push_back(std::make_pair(j, (*kit)*IT_(bh_) + IT_(bi)));
1710 ++j;
1711 ++kit;
1712 }
1713 }
1714 }
1715 }
1716
1717 // create data mirrors
1718 Index num_idx = Index(aux_data_mir.size());
1719 this->_buf_mir = LAFEM::VectorMirror<DT_, IT_>(owned_graph.get_num_indices(), num_idx);
1720 this->_loc_mir = LAFEM::VectorMirror<DT_, IT_>(local_matrix.num_nzes_raw(), num_idx);
1721
1722 Memory::TypedView<IT_> bm_idx = this->_buf_mir.indices_view_w();
1723 Memory::TypedView<IT_> lm_idx = this->_loc_mir.indices_view_w();
1724 for(Index i = 0; i < num_idx; ++i)
1725 {
1726 bm_idx[i] = aux_data_mir[i].first;
1727 lm_idx[i] = aux_data_mir[i].second;
1728 }
1729
1730 return num_owned_dofs * Index(bh_);
1731 }
1732
1733 template<typename DTA_>
1734 void upload_owned_data(DTA_* adp_val, const LAFEM::SparseMatrixBCSR<DT_, IT_, bh_, bw_>& local_matrix) const
1735 {
1736 const Memory::TypedView<DT_> loc_val = local_matrix.val_view_raw_r();
1737 const Memory::TypedView<IT_> adp_idx = _buf_mir.indices_view_r();
1738 const Memory::TypedView<IT_> loc_idx = _loc_mir.indices_view_r();
1739 XASSERT(_buf_mir.num_indices() == _loc_mir.num_indices());
1740 Index n = _buf_mir.num_indices();
1741 for(Index i = 0; i < n; ++i)
1742 {
1743 ASSERT(loc_idx[i] < local_matrix.num_nzes_raw());
1744 adp_val[adp_idx[i]] = DTA_(loc_val[loc_idx[i]]);
1745 }
1746 }
1747
1748 void gather_owner_data(
1749 LAFEM::DenseVector<DT_, IT_>& buffer,
1750 const LAFEM::SparseMatrixBCSR<DT_, IT_, bh_, bw_>& local_matrix) const
1751 {
1752 Memory::TypedView<DT_> buf_val = buffer.elements_view_w();
1753 const Memory::TypedView<DT_> loc_val = local_matrix.val_view_raw_r();
1754 const Memory::TypedView<IT_> buf_idx = this->_buf_mir.indices_view_r();
1755 const Memory::TypedView<IT_> loc_idx = this->_loc_mir.indices_view_r();
1756 XASSERT(this->_buf_mir.num_indices() == this->_loc_mir.num_indices());
1757 Index n = this->_buf_mir.num_indices();
1758 for(Index i = 0; i < n; ++i)
1759 {
1760 ASSERT(buf_idx[i] < buffer.size());
1761 ASSERT(loc_idx[i] < local_matrix.num_nzes_raw());
1762 buf_val[buf_idx[i]] = loc_val[loc_idx[i]];
1763 }
1764 }
1765
1766 }; // class ADPDOMM<LAFEM::SparseMatrixBCSR<DT_, IT_, bh_, bw_>>
1767
1769
1770 template<typename DT_, typename IT_, int bh_, int bw_>
1771 class ADPDOMM<LAFEM::NullMatrix<DT_, IT_, bh_, bw_>>
1772 {
1773 public:
1774 Index num_indices() const
1775 {
1776 return Index(0);
1777 }
1778
1779 Index buf_size() const
1780 {
1781 return Index(0);
1782 }
1783
1784 Index loc_size() const
1785 {
1786 return Index(0);
1787 }
1788
1789 String dump() const
1790 {
1791 return "[null]";
1792 }
1793
1794 Index asm_neighbor_owner_data_mir(
1795 const LAFEM::NullMatrix<DT_, IT_, bh_, bw_>&,
1796 const LAFEM::VectorMirror<DT_, IT_>& row_mirror,
1797 const LAFEM::MatrixMirrorBuffer<DT_, IT_>&,
1798 const LAFEM::DenseVectorBlocked<IT_, IT_, bw_>&,
1799 Index)
1800 {
1801 return row_mirror.num_indices() * Index(bh_);
1802 }
1803
1804 Index asm_neighbor_owner_data_mir(
1805 const LAFEM::NullMatrix<DT_, IT_, bh_, 1>&,
1806 const LAFEM::VectorMirror<DT_, IT_>& row_mirror,
1807 const LAFEM::MatrixMirrorBuffer<DT_, IT_>&,
1808 const LAFEM::DenseVector<IT_, IT_>&,
1809 Index)
1810 {
1811 return row_mirror.num_indices() * Index(bh_);
1812 }
1813
1814 Index asm_owned_data_mir(
1815 const LAFEM::NullMatrix<DT_, IT_, bh_, bw_>&,
1816 const Adjacency::Graph&,
1817 const LAFEM::VectorMirror<DT_, IT_>& row_mirror,
1818 const LAFEM::DenseVectorBlocked<IT_, IT_, bw_>&,
1819 Index)
1820 {
1821 return row_mirror.num_indices() * Index(bh_);
1822 }
1823
1824 Index asm_owned_data_mir(
1825 const LAFEM::NullMatrix<DT_, IT_, bh_, 1>&,
1826 const Adjacency::Graph&,
1827 const LAFEM::VectorMirror<DT_, IT_>& row_mirror,
1828 const LAFEM::DenseVector<IT_, IT_>&,
1829 Index)
1830 {
1831 return row_mirror.num_indices() * Index(bh_);
1832 }
1833
1834 template<typename DTA_>
1835 void upload_owned_data(DTA_*, const LAFEM::NullMatrix<DT_, IT_, bh_, bw_>&) const
1836 {
1837 }
1838
1839 void gather_owner_data(
1840 LAFEM::DenseVector<DT_, IT_>&,
1841 const LAFEM::NullMatrix<DT_, IT_, bh_, bw_>&) const
1842 {
1843 }
1844 }; // class ADPDOMM<LAFEM::NullMatrix<DT_, IT_, bh_, bw_>>
1845
1847
1848 template<typename FirstMatrix_, typename... RestMatrix_>
1849 class ADPDOMM<LAFEM::TupleMatrixRow<FirstMatrix_, RestMatrix_...>>
1850 {
1851 public:
1852 typedef typename FirstMatrix_::DataType DT_;
1853 typedef typename FirstMatrix_::IndexType IT_;
1854
1855 ADPDOMM<FirstMatrix_> first;
1856 ADPDOMM<LAFEM::TupleMatrixRow<RestMatrix_...>> rest;
1857
1858 Index num_indices() const
1859 {
1860 return first.num_indices() + rest.num_indices();
1861 }
1862
1863 Index buf_size() const
1864 {
1865 return first.buf_size() + rest.buf_size();
1866 }
1867
1868 Index loc_size() const
1869 {
1870 return first.loc_size() + rest.loc_size();
1871 }
1872
1873 String dump_raw() const
1874 {
1875 return first.dump() + "," + rest.dump_raw();
1876 }
1877
1878 String dump() const
1879 {
1880 return "[" + dump_raw() + "]";
1881 }
1882
1883 template<
1884 typename RowMirror_,
1885 typename FirstIdxVec_, typename... RestIdxVec_>
1886 Index asm_neighbor_owner_data_mir(
1887 const LAFEM::TupleMatrixRow<FirstMatrix_, RestMatrix_...>& local_matrix,
1888 const RowMirror_& row_mirror,
1889 const LAFEM::MatrixMirrorBuffer<DT_, IT_>& buffer,
1890 const LAFEM::TupleVector<FirstIdxVec_, RestIdxVec_...>& global_dof_idx,
1891 Index row_offset)
1892 {
1893 Index n1 = first.asm_neighbor_owner_data_mir(local_matrix.first(), row_mirror, buffer, global_dof_idx.first(), row_offset);
1894 Index n2 = rest.asm_neighbor_owner_data_mir(local_matrix.rest(), row_mirror, buffer, global_dof_idx.rest(), row_offset);
1895 XASSERT(n1 == n2);
1896 return n1;
1897 }
1898
1899 template<
1900 typename RowMirror_,
1901 typename FirstIdxVec_, typename... RestIdxVec_>
1902 Index asm_owned_data_mir(
1903 const LAFEM::TupleMatrixRow<FirstMatrix_, RestMatrix_...>& local_matrix,
1904 const Adjacency::Graph& owned_graph,
1905 const RowMirror_& row_mirror,
1906 const LAFEM::TupleVector<FirstIdxVec_, RestIdxVec_...>& global_dof_idx,
1907 Index row_offset)
1908 {
1909 Index n1 = first.asm_owned_data_mir(local_matrix.first(), owned_graph, row_mirror, global_dof_idx.first(), row_offset);
1910 Index n2 = rest.asm_owned_data_mir(local_matrix.rest(), owned_graph, row_mirror, global_dof_idx.rest(), row_offset);
1911 XASSERT(n1 == n2);
1912 return n1;
1913 }
1914
1915 template<typename DTA_>
1916 void upload_owned_data(DTA_* adp_val, const LAFEM::TupleMatrixRow<FirstMatrix_, RestMatrix_...>& local_matrix) const
1917 {
1918 first.upload_owned_data(adp_val, local_matrix.first());
1919 rest.upload_owned_data(adp_val, local_matrix.rest());
1920 }
1921
1922 void gather_owner_data(
1923 LAFEM::DenseVector<DT_, IT_>& buffer,
1924 const LAFEM::TupleMatrixRow<FirstMatrix_, RestMatrix_...>& local_matrix) const
1925 {
1926 first.gather_owner_data(buffer, local_matrix.first());
1927 rest.gather_owner_data(buffer, local_matrix.rest());
1928 }
1929 }; // class ADPDOMM<LAFEM::TupleMatrixRow<First_, Rest_...>>
1930
1932
1933 template<typename FirstMatrix_>
1934 class ADPDOMM<LAFEM::TupleMatrixRow<FirstMatrix_>>
1935 {
1936 public:
1937 typedef typename FirstMatrix_::DataType DT_;
1938 typedef typename FirstMatrix_::IndexType IT_;
1939
1940 ADPDOMM<FirstMatrix_> first;
1941
1942 Index num_indices() const
1943 {
1944 return first.num_indices();
1945 }
1946
1947 Index buf_size() const
1948 {
1949 return first.buf_size();
1950 }
1951
1952 Index loc_size() const
1953 {
1954 return first.loc_size();
1955 }
1956
1957 String dump_raw() const
1958 {
1959 return first.dump();
1960 }
1961
1962 String dump() const
1963 {
1964 return "[" + dump_raw() + "]";
1965 }
1966
1967 template<
1968 typename RowMirror_,
1969 typename FirstIdxVec_>
1970 Index asm_neighbor_owner_data_mir(
1971 const LAFEM::TupleMatrixRow<FirstMatrix_>& local_matrix,
1972 const RowMirror_& row_mirror,
1973 const LAFEM::MatrixMirrorBuffer<DT_, IT_>& buffer,
1974 const LAFEM::TupleVector<FirstIdxVec_>& global_dof_idx,
1975 Index row_offset)
1976 {
1977 return first.asm_neighbor_owner_data_mir(local_matrix.first(), row_mirror, buffer, global_dof_idx.first(), row_offset);
1978 }
1979
1980 template<
1981 typename RowMirror_,
1982 typename FirstIdxVec_>
1983 Index asm_owned_data_mir(
1984 const LAFEM::TupleMatrixRow<FirstMatrix_>& local_matrix,
1985 const Adjacency::Graph& owned_graph,
1986 const RowMirror_& row_mirror,
1987 const LAFEM::TupleVector<FirstIdxVec_>& global_dof_idx,
1988 Index row_offset)
1989 {
1990 return first.asm_owned_data_mir(local_matrix.first(), owned_graph, row_mirror, global_dof_idx.first(), row_offset);
1991 }
1992
1993 template<typename DTA_>
1994 void upload_owned_data(DTA_* adp_val, const LAFEM::TupleMatrixRow<FirstMatrix_>& local_matrix) const
1995 {
1996 first.upload_owned_data(adp_val, local_matrix.first());
1997 }
1998
1999 void gather_owner_data(
2000 LAFEM::DenseVector<DT_, IT_>& buffer,
2001 const LAFEM::TupleMatrixRow<FirstMatrix_>& local_matrix) const
2002 {
2003 first.gather_owner_data(buffer, local_matrix.first());
2004 }
2005 }; // class ADPDOMM<LAFEM::TupleMatrixRow<First_>>
2006
2008
2009 template<typename FirstMatRow_, typename... RestMatRow_>
2010 class ADPDOMM<LAFEM::TupleMatrix<FirstMatRow_, RestMatRow_...>>
2011 {
2012 public:
2013 typedef typename FirstMatRow_::DataType DT_;
2014 typedef typename FirstMatRow_::IndexType IT_;
2015
2016 ADPDOMM<FirstMatRow_> first;
2017 ADPDOMM<LAFEM::TupleMatrix<RestMatRow_...>> rest;
2018
2019 Index num_indices() const
2020 {
2021 return first.num_indices() + rest.num_indices();
2022 }
2023
2024 Index buf_size() const
2025 {
2026 return first.buf_size() + rest.buf_size();
2027 }
2028
2029 Index loc_size() const
2030 {
2031 return first.loc_size() + rest.loc_size();
2032 }
2033
2034 String dump_raw() const
2035 {
2036 return first.dump() + "," + rest.dump_raw();
2037 }
2038
2039 String dump() const
2040 {
2041 return "[" + dump_raw() + "]";
2042 }
2043
2044 template<
2045 typename FirstRowMir_, typename... RestRowMir_,
2046 typename FirstIdxVec_, typename... RestIdxVec_>
2047 Index asm_neighbor_owner_data_mir(
2048 const LAFEM::TupleMatrix<FirstMatRow_, RestMatRow_...>& local_matrix,
2049 const LAFEM::TupleMirror<FirstRowMir_, RestRowMir_...>& row_mirror,
2050 const LAFEM::MatrixMirrorBuffer<DT_, IT_>& buffer,
2051 const LAFEM::TupleVector<FirstIdxVec_, RestIdxVec_...>& global_dof_idx,
2052 Index row_offset)
2053 {
2054 Index n1 = first.asm_neighbor_owner_data_mir(local_matrix.first(), row_mirror.first(), buffer, global_dof_idx, row_offset);
2055 Index n2 = rest.asm_neighbor_owner_data_mir(local_matrix.rest(), row_mirror.rest(), buffer, global_dof_idx, row_offset + n1);
2056 return n1 + n2;
2057 }
2058
2059 template<
2060 typename FirstRowMir_, typename... RestRowMir_,
2061 typename FirstIdxVec_, typename... RestIdxVec_>
2062 Index asm_owned_data_mir(
2063 const LAFEM::TupleMatrix<FirstMatRow_, RestMatRow_...>& local_matrix,
2064 const Adjacency::Graph& owned_graph,
2065 const LAFEM::TupleMirror<FirstRowMir_, RestRowMir_...>& row_mirror,
2066 const LAFEM::TupleVector<FirstIdxVec_, RestIdxVec_...>& global_dof_idx,
2067 Index row_offset)
2068 {
2069 Index n1 = first.asm_owned_data_mir(local_matrix.first(), owned_graph, row_mirror.first(), global_dof_idx, row_offset);
2070 Index n2 = rest.asm_owned_data_mir(local_matrix.rest(), owned_graph, row_mirror.rest(), global_dof_idx, row_offset + n1);
2071 return n1 + n2;
2072 }
2073
2074 template<typename DTA_>
2075 void upload_owned_data(DTA_* adp_val, const LAFEM::TupleMatrix<FirstMatRow_, RestMatRow_...>& local_matrix) const
2076 {
2077 first.upload_owned_data(adp_val, local_matrix.first());
2078 rest.upload_owned_data(adp_val, local_matrix.rest());
2079 }
2080
2081 void gather_owner_data(
2082 LAFEM::DenseVector<DT_, IT_>& buffer,
2083 const LAFEM::TupleMatrix<FirstMatRow_, RestMatRow_...>& local_matrix) const
2084 {
2085 first.gather_owner_data(buffer, local_matrix.first());
2086 rest.gather_owner_data(buffer, local_matrix.rest());
2087 }
2088 }; // class ADPDOMM<LAFEM::TupleMatrix<First_, Rest_...>>
2089
2091
2092 template<typename FirstMatRow_>
2093 class ADPDOMM<LAFEM::TupleMatrix<FirstMatRow_>>
2094 {
2095 public:
2096 typedef typename FirstMatRow_::DataType DT_;
2097 typedef typename FirstMatRow_::IndexType IT_;
2098
2099 ADPDOMM<FirstMatRow_> first;
2100
2101 Index num_indices() const
2102 {
2103 return first.num_indices();
2104 }
2105
2106 Index buf_size() const
2107 {
2108 return first.buf_size();
2109 }
2110
2111 Index loc_size() const
2112 {
2113 return first.loc_size();
2114 }
2115
2116 String dump_raw() const
2117 {
2118 return first.dump();
2119 }
2120
2121 String dump() const
2122 {
2123 return "[" + dump_raw() + "]";
2124 }
2125
2126 template<
2127 typename FirstRowMir_,
2128 typename FirstIdxVec_, typename... RestIdxVec_>
2129 Index asm_neighbor_owner_data_mir(
2130 const LAFEM::TupleMatrix<FirstMatRow_>& local_matrix,
2131 const LAFEM::TupleMirror<FirstRowMir_>& row_mirror,
2132 const LAFEM::MatrixMirrorBuffer<DT_, IT_>& buffer,
2133 const LAFEM::TupleVector<FirstIdxVec_, RestIdxVec_...>& global_dof_idx,
2134 Index row_offset)
2135 {
2136 return first.asm_neighbor_owner_data_mir(local_matrix.first(), row_mirror.first(), buffer, global_dof_idx, row_offset);
2137 }
2138
2139 template<
2140 typename FirstRowMir_,
2141 typename FirstIdxVec_, typename... RestIdxVec_>
2142 Index asm_owned_data_mir(
2143 const LAFEM::TupleMatrix<FirstMatRow_>& local_matrix,
2144 const Adjacency::Graph& owned_graph,
2145 const LAFEM::TupleMirror<FirstRowMir_>& row_mirror,
2146 const LAFEM::TupleVector<FirstIdxVec_, RestIdxVec_...>& global_dof_idx,
2147 Index row_offset)
2148 {
2149 return first.asm_owned_data_mir(local_matrix.first(), owned_graph, row_mirror.first(), global_dof_idx, row_offset);
2150 }
2151
2152 template<typename DTA_>
2153 void upload_owned_data(DTA_* adp_val, const LAFEM::TupleMatrix<FirstMatRow_>& local_matrix) const
2154 {
2155 first.upload_owned_data(adp_val, local_matrix.first());
2156 }
2157
2158 void gather_owner_data(
2159 LAFEM::DenseVector<DT_, IT_>& buffer,
2160 const LAFEM::TupleMatrix<FirstMatRow_>& local_matrix) const
2161 {
2162 first.gather_owner_data(buffer, local_matrix.first());
2163 }
2164 }; // class ADPDOMM<LAFEM::TupleMatrix<First_>>
2165
2167
2168 template<typename MatrixA_, typename MatrixB_, typename MatrixD_>
2169 class ADPDOMM<LAFEM::SaddlePointMatrix<MatrixA_, MatrixB_, MatrixD_>>
2170 {
2171 public:
2172 typedef typename MatrixA_::DataType DT_;
2173 typedef typename MatrixA_::IndexType IT_;
2174
2175 ADPDOMM<MatrixA_> block_a;
2176 ADPDOMM<MatrixB_> block_b;
2177 ADPDOMM<MatrixD_> block_d;
2178
2179 Index num_indices() const
2180 {
2181 return block_a.num_indices() + block_b.num_indices() + block_d.num_indices();
2182 }
2183
2184 Index buf_size() const
2185 {
2186 return block_a.buf_size() + block_b.buf_size() + block_d.buf_size();
2187 }
2188
2189 Index loc_size() const
2190 {
2191 return block_a.loc_size() + block_b.loc_size() + block_d.loc_size();
2192 }
2193
2194 String dump() const
2195 {
2196 return "[[" + block_a.dump() + "," + block_b.dump() + "],[" + block_d.dump() + ",0]";
2197 }
2198
2199 template<
2200 typename MirrorV_, typename MirrorP_,
2201 typename IdxVecV_, typename IdxVecP_>
2202 Index asm_neighbor_owner_data_mir(
2203 const LAFEM::SaddlePointMatrix<MatrixA_, MatrixB_, MatrixD_>& local_matrix,
2204 const LAFEM::TupleMirror<MirrorV_, MirrorP_>& row_mirror,
2205 const LAFEM::MatrixMirrorBuffer<DT_, IT_>& buffer,
2206 const LAFEM::TupleVector<IdxVecV_, IdxVecP_>& global_dof_idx,
2207 Index row_offset)
2208 {
2209 Index na = block_a.asm_neighbor_owner_data_mir(local_matrix.block_a(), row_mirror.template at<0>(), buffer, global_dof_idx.template at<0>(), row_offset);
2210 Index nb = block_b.asm_neighbor_owner_data_mir(local_matrix.block_b(), row_mirror.template at<0>(), buffer, global_dof_idx.template at<1>(), row_offset);
2211 XASSERT(na == nb);
2212 Index nd = block_d.asm_neighbor_owner_data_mir(local_matrix.block_d(), row_mirror.template at<1>(), buffer, global_dof_idx.template at<0>(), row_offset + na);
2213 return na + nd;
2214 }
2215
2216 template<
2217 typename MirrorV_, typename MirrorP_,
2218 typename IdxVecV_, typename IdxVecP_>
2219 Index asm_owned_data_mir(
2220 const LAFEM::SaddlePointMatrix<MatrixA_, MatrixB_, MatrixD_>& local_matrix,
2221 const Adjacency::Graph& owned_graph,
2222 const LAFEM::TupleMirror<MirrorV_, MirrorP_>& row_mirror,
2223 const LAFEM::TupleVector<IdxVecV_, IdxVecP_>& global_dof_idx,
2224 Index row_offset)
2225 {
2226 Index na = block_a.asm_owned_data_mir(local_matrix.block_a(), owned_graph, row_mirror.template at<0>(), global_dof_idx.template at<0>(), row_offset);
2227 Index nb = block_b.asm_owned_data_mir(local_matrix.block_b(), owned_graph, row_mirror.template at<0>(), global_dof_idx.template at<1>(), row_offset);
2228 XASSERT(na == nb);
2229 Index nd = block_d.asm_owned_data_mir(local_matrix.block_d(), owned_graph, row_mirror.template at<1>(), global_dof_idx.template at<0>(), row_offset + na);
2230 return na + nd;
2231 }
2232
2233 template<typename DTA_>
2234 void upload_owned_data(DTA_* adp_val, const LAFEM::SaddlePointMatrix<MatrixA_, MatrixB_, MatrixD_>& local_matrix) const
2235 {
2236 block_a.upload_owned_data(adp_val, local_matrix.block_a());
2237 block_b.upload_owned_data(adp_val, local_matrix.block_b());
2238 block_d.upload_owned_data(adp_val, local_matrix.block_d());
2239 }
2240
2241 void gather_owner_data(
2242 LAFEM::DenseVector<DT_, IT_>& buffer,
2243 const LAFEM::SaddlePointMatrix<MatrixA_, MatrixB_, MatrixD_>& local_matrix) const
2244 {
2245 block_a.gather_owner_data(buffer, local_matrix.block_a());
2246 block_b.gather_owner_data(buffer, local_matrix.block_b());
2247 block_d.gather_owner_data(buffer, local_matrix.block_d());
2248 }
2249 }; // class ADPDOMM<LAFEM::SaddlePointMatrix<MatrixA_, MatrixB_, MatrixD_>>
2250
2252
2253 template<typename DT_, typename IT_>
2254 class ADPMatAux<LAFEM::SparseMatrixCSR<DT_, IT_>>
2255 {
2256 public:
2257 static Index calc_mat_buf_num_rows(
2258 const LAFEM::SparseMatrixCSR<DT_, IT_>& DOXY(local_matrix),
2259 const LAFEM::VectorMirror<DT_, IT_>& row_mirror)
2260 {
2261 return row_mirror.num_indices();
2262 }
2263
2264 static Index calc_mat_buf_row_nze(
2265 IT_* buf_row_nze,
2266 const LAFEM::SparseMatrixCSR<DT_, IT_>& local_matrix,
2267 const LAFEM::VectorMirror<DT_, IT_>& row_mirror)
2268 {
2269 const Index num_idx = row_mirror.num_indices();
2270 const Memory::TypedView<IT_> mir_idx = row_mirror.indices_view_r();
2271 const Memory::TypedView<IT_> row_ptr = local_matrix.row_ptr_view_r();
2272
2273 for(Index i(0); i < num_idx; ++i)
2274 {
2275 buf_row_nze[i] += (row_ptr[mir_idx[i]+1] - row_ptr[mir_idx[i]]);
2276 }
2277
2278 return num_idx;
2279 }
2280
2281 static Index gather_mat_buf_col_idx(
2282 IT_* aux_row_ptr,
2283 IT_* buf_col_idx,
2284 const LAFEM::SparseMatrixCSR<DT_, IT_>& local_matrix,
2285 const LAFEM::VectorMirror<DT_, IT_>& row_mirror,
2286 const LAFEM::DenseVector<IT_, IT_>& global_dof_idx)
2287 {
2288 const Index num_idx = row_mirror.num_indices();
2289 const Memory::TypedView<IT_> mir_idx = row_mirror.indices_view_r();
2290 const Memory::TypedView<IT_> row_ptr = local_matrix.row_ptr_view_r();
2291 const Memory::TypedView<IT_> col_idx = local_matrix.col_idx_view_r();
2292 const Memory::TypedView<IT_> glob_dof_idx = global_dof_idx.elements_view_r();
2293
2294 for(Index i(0); i < num_idx; ++i)
2295 {
2296 // k must be a reference as we need to update the auxiliary row pointer
2297 IT_& k = aux_row_ptr[i];
2298 const IT_ row = mir_idx[i];
2299
2300 // map local DOFs to global DOFs
2301 for(IT_ j(row_ptr[row]); j < row_ptr[row+1]; ++j, ++k)
2302 buf_col_idx[k] = glob_dof_idx[col_idx[j]];
2303 }
2304
2305 return num_idx;
2306 }
2307
2308 static Index gather_owned_struct(
2309 Adjacency::DynamicGraph& graph,
2310 const LAFEM::SparseMatrixCSR<DT_, IT_>& local_matrix,
2311 const LAFEM::VectorMirror<DT_, IT_>& row_mirror,
2312 const LAFEM::DenseVector<IT_, IT_>& global_dof_idx,
2313 const Index row_offset)
2314 {
2315 const Index num_rows = row_mirror.num_indices();
2316 const Memory::TypedView<IT_> loc_row_ptr = local_matrix.row_ptr_view_r();
2317 const Memory::TypedView<IT_> loc_col_idx = local_matrix.col_idx_view_r();
2318 const Memory::TypedView<IT_> row_mir_idx = row_mirror.indices_view_r();
2319 const Memory::TypedView<IT_> glob_dof_idx = global_dof_idx.elements_view_r();
2320
2321 for(Index i(0); i < num_rows; ++i)
2322 {
2323 const IT_ lrow = row_mir_idx[i];
2324 for(IT_ j(loc_row_ptr[lrow]); j < loc_row_ptr[lrow + 1]; ++j)
2325 {
2326 graph.insert(row_offset + i, Index(glob_dof_idx[loc_col_idx[j]]));
2327 }
2328 }
2329 return num_rows;
2330 }
2331 }; // class ADPMatAux<LAFEM::SparseMatrixCSR<DT_, IT_>>
2332
2334
2335 template<typename DT_, typename IT_, int bh_, int bw_>
2336 class ADPMatAux<LAFEM::SparseMatrixBCSR<DT_, IT_, bh_, bw_>>
2337 {
2338 public:
2339 static Index calc_mat_buf_num_rows(
2340 const LAFEM::SparseMatrixBCSR<DT_, IT_, bh_, bw_>& DOXY(local_matrix),
2341 const LAFEM::VectorMirror<DT_, IT_>& row_mirror)
2342 {
2343 return row_mirror.num_indices() * Index(bh_);
2344 }
2345
2346 static Index calc_mat_buf_row_nze(
2347 IT_* buf_row_nze,
2348 const LAFEM::SparseMatrixBCSR<DT_, IT_, bh_, bw_>& local_matrix,
2349 const LAFEM::VectorMirror<DT_, IT_>& row_mirror)
2350 {
2351 const Index num_idx = row_mirror.num_indices();
2352 const Memory::TypedView<IT_> mir_idx = row_mirror.indices_view_r();
2353 const Memory::TypedView<IT_> row_ptr = local_matrix.row_ptr_view_r();
2354
2355 for(Index i(0), j(0); i < num_idx; ++i)
2356 {
2357 IT_ nn = IT_(bw_) * (row_ptr[mir_idx[i]+1] - row_ptr[mir_idx[i]]);
2358 for(int k(0); k < bh_; ++k, ++j)
2359 buf_row_nze[j] += nn;
2360 }
2361
2362 return num_idx * Index(bh_);
2363 }
2364
2365 static Index gather_mat_buf_col_idx(
2366 IT_* aux_row_ptr,
2367 IT_* buf_col_idx,
2368 const LAFEM::SparseMatrixBCSR<DT_, IT_, bh_, bw_>& local_matrix,
2369 const LAFEM::VectorMirror<DT_, IT_>& row_mirror,
2370 const LAFEM::DenseVectorBlocked<IT_, IT_, bw_>& global_dof_idx)
2371 {
2372 const Index num_idx = row_mirror.num_indices();
2373 const Memory::TypedView<IT_> mir_idx = row_mirror.indices_view_r();
2374 const Memory::TypedView<IT_> row_ptr = local_matrix.row_ptr_view_r();
2375 const Memory::TypedView<IT_> col_idx = local_matrix.col_idx_view_r();
2376 const Memory::TypedView<Tiny::Vector<IT_,bw_>> glob_dof_idx = global_dof_idx.elements_view_r();
2377
2378 for(Index i(0); i < num_idx; ++i)
2379 {
2380 const IT_ row = mir_idx[i];
2381
2382 // loop over the rows of the block
2383 for(int bi(0); bi < bh_; ++bi)
2384 {
2385 // k must be a reference as we need to update the auxiliary row pointer
2386 IT_& k = aux_row_ptr[i*IT_(bh_) + IT_(bi)];
2387
2388 // map local DOFs to global DOFs
2389 for(IT_ j(row_ptr[row]); j < row_ptr[row+1]; ++j)
2390 {
2391 // loop over the columns of this block
2392 for(int bj(0); bj < bw_; ++bj, ++k)
2393 {
2394 buf_col_idx[k] = glob_dof_idx[col_idx[j]][bj];
2395 }
2396 }
2397 }
2398 }
2399
2400 return num_idx * Index(bh_);
2401 }
2402
2403 static Index gather_mat_buf_col_idx(
2404 IT_* aux_row_ptr,
2405 IT_* buf_col_idx,
2406 const LAFEM::SparseMatrixBCSR<DT_, IT_, bh_, 1>& local_matrix,
2407 const LAFEM::VectorMirror<DT_, IT_>& row_mirror,
2408 const LAFEM::DenseVector<IT_, IT_>& global_dof_idx)
2409 {
2410 const Index num_idx = row_mirror.num_indices();
2411 const Memory::TypedView<IT_> mir_idx = row_mirror.indices_view_r();
2412 const Memory::TypedView<IT_> row_ptr = local_matrix.row_ptr_view_r();
2413 const Memory::TypedView<IT_> col_idx = local_matrix.col_idx_view_r();
2414 const Memory::TypedView<IT_> glob_dof_idx = global_dof_idx.elements_view_r();
2415
2416 for(Index i(0); i < num_idx; ++i)
2417 {
2418 const IT_ row = mir_idx[i];
2419
2420 // loop over the rows of the block
2421 for(int bi(0); bi < bh_; ++bi)
2422 {
2423 // k must be a reference as we need to update the auxiliary row pointer
2424 IT_& k = aux_row_ptr[i*IT_(bh_) + IT_(bi)];
2425
2426 // map local DOFs to global DOFs
2427 for(IT_ j(row_ptr[row]); j < row_ptr[row+1]; ++j, ++k)
2428 {
2429 buf_col_idx[k] = glob_dof_idx[col_idx[j]];
2430 }
2431 }
2432 }
2433
2434 return num_idx * Index(bh_);
2435 }
2436
2437 static Index gather_owned_struct(
2438 Adjacency::DynamicGraph& graph,
2439 const LAFEM::SparseMatrixBCSR<DT_, IT_, bh_, bw_>& local_matrix,
2440 const LAFEM::VectorMirror<DT_, IT_>& row_mirror,
2441 const LAFEM::DenseVectorBlocked<IT_, IT_, bw_>& global_dof_idx,
2442 const Index row_offset)
2443 {
2444 const Index num_rows = row_mirror.num_indices();
2445 const Memory::TypedView<IT_> mir_idx = row_mirror.indices_view_r();
2446 const Memory::TypedView<IT_> row_ptr = local_matrix.row_ptr_view_r();
2447 const Memory::TypedView<IT_> col_idx = local_matrix.col_idx_view_r();
2448 const Memory::TypedView<Tiny::Vector<IT_, bw_>> glob_dof_idx = global_dof_idx.elements_view_r();
2449
2450 for(Index i(0); i < num_rows; ++i)
2451 {
2452 const Index lrow = mir_idx[i];
2453 for(IT_ j(row_ptr[lrow]); j < row_ptr[lrow + 1]; ++j)
2454 {
2455 const auto& gci = glob_dof_idx[col_idx[j]];
2456 for(int bi = 0; bi < bh_; ++bi)
2457 {
2458 for(int bj = 0; bj < bw_; ++bj)
2459 {
2460 graph.insert(row_offset + i*Index(bh_) + Index(bi), Index(gci[bj]));
2461 }
2462 }
2463 }
2464 }
2465 return num_rows * Index(bh_);
2466 }
2467
2468 static Index gather_owned_struct(
2469 Adjacency::DynamicGraph& graph,
2470 const LAFEM::SparseMatrixBCSR<DT_, IT_, bh_, 1>& local_matrix,
2471 const LAFEM::VectorMirror<DT_, IT_>& row_mirror,
2472 const LAFEM::DenseVector<IT_, IT_>& global_dof_idx,
2473 const Index row_offset)
2474 {
2475 const Index num_rows = row_mirror.num_indices();
2476 const Memory::TypedView<IT_> mir_idx = row_mirror.indices_view_r();
2477 const Memory::TypedView<IT_> row_ptr = local_matrix.row_ptr_view_r();
2478 const Memory::TypedView<IT_> col_idx = local_matrix.col_idx_view_r();
2479 const Memory::TypedView<IT_> glob_dof_idx = global_dof_idx.elements_view_r();
2480
2481 for(Index i(0); i < num_rows; ++i)
2482 {
2483 const Index lrow = mir_idx[i];
2484 for(IT_ j(row_ptr[lrow]); j < row_ptr[lrow + 1]; ++j)
2485 {
2486 const IT_ gci = glob_dof_idx[col_idx[j]];
2487 for(int bi = 0; bi < bh_; ++bi)
2488 {
2489 graph.insert(row_offset + i*Index(bh_) + Index(bi), Index(gci));
2490 }
2491 }
2492 }
2493 return num_rows * Index(bh_);
2494 }
2495 }; // class ADPMatAux<LAFEM::SparseMatrixBCSR<DT_, IT_, bh_, bw_>>
2496
2498
2499 template<typename DT_, typename IT_, int bh_, int bw_>
2500 class ADPMatAux<LAFEM::NullMatrix<DT_, IT_, bh_, bw_>>
2501 {
2502 public:
2503 static Index calc_mat_buf_num_rows(
2504 const LAFEM::NullMatrix<DT_, IT_, bh_, bw_>&,
2505 const LAFEM::VectorMirror<DT_, IT_>& row_mirror)
2506 {
2507 return row_mirror.num_indices() * Index(bh_);
2508 }
2509
2510 static Index calc_mat_buf_row_nze(
2511 IT_*,
2512 const LAFEM::NullMatrix<DT_, IT_, bh_, bw_>&,
2513 const LAFEM::VectorMirror<DT_, IT_>& row_mirror)
2514 {
2515 return row_mirror.num_indices() * Index(bh_);
2516 }
2517
2518 static Index gather_mat_buf_col_idx(
2519 IT_*,
2520 IT_*,
2521 const LAFEM::NullMatrix<DT_, IT_, bh_, bw_>&,
2522 const LAFEM::VectorMirror<DT_, IT_>& row_mirror,
2523 const LAFEM::DenseVectorBlocked<IT_, IT_, bw_>&)
2524 {
2525 return row_mirror.num_indices() * Index(bh_);
2526 }
2527
2528 static Index gather_mat_buf_col_idx(
2529 IT_*,
2530 IT_*,
2531 const LAFEM::NullMatrix<DT_, IT_, bh_, 1>&,
2532 const LAFEM::VectorMirror<DT_, IT_>& row_mirror,
2533 const LAFEM::DenseVector<IT_, IT_>&)
2534 {
2535 return row_mirror.num_indices() * Index(bh_);
2536 }
2537
2538 static Index gather_owned_struct(
2539 Adjacency::DynamicGraph&,
2540 const LAFEM::NullMatrix<DT_, IT_, bh_, bw_>&,
2541 const LAFEM::VectorMirror<DT_, IT_>& row_mirror,
2542 const LAFEM::DenseVectorBlocked<IT_, IT_, bw_>&,
2543 const Index)
2544 {
2545 return row_mirror.num_indices() * Index(bh_);
2546 }
2547
2548 static Index gather_owned_struct(
2549 Adjacency::DynamicGraph&,
2550 const LAFEM::NullMatrix<DT_, IT_, bh_, 1>&,
2551 const LAFEM::VectorMirror<DT_, IT_>& row_mirror,
2552 const LAFEM::DenseVector<IT_, IT_>&,
2553 const Index)
2554 {
2555 return row_mirror.num_indices() * Index(bh_);
2556 }
2557 }; // class ADPMatAux<LAFEM::NullMatrix<DT_, IT_, bh_, bw_>>
2558
2560
2561 template<typename FirstMatrix_, typename... RestMatrix_>
2562 class ADPMatAux<LAFEM::TupleMatrixRow<FirstMatrix_, RestMatrix_...>>
2563 {
2564 public:
2565 typedef typename FirstMatrix_::IndexType IT_;
2566 typedef ADPMatAux<FirstMatrix_> ADPMatAuxFirst;
2567 typedef ADPMatAux<LAFEM::TupleMatrixRow<RestMatrix_...>> ADPMatAuxRest;
2568
2569 template<typename RowMirror_>
2570 static Index calc_mat_buf_num_rows(
2571 const LAFEM::TupleMatrixRow<FirstMatrix_, RestMatrix_...>& local_matrix,
2572 const RowMirror_& row_mirror)
2573 {
2574 Index n1 = ADPMatAuxFirst::calc_mat_buf_num_rows(local_matrix.first(), row_mirror);
2575 Index n2 = ADPMatAuxRest::calc_mat_buf_num_rows(local_matrix.rest(), row_mirror);
2576 XASSERT(n1 == n2);
2577 return n1;
2578 }
2579
2580 template<typename RowMirror_>
2581 static Index calc_mat_buf_row_nze(
2582 IT_* buf_row_nze,
2583 const LAFEM::TupleMatrixRow<FirstMatrix_, RestMatrix_...>& local_matrix,
2584 const RowMirror_& row_mirror)
2585 {
2586 Index n1 = ADPMatAuxFirst::calc_mat_buf_row_nze(buf_row_nze, local_matrix.first(), row_mirror);
2587 Index n2 = ADPMatAuxRest::calc_mat_buf_row_nze(buf_row_nze, local_matrix.rest(), row_mirror);
2588 XASSERT(n1 == n2);
2589 return n1;
2590 }
2591
2592 template<
2593 typename RowMirror_,
2594 typename FirstIdxVec_, typename... RestIdxVec_>
2595 static Index gather_mat_buf_col_idx(
2596 IT_* aux_row_ptr,
2597 IT_* buf_col_idx,
2598 const LAFEM::TupleMatrixRow<FirstMatrix_, RestMatrix_...>& local_matrix,
2599 const RowMirror_& row_mirror,
2600 const LAFEM::TupleVector<FirstIdxVec_, RestIdxVec_...>& global_dof_idx)
2601 {
2602 Index n1 = ADPMatAuxFirst::gather_mat_buf_col_idx(aux_row_ptr, buf_col_idx, local_matrix.first(), row_mirror, global_dof_idx.first());
2603 Index n2 = ADPMatAuxRest::gather_mat_buf_col_idx(aux_row_ptr, buf_col_idx, local_matrix.rest(), row_mirror, global_dof_idx.rest());
2604 XASSERT(n1 == n2);
2605 return n1;
2606 }
2607
2608 template<
2609 typename RowMirror_,
2610 typename FirstIdxVec_, typename... RestIdxVec_>
2611 static Index gather_owned_struct(
2612 Adjacency::DynamicGraph& graph,
2613 const LAFEM::TupleMatrixRow<FirstMatrix_, RestMatrix_...>& local_matrix,
2614 const RowMirror_& row_mirror,
2615 const LAFEM::TupleVector<FirstIdxVec_, RestIdxVec_...>& global_dof_idx,
2616 const Index row_offset)
2617 {
2618 Index n1 = ADPMatAuxFirst::gather_owned_struct(graph, local_matrix.first(), row_mirror, global_dof_idx.first(), row_offset);
2619 Index n2 = ADPMatAuxRest::gather_owned_struct(graph, local_matrix.rest(), row_mirror, global_dof_idx.rest(), row_offset);
2620 XASSERT(n1 == n2);
2621 return n1;
2622 }
2623 }; // class ADPMatAux<LAFEM::TupleMatrixRow<FirstMatrix_, RestMatrix_...>>
2624
2626
2627 template<typename FirstMatrix_>
2628 class ADPMatAux<LAFEM::TupleMatrixRow<FirstMatrix_>>
2629 {
2630 public:
2631 typedef typename FirstMatrix_::IndexType IT_;
2632 typedef ADPMatAux<FirstMatrix_> ADPMatAuxFirst;
2633
2634 template<typename RowMirror_>
2635 static Index calc_mat_buf_num_rows(
2636 const LAFEM::TupleMatrixRow<FirstMatrix_>& local_matrix,
2637 const RowMirror_& row_mirror)
2638 {
2639 return ADPMatAuxFirst::calc_mat_buf_num_rows(local_matrix.first(), row_mirror);
2640 }
2641
2642 template<typename RowMirror_>
2643 static Index calc_mat_buf_row_nze(
2644 IT_* buf_row_nze,
2645 const LAFEM::TupleMatrixRow<FirstMatrix_>& local_matrix,
2646 const RowMirror_& row_mirror)
2647 {
2648 return ADPMatAuxFirst::calc_mat_buf_row_nze(buf_row_nze, local_matrix.first(), row_mirror);
2649 }
2650
2651 template<
2652 typename RowMirror_,
2653 typename FirstIdxVec_>
2654 static Index gather_mat_buf_col_idx(
2655 IT_* aux_row_ptr,
2656 IT_* buf_col_idx,
2657 const LAFEM::TupleMatrixRow<FirstMatrix_>& local_matrix,
2658 const RowMirror_& row_mirror,
2659 const LAFEM::TupleVector<FirstIdxVec_>& global_dof_idx)
2660 {
2661 return ADPMatAuxFirst::gather_mat_buf_col_idx(aux_row_ptr, buf_col_idx, local_matrix.first(), row_mirror, global_dof_idx.first());
2662 }
2663
2664 template<
2665 typename RowMirror_,
2666 typename FirstIdxVec_>
2667 static Index gather_owned_struct(
2668 Adjacency::DynamicGraph& graph,
2669 const LAFEM::TupleMatrixRow<FirstMatrix_>& local_matrix,
2670 const RowMirror_& row_mirror,
2671 const LAFEM::TupleVector<FirstIdxVec_>& global_dof_idx,
2672 const Index row_offset)
2673 {
2674 return ADPMatAuxFirst::gather_owned_struct(graph, local_matrix.first(), row_mirror, global_dof_idx.first(), row_offset);
2675 }
2676 }; // class ADPMatAux<LAFEM::TupleMatrixRow<FirstMatrix_>>
2677
2679
2680 template<typename FirstMatRow_, typename... RestMatRow_>
2681 class ADPMatAux<LAFEM::TupleMatrix<FirstMatRow_, RestMatRow_...>>
2682 {
2683 public:
2684 typedef typename FirstMatRow_::IndexType IT_;
2685 typedef ADPMatAux<FirstMatRow_> ADPMatAuxFirst;
2686 typedef ADPMatAux<LAFEM::TupleMatrix<RestMatRow_...>> ADPMatAuxRest;
2687
2688 template<typename FirstMirror_, typename... RestMirror_>
2689 static Index calc_mat_buf_num_rows(
2690 const LAFEM::TupleMatrix<FirstMatRow_, RestMatRow_...>& local_matrix,
2691 const LAFEM::TupleMirror<FirstMirror_, RestMirror_...>& row_mirror)
2692 {
2693 Index n1 = ADPMatAuxFirst::calc_mat_buf_num_rows(local_matrix.first(), row_mirror.first());
2694 Index n2 = ADPMatAuxRest::calc_mat_buf_num_rows(local_matrix.rest(), row_mirror.rest());
2695 return n1 + n2;
2696 }
2697
2698 template<typename FirstMirror_, typename... RestMirror_>
2699 static Index calc_mat_buf_row_nze(
2700 IT_* buf_row_nze,
2701 const LAFEM::TupleMatrix<FirstMatRow_, RestMatRow_...>& local_matrix,
2702 const LAFEM::TupleMirror<FirstMirror_, RestMirror_...>& row_mirror)
2703 {
2704 Index n1 = ADPMatAuxFirst::calc_mat_buf_row_nze(buf_row_nze, local_matrix.first(), row_mirror.first());
2705 Index n2 = ADPMatAuxRest::calc_mat_buf_row_nze(&buf_row_nze[n1], local_matrix.rest(), row_mirror.rest());
2706 return n1 + n2;
2707 }
2708
2709 template<
2710 typename FirstMirror_, typename... RestMirror_,
2711 typename IndexVector_>
2712 static Index gather_mat_buf_col_idx(
2713 IT_* aux_row_ptr,
2714 IT_* buf_col_idx,
2715 const LAFEM::TupleMatrix<FirstMatRow_, RestMatRow_...>& local_matrix,
2716 const LAFEM::TupleMirror<FirstMirror_, RestMirror_...>& row_mirror,
2717 const IndexVector_& global_dof_idx)
2718 {
2719 Index n1 = ADPMatAuxFirst::gather_mat_buf_col_idx(aux_row_ptr, buf_col_idx, local_matrix.first(), row_mirror.first(), global_dof_idx);
2720 Index n2 = ADPMatAuxRest::gather_mat_buf_col_idx(&aux_row_ptr[n1], buf_col_idx, local_matrix.rest(), row_mirror.rest(), global_dof_idx);
2721 return n1 + n2;
2722 }
2723
2724 template<
2725 typename FirstMirror_, typename... RestMirror_,
2726 typename IndexVector_>
2727 static Index gather_owned_struct(
2728 Adjacency::DynamicGraph& graph,
2729 const LAFEM::TupleMatrix<FirstMatRow_, RestMatRow_...>& local_matrix,
2730 const LAFEM::TupleMirror<FirstMirror_, RestMirror_...>& row_mirror,
2731 const IndexVector_& global_dof_idx,
2732 const Index row_offset)
2733 {
2734 Index n1 = ADPMatAuxFirst::gather_owned_struct(graph, local_matrix.first(), row_mirror.first(), global_dof_idx, row_offset);
2735 Index n2 = ADPMatAuxRest::gather_owned_struct(graph, local_matrix.rest(), row_mirror.rest(), global_dof_idx, row_offset + n1);
2736 return n1 + n2;
2737 }
2738 }; // class ADPMatAux<LAFEM::TupleMatrix<FirstMatRow_, RestMatRow_...>>
2739
2741
2742 template<typename FirstMatRow_>
2743 class ADPMatAux<LAFEM::TupleMatrix<FirstMatRow_>>
2744 {
2745 public:
2746 typedef typename FirstMatRow_::IndexType IT_;
2747 typedef ADPMatAux<FirstMatRow_> ADPMatAuxFirst;
2748
2749 template<typename FirstMirror_>
2750 static Index calc_mat_buf_num_rows(
2751 const LAFEM::TupleMatrix<FirstMatRow_>& local_matrix,
2752 const LAFEM::TupleMirror<FirstMirror_>& row_mirror)
2753 {
2754 return ADPMatAuxFirst::calc_mat_buf_num_rows(local_matrix.first(), row_mirror.first());
2755 }
2756
2757 template<typename FirstMirror_>
2758 static Index calc_mat_buf_row_nze(
2759 IT_* buf_row_nze,
2760 const LAFEM::TupleMatrix<FirstMatRow_>& local_matrix,
2761 const LAFEM::TupleMirror<FirstMirror_>& row_mirror)
2762 {
2763 return ADPMatAuxFirst::calc_mat_buf_row_nze(buf_row_nze, local_matrix.first(), row_mirror.first());
2764 }
2765
2766 template<
2767 typename FirstMirror_,
2768 typename IndexVector_>
2769 static Index gather_mat_buf_col_idx(
2770 IT_* aux_row_ptr,
2771 IT_* buf_col_idx,
2772 const LAFEM::TupleMatrix<FirstMatRow_>& local_matrix,
2773 const LAFEM::TupleMirror<FirstMirror_>& row_mirror,
2774 const IndexVector_& global_dof_idx)
2775 {
2776 return ADPMatAuxFirst::gather_mat_buf_col_idx(aux_row_ptr, buf_col_idx, local_matrix.first(), row_mirror.first(), global_dof_idx);
2777 }
2778
2779 template<
2780 typename FirstMirror_,
2781 typename IndexVector_>
2782 static Index gather_owned_struct(
2783 Adjacency::DynamicGraph& graph,
2784 const LAFEM::TupleMatrix<FirstMatRow_>& local_matrix,
2785 const LAFEM::TupleMirror<FirstMirror_>& row_mirror,
2786 const IndexVector_& global_dof_idx,
2787 const Index row_offset)
2788 {
2789 return ADPMatAuxFirst::gather_owned_struct(graph, local_matrix.first(), row_mirror.first(), global_dof_idx, row_offset);
2790 }
2791 }; // class ADPMatAux<LAFEM::TupleMatrix<FirstMatRow_>>
2792
2794
2795 template<typename MatrixA_, typename MatrixB_, typename MatrixD_>
2796 class ADPMatAux<LAFEM::SaddlePointMatrix<MatrixA_, MatrixB_, MatrixD_>>
2797 {
2798 public:
2799 typedef typename MatrixA_::IndexType IT_;
2800 typedef ADPMatAux<MatrixA_> ADPMatAuxA;
2801 typedef ADPMatAux<MatrixB_> ADPMatAuxB;
2802 typedef ADPMatAux<MatrixD_> ADPMatAuxD;
2803
2804 template<typename MirrorV_, typename MirrorP_>
2805 static Index calc_mat_buf_num_rows(
2806 const LAFEM::SaddlePointMatrix<MatrixA_, MatrixB_, MatrixD_>& local_matrix,
2807 const LAFEM::TupleMirror<MirrorV_, MirrorP_>& row_mirror)
2808 {
2809 Index n1 = ADPMatAuxB::calc_mat_buf_num_rows(local_matrix.block_b(), row_mirror.template at<0>());
2810 Index n2 = ADPMatAuxD::calc_mat_buf_num_rows(local_matrix.block_d(), row_mirror.template at<1>());
2811 return n1 + n2;
2812 }
2813
2814 template<typename MirrorV_, typename MirrorP_>
2815 static Index calc_mat_buf_row_nze(
2816 IT_* buf_row_nze,
2817 const LAFEM::SaddlePointMatrix<MatrixA_, MatrixB_, MatrixD_>& local_matrix,
2818 const LAFEM::TupleMirror<MirrorV_, MirrorP_>& row_mirror)
2819 {
2820 Index na = ADPMatAuxA::calc_mat_buf_row_nze(buf_row_nze, local_matrix.block_a(), row_mirror.template at<0>());
2821 Index nb = ADPMatAuxB::calc_mat_buf_row_nze(buf_row_nze, local_matrix.block_b(), row_mirror.template at<0>());
2822 XASSERT(na == nb);
2823 Index nd = ADPMatAuxD::calc_mat_buf_row_nze(&buf_row_nze[na], local_matrix.block_d(), row_mirror.template at<1>());
2824
2825 // \todo invent main diagonal for pressure block
2826 //for(Index i = 0u; i < nd; ++i)
2827 //++buf_row_nze[na + i];
2828
2829 return na + nd;
2830 }
2831
2832 template<
2833 typename MirrorV_, typename MirrorP_,
2834 typename IdxVecV_, typename IdxVecP_>
2835 static Index gather_mat_buf_col_idx(
2836 IT_* aux_row_ptr,
2837 IT_* buf_col_idx,
2838 const LAFEM::SaddlePointMatrix<MatrixA_, MatrixB_, MatrixD_>& local_matrix,
2839 const LAFEM::TupleMirror<MirrorV_, MirrorP_>& row_mirror,
2840 const LAFEM::TupleVector<IdxVecV_, IdxVecP_>& global_dof_idx)
2841 {
2842 Index na = ADPMatAuxA::gather_mat_buf_col_idx(aux_row_ptr, buf_col_idx, local_matrix.block_a(), row_mirror.template at<0>(), global_dof_idx.template at<0>());
2843 Index nb = ADPMatAuxB::gather_mat_buf_col_idx(aux_row_ptr, buf_col_idx, local_matrix.block_b(), row_mirror.template at<0>(), global_dof_idx.template at<1>());
2844 XASSERT(na == nb);
2845 Index nd = ADPMatAuxD::gather_mat_buf_col_idx(&aux_row_ptr[na], buf_col_idx, local_matrix.block_d(), row_mirror.template at<1>(), global_dof_idx.template at<0>());
2846
2847 // \todo invent main diagonal for pressure block
2848 //const auto* p_dof_idx = global_dof_idx.template at<1>().elements();
2849 //for(Index i = 0u; i < nd; ++i)
2850 //buf_col_idx[aux_row_ptr[na + i]] = p_dof_idx[i];
2851
2852 return na + nd;
2853 }
2854
2855 template<
2856 typename MirrorV_, typename MirrorP_,
2857 typename IdxVecV_, typename IdxVecP_>
2858 static Index gather_owned_struct(
2859 Adjacency::DynamicGraph& graph,
2860 const LAFEM::SaddlePointMatrix<MatrixA_, MatrixB_, MatrixD_>& local_matrix,
2861 const LAFEM::TupleMirror<MirrorV_, MirrorP_>& row_mirror,
2862 const LAFEM::TupleVector<IdxVecV_, IdxVecP_>& global_dof_idx,
2863 const Index row_offset)
2864 {
2865 Index na = ADPMatAuxA::gather_owned_struct(graph, local_matrix.block_a(), row_mirror.template at<0>(), global_dof_idx.template at<0>(), row_offset);
2866 Index nb = ADPMatAuxB::gather_owned_struct(graph, local_matrix.block_b(), row_mirror.template at<0>(), global_dof_idx.template at<1>(), row_offset);
2867 XASSERT(na == nb);
2868 Index nd = ADPMatAuxD::gather_owned_struct(graph, local_matrix.block_d(), row_mirror.template at<1>(), global_dof_idx.template at<0>(), row_offset + na);
2869
2870 // invent main diagonal for pressure block
2871 {
2872 const auto p_dof_idx = global_dof_idx.template at<1>().elements_view_r();
2873 for(Index i = 0u; i < nd; ++i)
2874 graph.insert(na + i, p_dof_idx[i]);
2875 }
2876
2877 return na + nd;
2878 }
2879 }; // class ADPMatAux<LAFEM::SaddlePointMatrix<MatrixA_, MatrixB_, MatrixD_>>
2880
2884
2885 template<typename DT_, typename IT_>
2886 class ADPFilAux<LAFEM::NoneFilter<DT_, IT_>>
2887 {
2888 public:
2889 static Index row_count(const LAFEM::VectorMirror<DT_, IT_>& row_mirror)
2890 {
2891 return row_mirror.num_indices();
2892 }
2893
2894 static Index upload_filter(
2895 LAFEM::SparseVectorFactory<DT_, IT_>& DOXY(factory),
2896 const LAFEM::NoneFilter<DT_, IT_>& DOXY(filter),
2897 const LAFEM::VectorMirror<DT_, IT_>& row_mirror,
2898 Index DOXY(row_offset))
2899 {
2900 // nothing to do here
2901 return row_count(row_mirror);
2902 }
2903 }; // class ADPFilAux<LAFEM::NoneFilter<DT_, IT_>>
2904
2906
2907 template<typename DT_, typename IT_, int bs_>
2908 class ADPFilAux<LAFEM::NoneFilterBlocked<DT_, IT_, bs_>>
2909 {
2910 public:
2911 static Index row_count(const LAFEM::VectorMirror<DT_, IT_>& row_mirror)
2912 {
2913 return row_mirror.num_indices() * Index(bs_);
2914 }
2915
2916 static Index upload_filter(
2917 LAFEM::SparseVectorFactory<DT_, IT_>& DOXY(factory),
2918 const LAFEM::NoneFilterBlocked<DT_, IT_, bs_>& DOXY(filter),
2919 const LAFEM::VectorMirror<DT_, IT_>& row_mirror,
2920 Index DOXY(row_offset))
2921 {
2922 // nothing to do here
2923 return row_count(row_mirror);
2924 }
2925 }; // class ADPFilAux<LAFEM::NoneFilterBlocked<DT_, IT_, bs_>>
2926
2928
2929 template<typename DT_, typename IT_>
2930 class ADPFilAux<LAFEM::UnitFilter<DT_, IT_>>
2931 {
2932 public:
2933 static Index row_count(const LAFEM::VectorMirror<DT_, IT_>& row_mirror)
2934 {
2935 return row_mirror.num_indices();
2936 }
2937
2938 static Index upload_filter(
2939 LAFEM::SparseVectorFactory<DT_, IT_>& factory,
2940 const LAFEM::UnitFilter<DT_, IT_>& filter,
2941 const LAFEM::VectorMirror<DT_, IT_>& row_mirror,
2942 Index row_offset)
2943 {
2944 if(filter.num_nzes() <= Index(0))
2945 return row_count(row_mirror);
2946
2947 const Memory::TypedView<IT_> fil_idx = filter.get_filter_vector().indices_view_r();
2948 const Memory::TypedView<IT_> mir_idx = row_mirror.indices_view_r();
2949 const Index num_fil = filter.num_nzes();
2950 const Index num_mir = row_mirror.num_indices();
2951
2952 Index i = 0u, j = 0u;
2953 while((i < num_fil) && (j < num_mir))
2954 {
2955 if(fil_idx[i] < Index(mir_idx[j]))
2956 ++i;
2957 else if(fil_idx[i] > Index(mir_idx[j]))
2958 ++j;
2959 else
2960 {
2961 factory.add(IT_(row_offset + j), DT_(0));
2962 ++i;
2963 ++j;
2964 }
2965 }
2966
2967 return row_count(row_mirror);
2968 }
2969 }; // class ADPFilAux<LAFEM::UnitFilter<DT_, IT_>>
2970
2972
2973 template<typename DT_, typename IT_, int bs_>
2974 class ADPFilAux<LAFEM::UnitFilterBlocked<DT_, IT_, bs_>>
2975 {
2976 public:
2977 static Index row_count(const LAFEM::VectorMirror<DT_, IT_>& row_mirror)
2978 {
2979 return row_mirror.num_indices() * Index(bs_);
2980 }
2981
2982 static Index upload_filter(
2983 LAFEM::SparseVectorFactory<DT_, IT_>& factory,
2984 const LAFEM::UnitFilterBlocked<DT_, IT_, bs_>& filter,
2985 const LAFEM::VectorMirror<DT_, IT_>& row_mirror,
2986 Index row_offset)
2987 {
2988 if(filter.num_nzes() <= Index(0))
2989 return row_count(row_mirror);
2990
2991 const bool ignore_nans = filter.get_ignore_nans();
2992 const auto fil_val = filter.get_filter_vector().elements_view_r();
2993 const Memory::TypedView<IT_> fil_idx = filter.get_filter_vector().indices_view_r();
2994 const Memory::TypedView<IT_> mir_idx = row_mirror.indices_view_r();
2995 const Index num_fil = filter.num_nzes();
2996 const Index num_mir = row_mirror.num_indices();
2997
2998 Index i = 0u, j = 0u;
2999 while((i < num_fil) && (j < num_mir))
3000 {
3001 if(fil_idx[i] < Index(mir_idx[j]))
3002 ++i;
3003 else if(fil_idx[i] > Index(mir_idx[j]))
3004 ++j;
3005 else
3006 {
3007 // process the entire block
3008 for(int k = 0; k < bs_; ++k)
3009 {
3010 if(!ignore_nans || !Math::isnan(fil_val[i][k]))
3011 factory.add(IT_(row_offset + j*Index(bs_) + Index(k)), DT_(0));
3012 }
3013 ++i;
3014 }
3015 }
3016
3017 return row_count(row_mirror);
3018 }
3019 }; // class ADPFilAux<LAFEM::UnitFilterBlocked<DT_, IT_, bs_>>
3020
3022
3023 template<typename DT_, typename IT_>
3024 class ADPFilAux<LAFEM::MeanFilter<DT_, IT_>>
3025 {
3026 public:
3027 static Index row_count(const LAFEM::VectorMirror<DT_, IT_>& row_mirror)
3028 {
3029 return row_mirror.num_indices();
3030 }
3031
3032 static Index upload_filter(
3033 LAFEM::SparseVectorFactory<DT_, IT_>& DOXY(factory),
3034 const LAFEM::MeanFilter<DT_, IT_>& filter,
3035 const LAFEM::VectorMirror<DT_, IT_>& row_mirror,
3036 Index DOXY(row_offset))
3037 {
3038 XASSERTM(filter.empty(), "AlgDofParti does not support LAFEM::MeanFilter yet!");
3039 return row_count(row_mirror);
3040 }
3041 }; // class ADPFilAux<LAFEM::MeanFilter<DT_, IT_>>
3042
3044
3045 template<typename DT_, typename IT_, int bs_>
3046 class ADPFilAux<LAFEM::MeanFilterBlocked<DT_, IT_, bs_>>
3047 {
3048 public:
3049 static Index row_count(const LAFEM::VectorMirror<DT_, IT_>& row_mirror)
3050 {
3051 return row_mirror.num_indices() * Index(bs_);
3052 }
3053
3054 static Index upload_filter(
3055 LAFEM::SparseVectorFactory<DT_, IT_>& DOXY(factory),
3056 const LAFEM::MeanFilterBlocked<DT_, IT_, bs_>& filter,
3057 const LAFEM::VectorMirror<DT_, IT_>& row_mirror,
3058 Index DOXY(row_offset))
3059 {
3060 XASSERTM(filter.empty(), "AlgDofParti does not support LAFEM::MeanFilterBlocked yet!");
3061 return row_count(row_mirror);
3062 }
3063 }; // class ADPFilAux<LAFEM::MeanFilterBlocked<DT_, IT_, bs_>>
3064
3066
3067 template<typename DT_, typename IT_>
3068 class ADPFilAux<Global::MeanFilter<DT_, IT_>>
3069 {
3070 public:
3071 static Index row_count(const LAFEM::VectorMirror<DT_, IT_>& row_mirror)
3072 {
3073 return row_mirror.num_indices();
3074 }
3075
3076 static Index upload_filter(
3077 LAFEM::SparseVectorFactory<DT_, IT_>& DOXY(factory),
3078 const Global::MeanFilter<DT_, IT_>& filter,
3079 const LAFEM::VectorMirror<DT_, IT_>& row_mirror,
3080 Index DOXY(row_offset))
3081 {
3082 XASSERTM(filter.empty(), "AlgDofParti does not support Global::MeanFilter yet!");
3083 return row_count(row_mirror);
3084 }
3085 }; // class ADPFilAux<Global::MeanFilter<DT_, IT_>>
3086
3088
3089 template<typename DT_, typename IT_, int bs_>
3090 class ADPFilAux<LAFEM::SlipFilter<DT_, IT_, bs_>>
3091 {
3092 public:
3093 static Index row_count(const LAFEM::VectorMirror<DT_, IT_>& row_mirror)
3094 {
3095 return row_mirror.num_indices() * Index(bs_);
3096 }
3097
3098 static Index upload_filter(
3099 LAFEM::SparseVectorFactory<DT_, IT_>& DOXY(factory),
3100 const LAFEM::SlipFilter<DT_, IT_, bs_>& filter,
3101 const LAFEM::VectorMirror<DT_, IT_>& row_mirror,
3102 Index DOXY(row_offset))
3103 {
3104 XASSERTM(filter.empty(), "AlgDofParti does not support LAFEM::SlipFilter yet!");
3105 return row_count(row_mirror);
3106 }
3107 }; // class ADPFilAux<LAFEM::SlipFilter<DT_, IT_, bs_>>
3108
3110
3111 template<typename FirstFilter_, typename... RestFilter_>
3112 class ADPFilAux<LAFEM::FilterChain<FirstFilter_, RestFilter_...>>
3113 {
3114 public:
3115 typedef typename FirstFilter_::DataType DT_;
3116 typedef typename FirstFilter_::IndexType IT_;
3117 typedef ADPFilAux<FirstFilter_> ADPFilAuxFirst;
3118 typedef ADPFilAux<LAFEM::FilterChain<RestFilter_...>> ADPFilAuxRest;
3119
3120 static Index row_count(const LAFEM::VectorMirror<DT_, IT_>& row_mirror)
3121 {
3122 Index n1 = ADPFilAuxFirst::row_count(row_mirror);
3123 Index n2 = ADPFilAuxRest::row_count(row_mirror);
3124 XASSERT(n1 == n2);
3125 return n1;
3126 }
3127
3128 template<typename RowMirror_>
3129 static Index upload_filter(
3130 LAFEM::SparseVectorFactory<DT_, IT_>& factory,
3131 const LAFEM::FilterChain<FirstFilter_, RestFilter_...>& filter,
3132 const RowMirror_& row_mirror,
3133 Index row_offset)
3134 {
3135 Index n1 = ADPFilAuxFirst::upload_filter(factory, filter.first(), row_mirror, row_offset);
3136 Index n2 = ADPFilAuxRest::upload_filter(factory, filter.rest(), row_mirror, row_offset);
3137 XASSERT(n1 == n2);
3138 return n1;
3139 }
3140 }; // class ADPFilAux<LAFEM::FilterChain<FirstFilter_, RestFilter_...>>
3141
3143
3144 template<typename FirstFilter_>
3145 class ADPFilAux<LAFEM::FilterChain<FirstFilter_>>
3146 {
3147 public:
3148 typedef typename FirstFilter_::DataType DT_;
3149 typedef typename FirstFilter_::IndexType IT_;
3150 typedef ADPFilAux<FirstFilter_> ADPFilAuxFirst;
3151
3152 static Index row_count(const LAFEM::VectorMirror<DT_, IT_>& row_mirror)
3153 {
3154 return ADPFilAuxFirst::row_count(row_mirror);
3155 }
3156
3157 template<typename RowMirror_>
3158 static Index upload_filter(
3159 LAFEM::SparseVectorFactory<DT_, IT_>& factory,
3160 const LAFEM::FilterChain<FirstFilter_>& filter,
3161 const RowMirror_& row_mirror,
3162 Index row_offset)
3163 {
3164 return ADPFilAuxFirst::upload_filter(factory, filter.first(), row_mirror, row_offset);
3165 }
3166 }; // class ADPFilAux<LAFEM::FilterChain<FirstFilter_>>
3167
3169
3170 template<typename SubFilter_>
3171 class ADPFilAux<LAFEM::FilterSequence<SubFilter_>>
3172 {
3173 public:
3174 typedef typename SubFilter_::DataType DT_;
3175 typedef typename SubFilter_::IndexType IT_;
3176 typedef ADPFilAux<SubFilter_> ADPFilAuxSub;
3177
3178 static Index row_count(const LAFEM::VectorMirror<DT_, IT_>& row_mirror)
3179 {
3180 return ADPFilAuxSub::row_count(row_mirror);
3181 }
3182
3183 template<typename RowMirror_>
3184 static Index upload_filter(
3185 LAFEM::SparseVectorFactory<DT_, IT_>& factory,
3186 const LAFEM::FilterSequence<SubFilter_>& filter,
3187 const RowMirror_& row_mirror,
3188 Index row_offset)
3189 {
3190 for(const auto& x : filter)
3191 {
3192 ADPFilAuxSub::upload_filter(factory, x.second, row_mirror, row_offset);
3193 }
3194 return row_count(row_mirror);
3195 }
3196 }; // class ADPFilAux<LAFEM::FilterSequence<SubFilter_>>
3197
3199
3200 template<typename FirstFilter_, typename... RestFilter_>
3201 class ADPFilAux<LAFEM::TupleFilter<FirstFilter_, RestFilter_...>>
3202 {
3203 public:
3204 typedef typename FirstFilter_::DataType DT_;
3205 typedef typename FirstFilter_::IndexType IT_;
3206 typedef ADPFilAux<FirstFilter_> ADPFilAuxFirst;
3207 typedef ADPFilAux<LAFEM::TupleFilter<RestFilter_...>> ADPFilAuxRest;
3208
3209 static Index row_count(const LAFEM::VectorMirror<DT_, IT_>& row_mirror)
3210 {
3211 Index n1 = ADPFilAuxFirst::row_count(row_mirror);
3212 Index n2 = ADPFilAuxRest::row_count(row_mirror);
3213 return n1 + n2;
3214 }
3215
3216 template<typename FirstMirror_, typename... RestMirror_>
3217 static Index upload_filter(
3218 LAFEM::SparseVectorFactory<DT_, IT_>& factory,
3219 const LAFEM::TupleFilter<FirstFilter_, RestFilter_...>& filter,
3220 const LAFEM::TupleMirror<FirstMirror_, RestMirror_...>& row_mirror,
3221 Index row_offset)
3222 {
3223 Index n1 = ADPFilAuxFirst::upload_filter(factory, filter.first(), row_mirror.first(), row_offset);
3224 Index n2 = ADPFilAuxRest::upload_filter(factory, filter.rest(), row_mirror.rest(), row_offset + n1);
3225 return n1 + n2;
3226 }
3227 }; // class ADPFilAux<LAFEM::TupleFilter<FirstFilter_, RestFilter_...>>
3228
3230
3231 template<typename FirstFilter_>
3232 class ADPFilAux<LAFEM::TupleFilter<FirstFilter_>>
3233 {
3234 public:
3235 typedef typename FirstFilter_::DataType DT_;
3236 typedef typename FirstFilter_::IndexType IT_;
3237 typedef ADPFilAux<FirstFilter_> ADPFilAuxFirst;
3238
3239 static Index row_count(const LAFEM::VectorMirror<DT_, IT_>& row_mirror)
3240 {
3241 return ADPFilAuxFirst::row_count(row_mirror);
3242 }
3243
3244 template<typename FirstMirror_>
3245 static Index upload_filter(
3246 LAFEM::SparseVectorFactory<DT_, IT_>& factory,
3247 const LAFEM::TupleFilter<FirstFilter_>& filter,
3248 const LAFEM::TupleMirror<FirstMirror_>& row_mirror,
3249 Index row_offset)
3250 {
3251 return ADPFilAuxFirst::upload_filter(factory, filter.first(), row_mirror.first(), row_offset);
3252 }
3253 }; // class ADPFilAux<LAFEM::TupleFilter<FirstFilter_, RestFilter_...>>
3254 } // namespace Intern
3256 } // namespace Global
3257} // namespace FEAT
#define ASSERT(expr)
Debug-Assertion macro definition.
Definition: assertion.hpp:229
#define ASSERTM(expr, msg)
Debug-Assertion macro definition with custom message.
Definition: assertion.hpp:230
#define XASSERT(expr)
Assertion macro definition.
Definition: assertion.hpp:262
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Definition: assertion.hpp:263
Dynamic Adjacency Graph implementation.
void clear()
Clears the graph.
bool insert(Index domain_node, Index image_node)
Inserts a new adjacency entry to the graph.
Index get_num_indices() const
Returns the total number of indices.
Adjacency Graph implementation.
Definition: graph.hpp:34
Index * get_domain_ptr()
Returns the domain pointer array.
Definition: graph.hpp:359
Index * get_image_idx()
Returns the image node index array.
Definition: graph.hpp:374
Index get_num_indices() const
Returns the total number indices.
Definition: graph.hpp:390
Communicator class.
Definition: dist.hpp:1657
void allreduce(const void *sendbuf, void *recvbuf, std::size_t count, const Datatype &datatype, const Operation &op) const
Blocking All-Reduce.
Definition: dist.cpp:658
Request irecv(void *buffer, std::size_t count, const Datatype &datatype, int source, int tag=0) const
Nonblocking Receive.
Definition: dist.cpp:719
Request isend(const void *buffer, std::size_t count, const Datatype &datatype, int dest, int tag=0) const
Nonblocking Send.
Definition: dist.cpp:707
void allgatherv(const void *sendbuf, std::size_t sendcount, const Datatype &sendtype, void *recvbuf, const int *recvcounts, const int *displs, const Datatype &recvtype) const
Blocking gather-to-all.
Definition: dist.cpp:610
Communication Request vector class.
Definition: dist.hpp:948
bool wait_any(std::size_t &idx, Status &status)
Blocks until one of the active requests has been fulfilled.
Definition: dist.cpp:332
void wait_all()
Blocks until all active requests are fulfilled.
Definition: dist.cpp:327
Algebraic DOF Partitioning implementation.
int get_donee_rank(Index i) const
Returns an donee neighbor rank.
const OwnedMirrorType & get_owned_mirror() const
Returns the Mirror of the owned DOFs.
const OwnerMirrorType & get_owner_mirror(Index i) const
Returns an owner neighbor mirror.
LocalVectorType::template ContainerTypeByDI< IndexType, IndexType > IndexVectorType
the index vector type, this one is required for internal computations
const IndexVectorType & get_global_dof_indices() const
Returns the global-dof-indices array.
int get_owner_rank(Index i) const
Returns an owner neighbor rank.
Index get_num_owner_neighbors() const
Index get_num_donee_neighbors() const
const DoneeMirrorType & get_donee_mirror(Index i) const
Returns a donee neighbor mirror.
Index get_num_global_dofs() const
Index get_num_owned_dofs() const
Algebraic DOF partitioning linear system conversion class.
Index _num_owned_non_zeros
number of non-zero entries owned by this process
void filter_vec_cor(DTV_ *vec_cor)
Applies the ADP filter onto an ADP correction vector.
void filter_vec_def(DTV_ *vec_def)
Applies the ADP filter onto an ADP defect vector.
std::shared_ptr< Adjacency::Graph > _owned_graph
adjacency graph containing the owned matrix structure
void upload_matrix_numeric(DTA_ *val, const RPT_ *row_ptr, const CIT_ *col_idx)
Uploads the data value array of the ADP CSR system matrix.
AlgDofPartiSystem(const GlobalMatrixType &matrix, const GlobalFilterType &filter)
Constructor.
LocalMatrix_ LocalMatrixType
the local matrix type
LAFEM::MatrixMirrorBuffer< DataType, IndexType > BufferMatrixType
the buffer matrix type used for communication
const GlobalFilterType & _global_filter
the global filter that we want to convert
LAFEM::VectorMirror< DataType, IndexType > DoneeMirrorType
donee neighbor mirror type
LAFEM::DenseVector< DataType, IndexType > BufferVectorType
the buffer vector type used for communication
LAFEM::SparseMatrixCSR< DataType, IndexType > OwnedMatrixType
the matrix type used for the internal storage of our owned matrix rows
void upload_filter(const LocalFilterType &filter)
Uploads the values of the given filter to the ADP system.
std::shared_ptr< AlgDofPartiType > _alg_dof_parti
the algebraic dof-partitioning
Global::AlgDofParti< LocalVectorType, MirrorType > AlgDofPartiType
the algebraic DOF partitioning
void upload_vector(DTV_ *val, const LocalVectorType &vector)
Uploads the ADP vector values to the given array.
Mirror_ MirrorType
the vector mirror type
AlgDofPartiSystem & operator=(const AlgDofPartiSystem &)=delete
no copy, no problems
void init_symbolic()
Performs the symbolic initialization.
void apply(DTX_ *vec_r, const DTX_ *vec_x, const DTX_ *val_a, const RPT_ *row_ptr, const CIT_ *col_idx) const
Performs a global matrix-vector product with this matrix.
static void _asm_neighbor_donee_data_mir(DoneeMirrorType &data_mirror, const Adjacency::Graph &owned_graph, const DoneeMirrorType &mirror, const BufferMatrixType &buffer)
Auxiliary function: assembles a data-mirror for a donee-neighbor.
const GlobalMatrixType & _global_matrix
the global matrix that we want to convert
void _assemble_data_mirrors()
Assembles the data-mirrors for all owner- and donee-neighbors.
const Dist::Comm * get_comm() const
void download_vector(LocalVectorType &vector, const DTV_ *val)
Downloads the ADP vector values from the given array.
LocalMatrixType::VectorTypeR LocalVectorType
the local vector type
static BufferMatrixType _asm_mat_buf(const LocalMatrixType &local_matrix, const MirrorType &row_mirror, const IndexVectorType &global_dof_idx, const Index num_global_dofs)
Assembles a matrix buffer for a given row mirror.
Global::Filter< LocalFilterType, MirrorType > GlobalFilterType
the global filter type
std::shared_ptr< AlgDofPartiType > get_alg_dof_parti()
Returns the algebraic dof partitioning that is used internally.
std::vector< DoneeMirrorType > _donee_data_mirs
the data array mirrors for our donee and owner neighbors
LocalMatrix_::DataType DataType
our data type
void _assemble_buffers()
Assembles the owner and donee matrix buffers.
void _assemble_structure()
Assembles the matrix structure of the algebraic-DOF-partitioned matrix.
LAFEM::UnitFilter< DataType, IndexType > _unit_filter_rows
indices of all unit-filtered matrix rows; we store this as a mirror
LocalMatrix_::IndexType IndexType
our index type
void filter_matrix(DTA_ *val, const RPT_ *row_ptr, const CIT_ *col_idx)
Applies the ADP filter onto an ADP matrix.
OwnerMirrorType _owned_data_mir
the data array mirror for this process
LocalFilter_ LocalFilterType
the local filter type
Index _num_global_non_zeros
number of non-zero entries in total
AlgDofPartiType::IndexVectorType IndexVectorType
auxiliary index vector type
static void _scatter_donee_data(DTA_ *adp_val, const BufferVectorType &buffer, const DoneeMirrorType &data_mirror)
Scatters the values of a donee-neighbor buffer-vector into a local matrix.
AlgDofPartiSystem(const AlgDofPartiSystem &)=delete
no copy, no problems
std::vector< BufferMatrixType > _donee_bufs
the matrix buffers for our donee and owner neighbors; both buffers use global DOF indices
void upload_matrix_numeric(DTA_ *val, const RPT_ *row_ptr, const CIT_ *col_idx, const LocalMatrixType &matrix)
Copies the matrix entry values from the input matrix into this algebraic-dof-partitioned matrix.
void upload_matrix_symbolic(RPT_ *row_ptr, CIT_ *col_idx, bool keep_graph=false)
Uploads the row-pointer and column-index arrays of the ADP CSR system matrix.
void upload_filter()
Uploads the values of the system filter to the ADP system.
Intern::ADPDOMM< LocalMatrixType > OwnerMirrorType
owner neighbor mirror type
AlgDofPartiSystem(const GlobalMatrixType &matrix, const GlobalFilterType &filter, std::shared_ptr< AlgDofPartiType > adp)
Constructor.
Global::Matrix< LocalMatrixType, MirrorType, MirrorType > GlobalMatrixType
the global matrix type
Global Filter wrapper class template.
Definition: filter.hpp:21
Global Matrix wrapper class template.
Definition: matrix.hpp:40
const GateRowType * get_row_gate() const
Returns a const pointer to the internal row gate of the matrix.
Definition: matrix.hpp:164
LocalMatrix_ & local()
Returns a reference to the internal local LAFEM matrix object.
Definition: matrix.hpp:136
Dense data vector class template.
Index size() const
Returns the size of this vector, i.e. its number of entries.
Matrix Mirror Buffer class template.
Index num_rows() const
Retrieve matrix row count.
Index num_cols() const
Retrieve matrix column count.
Index num_nzes() const
Retrieve non zero element count.
Index entries_per_nonzero() const
Retrieve entries per non zero element count.
CSR based sparse matrix.
Factory for SparseVector and SparseVectorBlocked construction.
Unit Filter class template.
Definition: unit_filter.hpp:31
Index num_nzes() const
Returns the number of non-zero entries in the filter.
std::size_t bytes() const
Returns the total amount of bytes allocated.
Memory::TypedView< IT_ > indices_view_r(Memory::Location loc=Memory::Location::main) const
Creates a read-only memory view for the indices array for a given memory location.
Handles vector prolongation, restriction and serialization.
Index size() const
Returns the size of this vector, i.e. its number of entries.
Index num_indices() const
Returns the number of indices in the mirror.
Typed memory view class.
T_ * get_w()
Returns a typed pointer to the array that grants write (and read) access.
@ as_is
Render-As-Is mode.
const Operation op_sum(MPI_SUM)
Operation wrapper for MPI_SUM.
Definition: dist.hpp:571
void memset_main(void *ptr, int value, std::size_t bytes)
Formats all bytes of a memory block in main memory to a given value.
@ rest
restriction (multigrid)
FEAT namespace.
Definition: adjactor.hpp:12
void feat_omp_ex_scan(std::size_t n, const T_ x[], T_ y[])
Computes an OpenMP-parallel exclusive scan a.k.a. a prefix sum of an array, i.e.
Definition: omp_util.hpp:153
String stringify(const T_ &item)
Converts an item into a String.
Definition: string.hpp:993
std::uint64_t Index
Index data type.