12 #include "../config/config.hpp"
13 #include "../general/error.hpp"
14 #include "../general/forall.hpp"
39 void hypre_CSRMatrixEliminateAXB(hypre_CSRMatrix *A,
40 HYPRE_Int nrows_to_eliminate,
41 HYPRE_Int *rows_to_eliminate,
46 HYPRE_Int irow, jcol, ibeg, iend, pos;
49 HYPRE_Int *Ai = hypre_CSRMatrixI(A);
50 HYPRE_Int *Aj = hypre_CSRMatrixJ(A);
51 HYPRE_Real *Adata = hypre_CSRMatrixData(A);
52 HYPRE_Int nrows = hypre_CSRMatrixNumRows(A);
54 HYPRE_Real *Xdata = hypre_VectorData(X);
55 HYPRE_Real *Bdata = hypre_VectorData(B);
58 for (i = 0; i < nrows; i++)
62 for (j = ibeg; j < iend; j++)
65 pos = hypre_BinarySearch(rows_to_eliminate, jcol, nrows_to_eliminate);
70 Bdata[i] -= a * Xdata[jcol];
76 for (i = 0; i < nrows_to_eliminate; i++)
78 irow = rows_to_eliminate[i];
81 for (j = ibeg; j < iend; j++)
100 void hypre_CSRMatrixEliminateOffdColsAXB(hypre_CSRMatrix *A,
101 HYPRE_Int ncols_to_eliminate,
102 HYPRE_Int *eliminate_cols,
103 HYPRE_Real *eliminate_coefs,
107 HYPRE_Int ibeg, iend, pos;
110 HYPRE_Int *Ai = hypre_CSRMatrixI(A);
111 HYPRE_Int *Aj = hypre_CSRMatrixJ(A);
112 HYPRE_Real *Adata = hypre_CSRMatrixData(A);
113 HYPRE_Int nrows = hypre_CSRMatrixNumRows(A);
115 HYPRE_Real *Bdata = hypre_VectorData(B);
117 for (i = 0; i < nrows; i++)
121 for (j = ibeg; j < iend; j++)
123 pos = hypre_BinarySearch(eliminate_cols, Aj[j], ncols_to_eliminate);
128 Bdata[i] -= a * eliminate_coefs[pos];
139 void hypre_CSRMatrixEliminateOffdRowsAXB(hypre_CSRMatrix *A,
140 HYPRE_Int nrows_to_eliminate,
141 HYPRE_Int *rows_to_eliminate)
143 HYPRE_Int *Ai = hypre_CSRMatrixI(A);
144 HYPRE_Real *Adata = hypre_CSRMatrixData(A);
147 HYPRE_Int irow, ibeg, iend;
149 for (i = 0; i < nrows_to_eliminate; i++)
151 irow = rows_to_eliminate[i];
154 for (j = ibeg; j < iend; j++)
185 void hypre_ParCSRMatrixEliminateAXB(hypre_ParCSRMatrix *A,
186 HYPRE_Int num_rowscols_to_elim,
187 HYPRE_Int *rowscols_to_elim,
191 hypre_CSRMatrix *diag = hypre_ParCSRMatrixDiag(A);
192 hypre_CSRMatrix *offd = hypre_ParCSRMatrixOffd(A);
193 HYPRE_Int diag_nrows = hypre_CSRMatrixNumRows(diag);
194 HYPRE_Int offd_ncols = hypre_CSRMatrixNumCols(offd);
196 hypre_Vector *Xlocal = hypre_ParVectorLocalVector(X);
197 hypre_Vector *Blocal = hypre_ParVectorLocalVector(B);
199 HYPRE_Real *Bdata = hypre_VectorData(Blocal);
200 HYPRE_Real *Xdata = hypre_VectorData(Xlocal);
202 HYPRE_Int num_offd_cols_to_elim;
203 HYPRE_Int *offd_cols_to_elim;
204 HYPRE_Real *eliminate_coefs;
207 hypre_ParCSRCommHandle *comm_handle;
208 hypre_ParCSRCommPkg *comm_pkg;
210 HYPRE_Int
index, start;
211 HYPRE_Int i, j, k, irow;
213 HYPRE_Real *eliminate_row = mfem_hypre_CTAlloc_host(HYPRE_Real, diag_nrows);
214 HYPRE_Real *eliminate_col = mfem_hypre_CTAlloc_host(HYPRE_Real, offd_ncols);
215 HYPRE_Real *buf_data, coef;
218 comm_pkg = hypre_ParCSRMatrixCommPkg(A);
221 hypre_MatvecCommPkgCreate(A);
222 comm_pkg = hypre_ParCSRMatrixCommPkg(A);
228 for (i = 0; i < diag_nrows; i++)
230 eliminate_row[i] = std::numeric_limits<HYPRE_Real>::quiet_NaN();
232 for (i = 0; i < num_rowscols_to_elim; i++)
234 irow = rowscols_to_elim[i];
235 eliminate_row[irow] = Xdata[irow];
240 num_sends = hypre_ParCSRCommPkgNumSends(comm_pkg);
241 buf_data = mfem_hypre_CTAlloc_host(
243 hypre_ParCSRCommPkgSendMapStart(comm_pkg, num_sends));
245 for (i = 0; i < num_sends; i++)
247 start = hypre_ParCSRCommPkgSendMapStart(comm_pkg, i);
248 for (j = start; j < hypre_ParCSRCommPkgSendMapStart(comm_pkg, i+1); j++)
250 k = hypre_ParCSRCommPkgSendMapElmt(comm_pkg,j);
251 buf_data[index++] = eliminate_row[k];
254 comm_handle = hypre_ParCSRCommHandleCreate(1, comm_pkg,
255 buf_data, eliminate_col);
258 hypre_CSRMatrixEliminateAXB(diag, num_rowscols_to_elim, rowscols_to_elim,
262 hypre_ParCSRCommHandleDestroy(comm_handle);
265 num_offd_cols_to_elim = 0;
266 for (i = 0; i < offd_ncols; i++)
268 coef = eliminate_col[i];
271 num_offd_cols_to_elim++;
275 offd_cols_to_elim = mfem_hypre_CTAlloc_host(HYPRE_Int,
276 num_offd_cols_to_elim);
277 eliminate_coefs = mfem_hypre_CTAlloc_host(HYPRE_Real, num_offd_cols_to_elim);
280 num_offd_cols_to_elim = 0;
281 for (i = 0; i < offd_ncols; i++)
283 coef = eliminate_col[i];
286 offd_cols_to_elim[num_offd_cols_to_elim] = i;
287 eliminate_coefs[num_offd_cols_to_elim] = coef;
288 num_offd_cols_to_elim++;
292 mfem_hypre_TFree_host(buf_data);
293 mfem_hypre_TFree_host(eliminate_col);
294 mfem_hypre_TFree_host(eliminate_row);
297 hypre_CSRMatrixEliminateOffdColsAXB(offd, num_offd_cols_to_elim,
299 eliminate_coefs, Blocal);
301 hypre_CSRMatrixEliminateOffdRowsAXB(offd, num_rowscols_to_elim,
305 for (
int i = 0; i < num_rowscols_to_elim; i++)
307 irow = rowscols_to_elim[i];
308 Bdata[irow] = Xdata[irow];
311 mfem_hypre_TFree_host(offd_cols_to_elim);
312 mfem_hypre_TFree_host(eliminate_coefs);
325 void hypre_CSRMatrixElimCreate(hypre_CSRMatrix *A,
327 HYPRE_Int nrows, HYPRE_Int *rows,
328 HYPRE_Int ncols, HYPRE_Int *cols,
332 HYPRE_Int A_beg, A_end;
334 HYPRE_Int *A_i = hypre_CSRMatrixI(A);
335 HYPRE_Int *A_j = hypre_CSRMatrixJ(A);
336 HYPRE_Int A_rows = hypre_CSRMatrixNumRows(A);
338 hypre_CSRMatrixI(Ae) = mfem_hypre_TAlloc_host(HYPRE_Int, A_rows+1);
340 HYPRE_Int *Ae_i = hypre_CSRMatrixI(Ae);
343 for (i = 0; i < A_rows; i++)
350 if (hypre_BinarySearch(rows, i, nrows) >= 0)
353 nnz += A_end - A_beg;
357 for (j = A_beg; j < A_end; j++)
359 col_mark[A_j[j]] = 1;
366 for (j = A_beg; j < A_end; j++)
369 if (hypre_BinarySearch(cols, col, ncols) >= 0)
372 if (col_mark) { col_mark[col] = 1; }
379 hypre_CSRMatrixJ(Ae) = mfem_hypre_TAlloc_host(HYPRE_Int, nnz);
380 hypre_CSRMatrixData(Ae) = mfem_hypre_TAlloc_host(HYPRE_Real, nnz);
381 hypre_CSRMatrixNumNonzeros(Ae) = nnz;
382 #if MFEM_HYPRE_VERSION >= 21800
383 hypre_CSRMatrixMemoryLocation(Ae) = HYPRE_MEMORY_HOST;
394 void hypre_CSRMatrixEliminateRowsCols(hypre_CSRMatrix *A,
396 HYPRE_Int nrows, HYPRE_Int *rows,
397 HYPRE_Int ncols, HYPRE_Int *cols,
398 int diag, HYPRE_Int* col_remap)
400 HYPRE_Int i, j, k, col;
401 HYPRE_Int A_beg, Ae_beg, A_end;
404 HYPRE_Int *A_i = hypre_CSRMatrixI(A);
405 HYPRE_Int *A_j = hypre_CSRMatrixJ(A);
406 HYPRE_Real *A_data = hypre_CSRMatrixData(A);
407 HYPRE_Int A_rows = hypre_CSRMatrixNumRows(A);
409 HYPRE_Int *Ae_i = hypre_CSRMatrixI(Ae);
410 HYPRE_Int *Ae_j = hypre_CSRMatrixJ(Ae);
411 HYPRE_Real *Ae_data = hypre_CSRMatrixData(Ae);
413 for (i = 0; i < A_rows; i++)
419 if (hypre_BinarySearch(rows, i, nrows) >= 0)
422 for (j = A_beg, k = Ae_beg; j < A_end; j++, k++)
425 Ae_j[k] = col_remap ? col_remap[col] : col;
426 a = (diag && col == i) ? 1.0 : 0.0;
427 Ae_data[k] = A_data[j] -
a;
434 for (j = A_beg, k = Ae_beg; j < A_end; j++)
437 if (hypre_BinarySearch(cols, col, ncols) >= 0)
439 Ae_j[k] = col_remap ? col_remap[col] : col;
440 Ae_data[k] = A_data[j];
452 void hypre_CSRMatrixEliminateRows(hypre_CSRMatrix *A,
453 HYPRE_Int nrows,
const HYPRE_Int *rows)
455 HYPRE_Int irow, i, j;
456 HYPRE_Int A_beg, A_end;
458 HYPRE_Int *A_i = hypre_CSRMatrixI(A);
459 HYPRE_Real *A_data = hypre_CSRMatrixData(A);
461 for (i = 0; i < nrows; i++)
467 for (j = A_beg; j < A_end; j++)
491 void hypre_ParCSRMatrixEliminateAAe(hypre_ParCSRMatrix *A,
492 hypre_ParCSRMatrix **Ae,
493 HYPRE_Int num_rowscols_to_elim,
494 HYPRE_Int *rowscols_to_elim,
499 hypre_CSRMatrix *A_diag = hypre_ParCSRMatrixDiag(A);
500 hypre_CSRMatrix *A_offd = hypre_ParCSRMatrixOffd(A);
501 HYPRE_Int A_diag_ncols = hypre_CSRMatrixNumCols(A_diag);
502 HYPRE_Int A_offd_ncols = hypre_CSRMatrixNumCols(A_offd);
504 *Ae = hypre_ParCSRMatrixCreate(hypre_ParCSRMatrixComm(A),
505 hypre_ParCSRMatrixGlobalNumRows(A),
506 hypre_ParCSRMatrixGlobalNumCols(A),
507 hypre_ParCSRMatrixRowStarts(A),
508 hypre_ParCSRMatrixColStarts(A),
511 hypre_ParCSRMatrixSetRowStartsOwner(*Ae, 0);
512 hypre_ParCSRMatrixSetColStartsOwner(*Ae, 0);
514 hypre_CSRMatrix *Ae_diag = hypre_ParCSRMatrixDiag(*Ae);
515 hypre_CSRMatrix *Ae_offd = hypre_ParCSRMatrixOffd(*Ae);
516 HYPRE_Int Ae_offd_ncols;
518 HYPRE_Int num_offd_cols_to_elim;
519 HYPRE_Int *offd_cols_to_elim;
521 HYPRE_BigInt *A_col_map_offd = hypre_ParCSRMatrixColMapOffd(A);
525 HYPRE_Int *col_remap;
529 hypre_ParCSRCommHandle *comm_handle;
530 hypre_ParCSRCommPkg *comm_pkg;
531 HYPRE_Int num_sends, *int_buf_data;
532 HYPRE_Int
index, start;
534 HYPRE_Int *eliminate_diag_col = mfem_hypre_CTAlloc_host(HYPRE_Int,
536 HYPRE_Int *eliminate_offd_col = mfem_hypre_CTAlloc_host(HYPRE_Int,
540 comm_pkg = hypre_ParCSRMatrixCommPkg(A);
543 hypre_MatvecCommPkgCreate(A);
544 comm_pkg = hypre_ParCSRMatrixCommPkg(A);
548 for (i = 0; i < A_diag_ncols; i++)
550 eliminate_diag_col[i] = 0;
552 for (i = 0; i < num_rowscols_to_elim; i++)
554 eliminate_diag_col[rowscols_to_elim[i]] = 1;
559 num_sends = hypre_ParCSRCommPkgNumSends(comm_pkg);
560 int_buf_data = mfem_hypre_CTAlloc_host(
562 hypre_ParCSRCommPkgSendMapStart(comm_pkg, num_sends));
564 for (i = 0; i < num_sends; i++)
566 start = hypre_ParCSRCommPkgSendMapStart(comm_pkg, i);
567 for (j = start; j < hypre_ParCSRCommPkgSendMapStart(comm_pkg, i+1); j++)
569 k = hypre_ParCSRCommPkgSendMapElmt(comm_pkg, j);
570 int_buf_data[index++] = eliminate_diag_col[k];
573 comm_handle = hypre_ParCSRCommHandleCreate(11, comm_pkg,
580 hypre_CSRMatrixElimCreate(A_diag, Ae_diag,
582 num_rowscols_to_elim, rowscols_to_elim,
585 hypre_CSRMatrixEliminateRowsCols(A_diag, Ae_diag,
587 num_rowscols_to_elim, rowscols_to_elim,
592 hypre_CSRMatrixElimCreate(A_diag, Ae_diag,
593 num_rowscols_to_elim, rowscols_to_elim,
594 num_rowscols_to_elim, rowscols_to_elim,
597 hypre_CSRMatrixEliminateRowsCols(A_diag, Ae_diag,
598 num_rowscols_to_elim, rowscols_to_elim,
599 num_rowscols_to_elim, rowscols_to_elim,
603 hypre_CSRMatrixReorder(Ae_diag);
606 hypre_ParCSRCommHandleDestroy(comm_handle);
609 num_offd_cols_to_elim = 0;
610 for (i = 0; i < A_offd_ncols; i++)
612 if (eliminate_offd_col[i]) { num_offd_cols_to_elim++; }
615 offd_cols_to_elim = mfem_hypre_CTAlloc_host(HYPRE_Int,
616 num_offd_cols_to_elim);
619 num_offd_cols_to_elim = 0;
620 for (i = 0; i < A_offd_ncols; i++)
622 if (eliminate_offd_col[i])
624 offd_cols_to_elim[num_offd_cols_to_elim++] = i;
628 mfem_hypre_TFree_host(int_buf_data);
629 mfem_hypre_TFree_host(eliminate_offd_col);
630 mfem_hypre_TFree_host(eliminate_diag_col);
634 col_mark = mfem_hypre_CTAlloc_host(HYPRE_Int, A_offd_ncols);
635 col_remap = mfem_hypre_CTAlloc_host(HYPRE_Int, A_offd_ncols);
639 hypre_CSRMatrixElimCreate(A_offd, Ae_offd,
641 num_offd_cols_to_elim, offd_cols_to_elim,
644 for (i = k = 0; i < A_offd_ncols; i++)
646 if (col_mark[i]) { col_remap[i] = k++; }
649 hypre_CSRMatrixEliminateRowsCols(A_offd, Ae_offd,
651 num_offd_cols_to_elim, offd_cols_to_elim,
656 hypre_CSRMatrixElimCreate(A_offd, Ae_offd,
657 num_rowscols_to_elim, rowscols_to_elim,
658 num_offd_cols_to_elim, offd_cols_to_elim,
661 for (i = k = 0; i < A_offd_ncols; i++)
663 if (col_mark[i]) { col_remap[i] = k++; }
666 hypre_CSRMatrixEliminateRowsCols(A_offd, Ae_offd,
667 num_rowscols_to_elim, rowscols_to_elim,
668 num_offd_cols_to_elim, offd_cols_to_elim,
674 for (i = 0; i < A_offd_ncols; i++)
676 if (col_mark[i]) { Ae_offd_ncols++; }
679 Ae_col_map_offd = mfem_hypre_CTAlloc_host(
HYPRE_BigInt, Ae_offd_ncols);
682 for (i = 0; i < A_offd_ncols; i++)
686 Ae_col_map_offd[Ae_offd_ncols++] = A_col_map_offd[i];
690 hypre_ParCSRMatrixColMapOffd(*Ae) = Ae_col_map_offd;
691 hypre_CSRMatrixNumCols(Ae_offd) = Ae_offd_ncols;
693 mfem_hypre_TFree_host(col_remap);
694 mfem_hypre_TFree_host(col_mark);
695 mfem_hypre_TFree_host(offd_cols_to_elim);
697 hypre_ParCSRMatrixSetNumNonzeros(*Ae);
698 hypre_MatvecCommPkgCreate(*Ae);
703 void hypre_ParCSRMatrixEliminateRows(hypre_ParCSRMatrix *A,
704 HYPRE_Int num_rows_to_elim,
705 const HYPRE_Int *rows_to_elim)
707 hypre_CSRMatrix *A_diag = hypre_ParCSRMatrixDiag(A);
708 hypre_CSRMatrix *A_offd = hypre_ParCSRMatrixOffd(A);
709 hypre_CSRMatrixEliminateRows(A_diag, num_rows_to_elim, rows_to_elim);
710 hypre_CSRMatrixEliminateRows(A_offd, num_rows_to_elim, rows_to_elim);
718 void hypre_CSRMatrixSplit(hypre_CSRMatrix *A,
719 HYPRE_Int nr, HYPRE_Int nc,
720 HYPRE_Int *row_block_num, HYPRE_Int *col_block_num,
721 hypre_CSRMatrix **blocks)
723 HYPRE_Int i, j, k, bi, bj;
725 HYPRE_Int* A_i = hypre_CSRMatrixI(A);
726 HYPRE_Int* A_j = hypre_CSRMatrixJ(A);
727 HYPRE_Complex* A_data = hypre_CSRMatrixData(A);
729 HYPRE_Int A_rows = hypre_CSRMatrixNumRows(A);
730 HYPRE_Int A_cols = hypre_CSRMatrixNumCols(A);
732 HYPRE_Int *num_rows = mfem_hypre_CTAlloc_host(HYPRE_Int, nr);
733 HYPRE_Int *num_cols = mfem_hypre_CTAlloc_host(HYPRE_Int, nc);
735 HYPRE_Int *block_row = mfem_hypre_TAlloc_host(HYPRE_Int, A_rows);
736 HYPRE_Int *block_col = mfem_hypre_TAlloc_host(HYPRE_Int, A_cols);
738 for (i = 0; i < A_rows; i++)
740 block_row[i] = num_rows[row_block_num[i]]++;
742 for (j = 0; j < A_cols; j++)
744 block_col[j] = num_cols[col_block_num[j]]++;
748 for (i = 0; i < nr; i++)
750 for (j = 0; j < nc; j++)
752 hypre_CSRMatrix *B = hypre_CSRMatrixCreate(num_rows[i],
754 hypre_CSRMatrixI(B) = mfem_hypre_CTAlloc_host(HYPRE_Int,
756 #if MFEM_HYPRE_VERSION >= 21800
757 hypre_CSRMatrixMemoryLocation(B) = HYPRE_MEMORY_HOST;
759 blocks[i*nc + j] = B;
764 for (i = 0; i < A_rows; i++)
766 bi = row_block_num[i];
767 for (j = A_i[i]; j < A_i[i+1]; j++)
769 bj = col_block_num[A_j[j]];
770 hypre_CSRMatrix *B = blocks[bi*nc + bj];
771 hypre_CSRMatrixI(B)[block_row[i] + 1]++;
776 for (k = 0; k < nr*nc; k++)
778 hypre_CSRMatrix *B = blocks[k];
779 HYPRE_Int* B_i = hypre_CSRMatrixI(B);
781 HYPRE_Int nnz = 0, rs;
782 for (
int k = 1; k <= hypre_CSRMatrixNumRows(B); k++)
784 rs = B_i[k], B_i[k] = nnz, nnz += rs;
787 hypre_CSRMatrixJ(B) = mfem_hypre_TAlloc_host(HYPRE_Int, nnz);
788 hypre_CSRMatrixData(B) = mfem_hypre_TAlloc_host(HYPRE_Complex, nnz);
789 hypre_CSRMatrixNumNonzeros(B) = nnz;
793 for (i = 0; i < A_rows; i++)
795 bi = row_block_num[i];
796 for (j = A_i[i]; j < A_i[i+1]; j++)
799 bj = col_block_num[k];
800 hypre_CSRMatrix *B = blocks[bi*nc + bj];
801 HYPRE_Int *bii = hypre_CSRMatrixI(B) + block_row[i] + 1;
802 hypre_CSRMatrixJ(B)[*bii] = block_col[k];
803 hypre_CSRMatrixData(B)[*bii] = A_data[j];
808 mfem_hypre_TFree_host(block_col);
809 mfem_hypre_TFree_host(block_row);
811 mfem_hypre_TFree_host(num_cols);
812 mfem_hypre_TFree_host(num_rows);
816 void hypre_ParCSRMatrixSplit(hypre_ParCSRMatrix *A,
817 HYPRE_Int nr, HYPRE_Int nc,
818 hypre_ParCSRMatrix **blocks,
819 int interleaved_rows,
int interleaved_cols)
823 MPI_Comm comm = hypre_ParCSRMatrixComm(A);
825 hypre_CSRMatrix *Adiag = hypre_ParCSRMatrixDiag(A);
826 hypre_CSRMatrix *Aoffd = hypre_ParCSRMatrixOffd(A);
828 HYPRE_BigInt global_rows = hypre_ParCSRMatrixGlobalNumRows(A);
829 HYPRE_BigInt global_cols = hypre_ParCSRMatrixGlobalNumCols(A);
831 HYPRE_Int local_rows = hypre_CSRMatrixNumRows(Adiag);
832 HYPRE_Int local_cols = hypre_CSRMatrixNumCols(Adiag);
833 HYPRE_Int offd_cols = hypre_CSRMatrixNumCols(Aoffd);
835 hypre_assert(local_rows % nr == 0 && local_cols % nc == 0);
836 hypre_assert(global_rows % nr == 0 && global_cols % nc == 0);
838 HYPRE_Int block_rows = local_rows / nr;
839 HYPRE_Int block_cols = local_cols / nc;
840 HYPRE_Int num_blocks = nr * nc;
843 HYPRE_Int *row_block_num = mfem_hypre_TAlloc_host(HYPRE_Int, local_rows);
844 HYPRE_Int *col_block_num = mfem_hypre_TAlloc_host(HYPRE_Int, local_cols);
846 for (i = 0; i < local_rows; i++)
848 row_block_num[i] = interleaved_rows ? (i % nr) : (i / block_rows);
850 for (i = 0; i < local_cols; i++)
852 col_block_num[i] = interleaved_cols ? (i % nc) : (i / block_cols);
858 hypre_ParCSRCommHandle *comm_handle;
862 hypre_ParCSRCommPkg *comm_pkg = hypre_ParCSRMatrixCommPkg(A);
865 hypre_MatvecCommPkgCreate(A);
866 comm_pkg = hypre_ParCSRMatrixCommPkg(A);
870 HYPRE_Int *count = mfem_hypre_CTAlloc_host(HYPRE_Int, nc);
873 HYPRE_BigInt first_col = hypre_ParCSRMatrixFirstColDiag(A) / nc;
874 for (i = 0; i < local_cols; i++)
876 block_global_col[i] = first_col + count[col_block_num[i]]++;
878 mfem_hypre_TFree_host(count);
881 HYPRE_Int num_sends = hypre_ParCSRCommPkgNumSends(comm_pkg);
882 int_buf_data = mfem_hypre_CTAlloc_host(
884 hypre_ParCSRCommPkgSendMapStart(comm_pkg, num_sends));
885 HYPRE_Int start, index = 0;
886 for (i = 0; i < num_sends; i++)
888 start = hypre_ParCSRCommPkgSendMapStart(comm_pkg, i);
889 for (j = start; j < hypre_ParCSRCommPkgSendMapStart(comm_pkg, i+1); j++)
891 k = hypre_ParCSRCommPkgSendMapElmt(comm_pkg, j);
892 int_buf_data[index++] = col_block_num[k] + nc*block_global_col[k];
896 mfem_hypre_TFree_host(block_global_col);
898 #if MFEM_HYPRE_VERSION < 21600
903 comm_handle = hypre_ParCSRCommHandleCreate(job, comm_pkg, int_buf_data,
908 HYPRE_Int num_procs = 1;
909 if (!hypre_ParCSRMatrixAssumedPartition(A))
911 hypre_MPI_Comm_size(comm, &num_procs);
916 for (i = 0; i <= num_procs; i++)
918 row_starts[i] = hypre_ParCSRMatrixRowStarts(A)[i] / nr;
919 col_starts[i] = hypre_ParCSRMatrixColStarts(A)[i] / nc;
922 for (i = 0; i < num_blocks; i++)
924 blocks[i] = hypre_ParCSRMatrixCreate(comm,
925 global_rows/nr, global_cols/nc,
926 row_starts, col_starts, 0, 0, 0);
930 hypre_CSRMatrix **csr_blocks = mfem_hypre_TAlloc_host(hypre_CSRMatrix*,
932 hypre_CSRMatrixSplit(Adiag, nr, nc, row_block_num, col_block_num,
935 for (i = 0; i < num_blocks; i++)
937 mfem_hypre_TFree_host(hypre_ParCSRMatrixDiag(blocks[i]));
938 hypre_ParCSRMatrixDiag(blocks[i]) = csr_blocks[i];
942 hypre_ParCSRCommHandleDestroy(comm_handle);
943 mfem_hypre_TFree_host(int_buf_data);
946 HYPRE_Int *offd_col_block_num_nc = mfem_hypre_TAlloc_host(HYPRE_Int,
950 for (i = 0; i < offd_cols; i++)
952 offd_global_col[i] = offd_col_block_num[i] / nc;
953 offd_col_block_num_nc[i] = offd_col_block_num[i] % nc;
956 mfem_hypre_TFree_host(offd_col_block_num);
959 hypre_CSRMatrixSplit(Aoffd, nr, nc, row_block_num, offd_col_block_num_nc,
962 for (i = 0; i < num_blocks; i++)
964 mfem_hypre_TFree_host(hypre_ParCSRMatrixOffd(blocks[i]));
965 hypre_ParCSRMatrixOffd(blocks[i]) = csr_blocks[i];
968 mfem_hypre_TFree_host(csr_blocks);
969 mfem_hypre_TFree_host(col_block_num);
970 mfem_hypre_TFree_host(row_block_num);
973 for (
int bi = 0; bi < nr; bi++)
975 for (
int bj = 0; bj < nc; bj++)
977 hypre_ParCSRMatrix *block = blocks[bi*nc + bj];
978 hypre_CSRMatrix *block_offd = hypre_ParCSRMatrixOffd(block);
979 HYPRE_Int block_offd_cols = hypre_CSRMatrixNumCols(block_offd);
983 for (i = j = 0; i < offd_cols; i++)
985 HYPRE_Int bn = offd_col_block_num_nc[i];
986 if (bn == bj) { block_col_map[j++] = offd_global_col[i]; }
988 hypre_assert(j == block_offd_cols);
990 hypre_ParCSRMatrixColMapOffd(block) = block_col_map;
994 mfem_hypre_TFree_host(offd_global_col);
995 mfem_hypre_TFree_host(offd_col_block_num_nc);
998 for (i = 0; i < num_blocks; i++)
1000 hypre_ParCSRMatrixSetNumNonzeros(blocks[i]);
1001 hypre_MatvecCommPkgCreate(blocks[i]);
1003 hypre_ParCSRMatrixOwnsData(blocks[i]) = 1;
1006 hypre_ParCSRMatrixOwnsRowStarts(blocks[i]) = !i;
1007 hypre_ParCSRMatrixOwnsColStarts(blocks[i]) = !i;
1012 void hypre_CSRMatrixAbsMatvec(hypre_CSRMatrix *A,
1018 HYPRE_Real *A_data = hypre_CSRMatrixData(A);
1019 HYPRE_Int *A_i = hypre_CSRMatrixI(A);
1020 HYPRE_Int *A_j = hypre_CSRMatrixJ(A);
1021 HYPRE_Int num_rows = hypre_CSRMatrixNumRows(A);
1023 HYPRE_Int *A_rownnz = hypre_CSRMatrixRownnz(A);
1024 HYPRE_Int num_rownnz = hypre_CSRMatrixNumRownnz(A);
1026 HYPRE_Real *x_data = x;
1027 HYPRE_Real *y_data = y;
1029 HYPRE_Real temp, tempx;
1035 HYPRE_Real xpar=0.7;
1043 for (i = 0; i < num_rows; i++)
1054 temp = beta /
alpha;
1060 for (i = 0; i < num_rows; i++)
1067 for (i = 0; i < num_rows; i++)
1081 if (num_rownnz < xpar*(num_rows))
1083 for (i = 0; i < num_rownnz; i++)
1088 for (jj = A_i[m]; jj < A_i[m+1]; jj++)
1090 tempx += std::abs(A_data[jj])*x_data[A_j[jj]];
1097 for (i = 0; i < num_rows; i++)
1100 for (jj = A_i[i]; jj < A_i[i+1]; jj++)
1102 tempx += std::abs(A_data[jj])*x_data[A_j[jj]];
1114 for (i = 0; i < num_rows; i++)
1123 void hypre_CSRMatrixAbsMatvecT(hypre_CSRMatrix *A,
1129 HYPRE_Real *A_data = hypre_CSRMatrixData(A);
1130 HYPRE_Int *A_i = hypre_CSRMatrixI(A);
1131 HYPRE_Int *A_j = hypre_CSRMatrixJ(A);
1132 HYPRE_Int num_rows = hypre_CSRMatrixNumRows(A);
1133 HYPRE_Int num_cols = hypre_CSRMatrixNumCols(A);
1135 HYPRE_Real *x_data = x;
1136 HYPRE_Real *y_data = y;
1144 for (i = 0; i < num_cols; i++)
1155 temp = beta /
alpha;
1161 for (i = 0; i < num_cols; i++)
1168 for (i = 0; i < num_cols; i++)
1179 for (i = 0; i < num_rows; i++)
1181 for (jj = A_i[i]; jj < A_i[i+1]; jj++)
1184 y_data[j] += std::abs(A_data[jj]) * x_data[i];
1194 for (i = 0; i < num_cols; i++)
1202 void hypre_CSRMatrixBooleanMatvec(hypre_CSRMatrix *A,
1209 HYPRE_Int *A_i = hypre_CSRMatrixI(A);
1210 HYPRE_Int *A_j = hypre_CSRMatrixJ(A);
1211 HYPRE_Int num_rows = hypre_CSRMatrixNumRows(A);
1213 HYPRE_Int *A_rownnz = hypre_CSRMatrixRownnz(A);
1214 HYPRE_Int num_rownnz = hypre_CSRMatrixNumRownnz(A);
1216 HYPRE_Bool *x_data = x;
1217 HYPRE_Bool *y_data = y;
1219 HYPRE_Bool temp, tempx;
1225 HYPRE_Real xpar=0.7;
1233 #ifdef HYPRE_USING_OPENMP
1234 #pragma omp parallel for private(i) HYPRE_SMP_SCHEDULE
1236 for (i = 0; i < num_rows; i++)
1238 y_data[i] = y_data[i] && beta;
1249 #ifdef HYPRE_USING_OPENMP
1250 #pragma omp parallel for private(i) HYPRE_SMP_SCHEDULE
1252 for (i = 0; i < num_rows; i++)
1268 if (num_rownnz < xpar*(num_rows))
1270 #ifdef HYPRE_USING_OPENMP
1271 #pragma omp parallel for private(i,jj,m,tempx) HYPRE_SMP_SCHEDULE
1273 for (i = 0; i < num_rownnz; i++)
1278 for (jj = A_i[m]; jj < A_i[m+1]; jj++)
1281 tempx = tempx || x_data[A_j[jj]];
1283 y_data[m] = y_data[m] || tempx;
1288 #ifdef HYPRE_USING_OPENMP
1289 #pragma omp parallel for private(i,jj,temp) HYPRE_SMP_SCHEDULE
1291 for (i = 0; i < num_rows; i++)
1294 for (jj = A_i[i]; jj < A_i[i+1]; jj++)
1297 temp = temp || x_data[A_j[jj]];
1299 y_data[i] = y_data[i] || temp;
1310 void hypre_CSRMatrixBooleanMatvecT(hypre_CSRMatrix *A,
1317 HYPRE_Int *A_i = hypre_CSRMatrixI(A);
1318 HYPRE_Int *A_j = hypre_CSRMatrixJ(A);
1319 HYPRE_Int num_rows = hypre_CSRMatrixNumRows(A);
1320 HYPRE_Int num_cols = hypre_CSRMatrixNumCols(A);
1322 HYPRE_Bool *x_data = x;
1323 HYPRE_Bool *y_data = y;
1333 for (i = 0; i < num_cols; i++)
1357 for (i = 0; i < num_rows; i++)
1361 for (jj = A_i[i]; jj < A_i[i+1]; jj++)
1373 hypre_ParCSRCommHandle *
1374 hypre_ParCSRCommHandleCreate_bool(HYPRE_Int job,
1375 hypre_ParCSRCommPkg *comm_pkg,
1376 HYPRE_Bool *send_data,
1377 HYPRE_Bool *recv_data)
1379 HYPRE_Int num_sends = hypre_ParCSRCommPkgNumSends(comm_pkg);
1380 HYPRE_Int num_recvs = hypre_ParCSRCommPkgNumRecvs(comm_pkg);
1381 MPI_Comm comm = hypre_ParCSRCommPkgComm(comm_pkg);
1383 hypre_ParCSRCommHandle *comm_handle;
1384 HYPRE_Int num_requests;
1385 hypre_MPI_Request *requests;
1388 HYPRE_Int my_id, num_procs;
1389 HYPRE_Int ip, vec_start, vec_len;
1391 num_requests = num_sends + num_recvs;
1392 requests = mfem_hypre_CTAlloc_host(hypre_MPI_Request, num_requests);
1394 hypre_MPI_Comm_size(comm, &num_procs);
1395 hypre_MPI_Comm_rank(comm, &my_id);
1402 HYPRE_Bool *d_send_data = (HYPRE_Bool *) send_data;
1403 HYPRE_Bool *d_recv_data = (HYPRE_Bool *) recv_data;
1404 for (i = 0; i < num_recvs; i++)
1406 ip = hypre_ParCSRCommPkgRecvProc(comm_pkg, i);
1407 vec_start = hypre_ParCSRCommPkgRecvVecStart(comm_pkg, i);
1408 vec_len = hypre_ParCSRCommPkgRecvVecStart(comm_pkg, i+1)-vec_start;
1409 hypre_MPI_Irecv(&d_recv_data[vec_start], vec_len, HYPRE_MPI_BOOL,
1410 ip, 0, comm, &requests[j++]);
1412 for (i = 0; i < num_sends; i++)
1414 vec_start = hypre_ParCSRCommPkgSendMapStart(comm_pkg, i);
1415 vec_len = hypre_ParCSRCommPkgSendMapStart(comm_pkg, i+1)-vec_start;
1416 ip = hypre_ParCSRCommPkgSendProc(comm_pkg, i);
1417 hypre_MPI_Isend(&d_send_data[vec_start], vec_len, HYPRE_MPI_BOOL,
1418 ip, 0, comm, &requests[j++]);
1424 HYPRE_Bool *d_send_data = (HYPRE_Bool *) send_data;
1425 HYPRE_Bool *d_recv_data = (HYPRE_Bool *) recv_data;
1426 for (i = 0; i < num_sends; i++)
1428 vec_start = hypre_ParCSRCommPkgSendMapStart(comm_pkg, i);
1429 vec_len = hypre_ParCSRCommPkgSendMapStart(comm_pkg, i+1)-vec_start;
1430 ip = hypre_ParCSRCommPkgSendProc(comm_pkg, i);
1431 hypre_MPI_Irecv(&d_recv_data[vec_start], vec_len, HYPRE_MPI_BOOL,
1432 ip, 0, comm, &requests[j++]);
1434 for (i = 0; i < num_recvs; i++)
1436 ip = hypre_ParCSRCommPkgRecvProc(comm_pkg, i);
1437 vec_start = hypre_ParCSRCommPkgRecvVecStart(comm_pkg, i);
1438 vec_len = hypre_ParCSRCommPkgRecvVecStart(comm_pkg, i+1)-vec_start;
1439 hypre_MPI_Isend(&d_send_data[vec_start], vec_len, HYPRE_MPI_BOOL,
1440 ip, 0, comm, &requests[j++]);
1449 comm_handle = mfem_hypre_CTAlloc_host(hypre_ParCSRCommHandle, 1);
1451 hypre_ParCSRCommHandleCommPkg(comm_handle) = comm_pkg;
1452 hypre_ParCSRCommHandleSendData(comm_handle) = send_data;
1453 hypre_ParCSRCommHandleRecvData(comm_handle) = recv_data;
1454 hypre_ParCSRCommHandleNumRequests(comm_handle) = num_requests;
1455 hypre_ParCSRCommHandleRequests(comm_handle) = requests;
1461 void hypre_ParCSRMatrixAbsMatvec(hypre_ParCSRMatrix *A,
1467 hypre_ParCSRCommHandle *comm_handle;
1468 hypre_ParCSRCommPkg *comm_pkg = hypre_ParCSRMatrixCommPkg(A);
1469 hypre_CSRMatrix *diag = hypre_ParCSRMatrixDiag(A);
1470 hypre_CSRMatrix *offd = hypre_ParCSRMatrixOffd(A);
1472 HYPRE_Int num_cols_offd = hypre_CSRMatrixNumCols(offd);
1473 HYPRE_Int num_sends, i, j,
index;
1475 HYPRE_Real *x_tmp, *x_buf;
1477 x_tmp = mfem_hypre_CTAlloc_host(HYPRE_Real, num_cols_offd);
1485 hypre_MatvecCommPkgCreate(A);
1486 comm_pkg = hypre_ParCSRMatrixCommPkg(A);
1489 num_sends = hypre_ParCSRCommPkgNumSends(comm_pkg);
1490 x_buf = mfem_hypre_CTAlloc_host(
1491 HYPRE_Real, hypre_ParCSRCommPkgSendMapStart(comm_pkg, num_sends));
1494 for (i = 0; i < num_sends; i++)
1496 j = hypre_ParCSRCommPkgSendMapStart(comm_pkg, i);
1497 for ( ; j < hypre_ParCSRCommPkgSendMapStart(comm_pkg, i+1); j++)
1499 x_buf[index++] = x[hypre_ParCSRCommPkgSendMapElmt(comm_pkg, j)];
1503 comm_handle = hypre_ParCSRCommHandleCreate(1, comm_pkg, x_buf, x_tmp);
1505 hypre_CSRMatrixAbsMatvec(diag, alpha, x, beta, y);
1507 hypre_ParCSRCommHandleDestroy(comm_handle);
1511 hypre_CSRMatrixAbsMatvec(offd, alpha, x_tmp, 1.0, y);
1514 mfem_hypre_TFree_host(x_buf);
1515 mfem_hypre_TFree_host(x_tmp);
1519 void hypre_ParCSRMatrixAbsMatvecT(hypre_ParCSRMatrix *A,
1525 hypre_ParCSRCommHandle *comm_handle;
1526 hypre_ParCSRCommPkg *comm_pkg = hypre_ParCSRMatrixCommPkg(A);
1527 hypre_CSRMatrix *diag = hypre_ParCSRMatrixDiag(A);
1528 hypre_CSRMatrix *offd = hypre_ParCSRMatrixOffd(A);
1532 HYPRE_Int num_cols_offd = hypre_CSRMatrixNumCols(offd);
1534 HYPRE_Int i, j, jj, end, num_sends;
1536 y_tmp = mfem_hypre_TAlloc_host(HYPRE_Real, num_cols_offd);
1544 hypre_MatvecCommPkgCreate(A);
1545 comm_pkg = hypre_ParCSRMatrixCommPkg(A);
1548 num_sends = hypre_ParCSRCommPkgNumSends(comm_pkg);
1549 y_buf = mfem_hypre_CTAlloc_host(
1550 HYPRE_Real, hypre_ParCSRCommPkgSendMapStart(comm_pkg, num_sends));
1554 #if MFEM_HYPRE_VERSION >= 21100
1558 hypre_CSRMatrixAbsMatvec(A->offdT, alpha, x, 0., y_tmp);
1563 hypre_CSRMatrixAbsMatvecT(offd, alpha, x, 0., y_tmp);
1567 comm_handle = hypre_ParCSRCommHandleCreate(2, comm_pkg, y_tmp, y_buf);
1569 #if MFEM_HYPRE_VERSION >= 21100
1573 hypre_CSRMatrixAbsMatvec(A->diagT, alpha, x, beta, y);
1578 hypre_CSRMatrixAbsMatvecT(diag, alpha, x, beta, y);
1581 hypre_ParCSRCommHandleDestroy(comm_handle);
1583 for (i = 0; i < num_sends; i++)
1585 end = hypre_ParCSRCommPkgSendMapStart(comm_pkg, i+1);
1586 for (j = hypre_ParCSRCommPkgSendMapStart(comm_pkg, i); j < end; j++)
1588 jj = hypre_ParCSRCommPkgSendMapElmt(comm_pkg, j);
1593 mfem_hypre_TFree_host(y_buf);
1594 mfem_hypre_TFree_host(y_tmp);
1598 void hypre_ParCSRMatrixBooleanMatvec(hypre_ParCSRMatrix *A,
1604 hypre_ParCSRCommHandle *comm_handle;
1605 hypre_ParCSRCommPkg *comm_pkg = hypre_ParCSRMatrixCommPkg(A);
1606 hypre_CSRMatrix *diag = hypre_ParCSRMatrixDiag(A);
1607 hypre_CSRMatrix *offd = hypre_ParCSRMatrixOffd(A);
1609 HYPRE_Int num_cols_offd = hypre_CSRMatrixNumCols(offd);
1610 HYPRE_Int num_sends, i, j,
index;
1612 HYPRE_Bool *x_tmp, *x_buf;
1614 x_tmp = mfem_hypre_CTAlloc_host(HYPRE_Bool, num_cols_offd);
1622 hypre_MatvecCommPkgCreate(A);
1623 comm_pkg = hypre_ParCSRMatrixCommPkg(A);
1626 num_sends = hypre_ParCSRCommPkgNumSends(comm_pkg);
1627 x_buf = mfem_hypre_CTAlloc_host(
1628 HYPRE_Bool, hypre_ParCSRCommPkgSendMapStart(comm_pkg, num_sends));
1631 for (i = 0; i < num_sends; i++)
1633 j = hypre_ParCSRCommPkgSendMapStart(comm_pkg, i);
1634 for ( ; j < hypre_ParCSRCommPkgSendMapStart(comm_pkg, i+1); j++)
1636 x_buf[index++] = x[hypre_ParCSRCommPkgSendMapElmt(comm_pkg, j)];
1640 comm_handle = hypre_ParCSRCommHandleCreate_bool(1, comm_pkg, x_buf, x_tmp);
1642 hypre_CSRMatrixBooleanMatvec(diag, alpha, x, beta, y);
1644 hypre_ParCSRCommHandleDestroy(comm_handle);
1648 hypre_CSRMatrixBooleanMatvec(offd, alpha, x_tmp, 1, y);
1651 mfem_hypre_TFree_host(x_buf);
1652 mfem_hypre_TFree_host(x_tmp);
1656 void hypre_ParCSRMatrixBooleanMatvecT(hypre_ParCSRMatrix *A,
1662 hypre_ParCSRCommHandle *comm_handle;
1663 hypre_ParCSRCommPkg *comm_pkg = hypre_ParCSRMatrixCommPkg(A);
1664 hypre_CSRMatrix *diag = hypre_ParCSRMatrixDiag(A);
1665 hypre_CSRMatrix *offd = hypre_ParCSRMatrixOffd(A);
1669 HYPRE_Int num_cols_offd = hypre_CSRMatrixNumCols(offd);
1671 HYPRE_Int i, j, jj, end, num_sends;
1673 y_tmp = mfem_hypre_TAlloc_host(HYPRE_Bool, num_cols_offd);
1681 hypre_MatvecCommPkgCreate(A);
1682 comm_pkg = hypre_ParCSRMatrixCommPkg(A);
1685 num_sends = hypre_ParCSRCommPkgNumSends(comm_pkg);
1686 y_buf = mfem_hypre_CTAlloc_host(
1687 HYPRE_Bool, hypre_ParCSRCommPkgSendMapStart(comm_pkg, num_sends));
1691 #if MFEM_HYPRE_VERSION >= 21100
1695 hypre_CSRMatrixBooleanMatvec(A->offdT, alpha, x, 0, y_tmp);
1700 hypre_CSRMatrixBooleanMatvecT(offd, alpha, x, 0, y_tmp);
1704 comm_handle = hypre_ParCSRCommHandleCreate_bool(2, comm_pkg, y_tmp, y_buf);
1706 #if MFEM_HYPRE_VERSION >= 21100
1710 hypre_CSRMatrixBooleanMatvec(A->diagT, alpha, x, beta, y);
1715 hypre_CSRMatrixBooleanMatvecT(diag, alpha, x, beta, y);
1718 hypre_ParCSRCommHandleDestroy(comm_handle);
1720 for (i = 0; i < num_sends; i++)
1722 end = hypre_ParCSRCommPkgSendMapStart(comm_pkg, i+1);
1723 for (j = hypre_ParCSRCommPkgSendMapStart(comm_pkg, i); j < end; j++)
1725 jj = hypre_ParCSRCommPkgSendMapElmt(comm_pkg, j);
1726 y[jj] = y[jj] || y_buf[j];
1730 mfem_hypre_TFree_host(y_buf);
1731 mfem_hypre_TFree_host(y_tmp);
1735 hypre_CSRMatrixSum(hypre_CSRMatrix *A,
1739 HYPRE_Complex *A_data = hypre_CSRMatrixData(A);
1740 HYPRE_Int *A_i = hypre_CSRMatrixI(A);
1741 HYPRE_Int *A_j = hypre_CSRMatrixJ(A);
1742 HYPRE_Int nrows_A = hypre_CSRMatrixNumRows(A);
1743 HYPRE_Int ncols_A = hypre_CSRMatrixNumCols(A);
1744 HYPRE_Complex *B_data = hypre_CSRMatrixData(B);
1745 HYPRE_Int *B_i = hypre_CSRMatrixI(B);
1746 HYPRE_Int *B_j = hypre_CSRMatrixJ(B);
1747 HYPRE_Int nrows_B = hypre_CSRMatrixNumRows(B);
1748 HYPRE_Int ncols_B = hypre_CSRMatrixNumCols(B);
1750 HYPRE_Int ia, j, pos;
1753 if (nrows_A != nrows_B || ncols_A != ncols_B)
1758 marker = mfem_hypre_CTAlloc_host(HYPRE_Int, ncols_A);
1759 for (ia = 0; ia < ncols_A; ia++)
1764 for (ia = 0; ia < nrows_A; ia++)
1766 for (j = A_i[ia]; j < A_i[ia+1]; j++)
1771 for (j = B_i[ia]; j < B_i[ia+1]; j++)
1773 pos = marker[B_j[j]];
1778 A_data[pos] += beta * B_data[j];
1782 mfem_hypre_TFree_host(marker);
1786 hypre_ParCSRMatrix *
1787 hypre_ParCSRMatrixAdd(hypre_ParCSRMatrix *A,
1788 hypre_ParCSRMatrix *B)
1790 MPI_Comm comm = hypre_ParCSRMatrixComm(A);
1791 hypre_CSRMatrix *A_diag = hypre_ParCSRMatrixDiag(A);
1792 hypre_CSRMatrix *A_offd = hypre_ParCSRMatrixOffd(A);
1793 HYPRE_BigInt *A_cmap = hypre_ParCSRMatrixColMapOffd(A);
1794 HYPRE_Int A_cmap_size = hypre_CSRMatrixNumCols(A_offd);
1795 hypre_CSRMatrix *B_diag = hypre_ParCSRMatrixDiag(B);
1796 hypre_CSRMatrix *B_offd = hypre_ParCSRMatrixOffd(B);
1797 HYPRE_BigInt *B_cmap = hypre_ParCSRMatrixColMapOffd(B);
1798 HYPRE_Int B_cmap_size = hypre_CSRMatrixNumCols(B_offd);
1799 hypre_ParCSRMatrix *C;
1800 hypre_CSRMatrix *C_diag;
1801 hypre_CSRMatrix *C_offd;
1804 HYPRE_Int cmap_differ;
1808 if (A_cmap_size != B_cmap_size)
1814 for (im = 0; im < A_cmap_size; im++)
1816 if (A_cmap[im] != B_cmap[im])
1824 if ( cmap_differ == 0 )
1831 C_diag = hypre_CSRMatrixAdd(A_diag, B_diag);
1836 C_offd = hypre_CSRMatrixAdd(A_offd, B_offd);
1839 hypre_CSRMatrixDestroy(C_diag);
1843 C_cmap = mfem_hypre_TAlloc_host(
HYPRE_BigInt, A_cmap_size);
1844 for (im = 0; im < A_cmap_size; im++)
1846 C_cmap[im] = A_cmap[im];
1849 C = hypre_ParCSRMatrixCreate(comm,
1850 hypre_ParCSRMatrixGlobalNumRows(A),
1851 hypre_ParCSRMatrixGlobalNumCols(A),
1852 hypre_ParCSRMatrixRowStarts(A),
1853 hypre_ParCSRMatrixColStarts(A),
1854 hypre_CSRMatrixNumCols(C_offd),
1855 hypre_CSRMatrixNumNonzeros(C_diag),
1856 hypre_CSRMatrixNumNonzeros(C_offd));
1860 hypre_CSRMatrixDestroy(hypre_ParCSRMatrixDiag(C));
1861 hypre_CSRMatrixDestroy(hypre_ParCSRMatrixOffd(C));
1862 hypre_ParCSRMatrixDiag(C) = C_diag;
1863 hypre_ParCSRMatrixOffd(C) = C_offd;
1865 hypre_ParCSRMatrixColMapOffd(C) = C_cmap;
1873 hypre_CSRMatrix * csr_A;
1874 hypre_CSRMatrix * csr_B;
1875 hypre_CSRMatrix * csr_C_temp;
1878 csr_A = hypre_MergeDiagAndOffd(A);
1881 csr_B = hypre_MergeDiagAndOffd(B);
1884 csr_C_temp = hypre_CSRMatrixAdd(csr_A, csr_B);
1887 ierr += hypre_CSRMatrixDestroy(csr_A);
1888 ierr += hypre_CSRMatrixDestroy(csr_B);
1891 C = hypre_ParCSRMatrixCreate(hypre_ParCSRMatrixComm(A),
1892 hypre_ParCSRMatrixGlobalNumRows(A),
1893 hypre_ParCSRMatrixGlobalNumCols(A),
1894 hypre_ParCSRMatrixRowStarts(A),
1895 hypre_ParCSRMatrixColStarts(A),
1902 ierr += GenerateDiagAndOffd(csr_C_temp, C,
1903 hypre_ParCSRMatrixFirstColDiag(A),
1904 hypre_ParCSRMatrixLastColDiag(A));
1907 ierr += hypre_CSRMatrixDestroy(csr_C_temp);
1909 MFEM_VERIFY(ierr == 0,
"");
1915 hypre_CSRMatrixReorder(hypre_ParCSRMatrixDiag(C));
1918 hypre_ParCSRMatrixSetDataOwner(C, 1);
1920 hypre_ParCSRMatrixSetRowStartsOwner(C, 0);
1921 hypre_ParCSRMatrixSetColStartsOwner(C, 0);
1927 hypre_ParCSRMatrixSum(hypre_ParCSRMatrix *A,
1929 hypre_ParCSRMatrix *B)
1931 hypre_CSRMatrix *A_diag = hypre_ParCSRMatrixDiag(A);
1932 hypre_CSRMatrix *A_offd = hypre_ParCSRMatrixOffd(A);
1933 hypre_CSRMatrix *B_diag = hypre_ParCSRMatrixDiag(B);
1934 hypre_CSRMatrix *B_offd = hypre_ParCSRMatrixOffd(B);
1935 HYPRE_Int ncols_B_offd = hypre_CSRMatrixNumCols(B_offd);
1938 error = hypre_CSRMatrixSum(A_diag, beta, B_diag);
1939 if (ncols_B_offd > 0)
1941 error = error ? error : hypre_CSRMatrixSum(A_offd, beta, B_offd);
1948 hypre_CSRMatrixSetConstantValues(hypre_CSRMatrix *A,
1949 HYPRE_Complex value)
1951 HYPRE_Complex *A_data = hypre_CSRMatrixData(A);
1952 HYPRE_Int A_nnz = hypre_CSRMatrixNumNonzeros(A);
1955 for (ia = 0; ia < A_nnz; ia++)
1964 hypre_ParCSRMatrixSetConstantValues(hypre_ParCSRMatrix *A,
1965 HYPRE_Complex value)
1967 internal::hypre_CSRMatrixSetConstantValues(hypre_ParCSRMatrixDiag(A), value);
1968 internal::hypre_CSRMatrixSetConstantValues(hypre_ParCSRMatrixOffd(A), value);
1977 #endif // MFEM_USE_MPI
int index(int i, int j, int nx, int ny)