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 ii = 0; ii < num_rowscols_to_elim; ii++)
307 irow = rowscols_to_elim[ii];
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 #if MFEM_HYPRE_VERSION <= 22200
512 hypre_ParCSRMatrixSetRowStartsOwner(*Ae, 0);
513 hypre_ParCSRMatrixSetColStartsOwner(*Ae, 0);
516 hypre_CSRMatrix *Ae_diag = hypre_ParCSRMatrixDiag(*Ae);
517 hypre_CSRMatrix *Ae_offd = hypre_ParCSRMatrixOffd(*Ae);
518 HYPRE_Int Ae_offd_ncols;
520 HYPRE_Int num_offd_cols_to_elim;
521 HYPRE_Int *offd_cols_to_elim;
523 HYPRE_BigInt *A_col_map_offd = hypre_ParCSRMatrixColMapOffd(A);
527 HYPRE_Int *col_remap;
531 hypre_ParCSRCommHandle *comm_handle;
532 hypre_ParCSRCommPkg *comm_pkg;
533 HYPRE_Int num_sends, *int_buf_data;
534 HYPRE_Int
index, start;
536 HYPRE_Int *eliminate_diag_col = mfem_hypre_CTAlloc_host(HYPRE_Int,
538 HYPRE_Int *eliminate_offd_col = mfem_hypre_CTAlloc_host(HYPRE_Int,
542 comm_pkg = hypre_ParCSRMatrixCommPkg(A);
545 hypre_MatvecCommPkgCreate(A);
546 comm_pkg = hypre_ParCSRMatrixCommPkg(A);
550 for (i = 0; i < A_diag_ncols; i++)
552 eliminate_diag_col[i] = 0;
554 for (i = 0; i < num_rowscols_to_elim; i++)
556 eliminate_diag_col[rowscols_to_elim[i]] = 1;
561 num_sends = hypre_ParCSRCommPkgNumSends(comm_pkg);
562 int_buf_data = mfem_hypre_CTAlloc_host(
564 hypre_ParCSRCommPkgSendMapStart(comm_pkg, num_sends));
566 for (i = 0; i < num_sends; i++)
568 start = hypre_ParCSRCommPkgSendMapStart(comm_pkg, i);
569 for (j = start; j < hypre_ParCSRCommPkgSendMapStart(comm_pkg, i+1); j++)
571 k = hypre_ParCSRCommPkgSendMapElmt(comm_pkg, j);
572 int_buf_data[index++] = eliminate_diag_col[k];
575 comm_handle = hypre_ParCSRCommHandleCreate(11, comm_pkg,
582 hypre_CSRMatrixElimCreate(A_diag, Ae_diag,
584 num_rowscols_to_elim, rowscols_to_elim,
587 hypre_CSRMatrixEliminateRowsCols(A_diag, Ae_diag,
589 num_rowscols_to_elim, rowscols_to_elim,
594 hypre_CSRMatrixElimCreate(A_diag, Ae_diag,
595 num_rowscols_to_elim, rowscols_to_elim,
596 num_rowscols_to_elim, rowscols_to_elim,
599 hypre_CSRMatrixEliminateRowsCols(A_diag, Ae_diag,
600 num_rowscols_to_elim, rowscols_to_elim,
601 num_rowscols_to_elim, rowscols_to_elim,
605 hypre_CSRMatrixReorder(Ae_diag);
608 hypre_ParCSRCommHandleDestroy(comm_handle);
611 num_offd_cols_to_elim = 0;
612 for (i = 0; i < A_offd_ncols; i++)
614 if (eliminate_offd_col[i]) { num_offd_cols_to_elim++; }
617 offd_cols_to_elim = mfem_hypre_CTAlloc_host(HYPRE_Int,
618 num_offd_cols_to_elim);
621 num_offd_cols_to_elim = 0;
622 for (i = 0; i < A_offd_ncols; i++)
624 if (eliminate_offd_col[i])
626 offd_cols_to_elim[num_offd_cols_to_elim++] = i;
630 mfem_hypre_TFree_host(int_buf_data);
631 mfem_hypre_TFree_host(eliminate_offd_col);
632 mfem_hypre_TFree_host(eliminate_diag_col);
636 col_mark = mfem_hypre_CTAlloc_host(HYPRE_Int, A_offd_ncols);
637 col_remap = mfem_hypre_CTAlloc_host(HYPRE_Int, A_offd_ncols);
641 hypre_CSRMatrixElimCreate(A_offd, Ae_offd,
643 num_offd_cols_to_elim, offd_cols_to_elim,
646 for (i = k = 0; i < A_offd_ncols; i++)
648 if (col_mark[i]) { col_remap[i] = k++; }
651 hypre_CSRMatrixEliminateRowsCols(A_offd, Ae_offd,
653 num_offd_cols_to_elim, offd_cols_to_elim,
658 hypre_CSRMatrixElimCreate(A_offd, Ae_offd,
659 num_rowscols_to_elim, rowscols_to_elim,
660 num_offd_cols_to_elim, offd_cols_to_elim,
663 for (i = k = 0; i < A_offd_ncols; i++)
665 if (col_mark[i]) { col_remap[i] = k++; }
668 hypre_CSRMatrixEliminateRowsCols(A_offd, Ae_offd,
669 num_rowscols_to_elim, rowscols_to_elim,
670 num_offd_cols_to_elim, offd_cols_to_elim,
676 for (i = 0; i < A_offd_ncols; i++)
678 if (col_mark[i]) { Ae_offd_ncols++; }
681 Ae_col_map_offd = mfem_hypre_CTAlloc_host(
HYPRE_BigInt, Ae_offd_ncols);
684 for (i = 0; i < A_offd_ncols; i++)
688 Ae_col_map_offd[Ae_offd_ncols++] = A_col_map_offd[i];
692 hypre_ParCSRMatrixColMapOffd(*Ae) = Ae_col_map_offd;
693 hypre_CSRMatrixNumCols(Ae_offd) = Ae_offd_ncols;
695 mfem_hypre_TFree_host(col_remap);
696 mfem_hypre_TFree_host(col_mark);
697 mfem_hypre_TFree_host(offd_cols_to_elim);
699 hypre_ParCSRMatrixSetNumNonzeros(*Ae);
700 hypre_MatvecCommPkgCreate(*Ae);
705 void hypre_ParCSRMatrixEliminateRows(hypre_ParCSRMatrix *A,
706 HYPRE_Int num_rows_to_elim,
707 const HYPRE_Int *rows_to_elim)
709 hypre_CSRMatrix *A_diag = hypre_ParCSRMatrixDiag(A);
710 hypre_CSRMatrix *A_offd = hypre_ParCSRMatrixOffd(A);
711 hypre_CSRMatrixEliminateRows(A_diag, num_rows_to_elim, rows_to_elim);
712 hypre_CSRMatrixEliminateRows(A_offd, num_rows_to_elim, rows_to_elim);
720 void hypre_CSRMatrixSplit(hypre_CSRMatrix *A,
721 HYPRE_Int nr, HYPRE_Int nc,
722 HYPRE_Int *row_block_num, HYPRE_Int *col_block_num,
723 hypre_CSRMatrix **blocks)
725 HYPRE_Int i, j, k, bi, bj;
727 HYPRE_Int* A_i = hypre_CSRMatrixI(A);
728 HYPRE_Int* A_j = hypre_CSRMatrixJ(A);
729 HYPRE_Complex* A_data = hypre_CSRMatrixData(A);
731 HYPRE_Int A_rows = hypre_CSRMatrixNumRows(A);
732 HYPRE_Int A_cols = hypre_CSRMatrixNumCols(A);
734 HYPRE_Int *num_rows = mfem_hypre_CTAlloc_host(HYPRE_Int, nr);
735 HYPRE_Int *num_cols = mfem_hypre_CTAlloc_host(HYPRE_Int, nc);
737 HYPRE_Int *block_row = mfem_hypre_TAlloc_host(HYPRE_Int, A_rows);
738 HYPRE_Int *block_col = mfem_hypre_TAlloc_host(HYPRE_Int, A_cols);
740 for (i = 0; i < A_rows; i++)
742 block_row[i] = num_rows[row_block_num[i]]++;
744 for (j = 0; j < A_cols; j++)
746 block_col[j] = num_cols[col_block_num[j]]++;
750 for (i = 0; i < nr; i++)
752 for (j = 0; j < nc; j++)
754 hypre_CSRMatrix *B = hypre_CSRMatrixCreate(num_rows[i],
756 hypre_CSRMatrixI(B) = mfem_hypre_CTAlloc_host(HYPRE_Int,
758 #if MFEM_HYPRE_VERSION >= 21800
759 hypre_CSRMatrixMemoryLocation(B) = HYPRE_MEMORY_HOST;
761 blocks[i*nc + j] = B;
766 for (i = 0; i < A_rows; i++)
768 bi = row_block_num[i];
769 for (j = A_i[i]; j < A_i[i+1]; j++)
771 bj = col_block_num[A_j[j]];
772 hypre_CSRMatrix *B = blocks[bi*nc + bj];
773 hypre_CSRMatrixI(B)[block_row[i] + 1]++;
778 for (k = 0; k < nr*nc; k++)
780 hypre_CSRMatrix *B = blocks[k];
781 HYPRE_Int* B_i = hypre_CSRMatrixI(B);
783 HYPRE_Int nnz = 0, rs;
784 for (
int kk = 1; kk <= hypre_CSRMatrixNumRows(B); kk++)
786 rs = B_i[kk], B_i[kk] = nnz, nnz += rs;
789 hypre_CSRMatrixJ(B) = mfem_hypre_TAlloc_host(HYPRE_Int, nnz);
790 hypre_CSRMatrixData(B) = mfem_hypre_TAlloc_host(HYPRE_Complex, nnz);
791 hypre_CSRMatrixNumNonzeros(B) = nnz;
795 for (i = 0; i < A_rows; i++)
797 bi = row_block_num[i];
798 for (j = A_i[i]; j < A_i[i+1]; j++)
801 bj = col_block_num[k];
802 hypre_CSRMatrix *B = blocks[bi*nc + bj];
803 HYPRE_Int *bii = hypre_CSRMatrixI(B) + block_row[i] + 1;
804 hypre_CSRMatrixJ(B)[*bii] = block_col[k];
805 hypre_CSRMatrixData(B)[*bii] = A_data[j];
810 mfem_hypre_TFree_host(block_col);
811 mfem_hypre_TFree_host(block_row);
813 mfem_hypre_TFree_host(num_cols);
814 mfem_hypre_TFree_host(num_rows);
818 void hypre_ParCSRMatrixSplit(hypre_ParCSRMatrix *A,
819 HYPRE_Int nr, HYPRE_Int nc,
820 hypre_ParCSRMatrix **blocks,
821 int interleaved_rows,
int interleaved_cols)
825 MPI_Comm comm = hypre_ParCSRMatrixComm(A);
827 hypre_CSRMatrix *Adiag = hypre_ParCSRMatrixDiag(A);
828 hypre_CSRMatrix *Aoffd = hypre_ParCSRMatrixOffd(A);
830 HYPRE_BigInt global_rows = hypre_ParCSRMatrixGlobalNumRows(A);
831 HYPRE_BigInt global_cols = hypre_ParCSRMatrixGlobalNumCols(A);
833 HYPRE_Int local_rows = hypre_CSRMatrixNumRows(Adiag);
834 HYPRE_Int local_cols = hypre_CSRMatrixNumCols(Adiag);
835 HYPRE_Int offd_cols = hypre_CSRMatrixNumCols(Aoffd);
837 hypre_assert(local_rows % nr == 0 && local_cols % nc == 0);
838 hypre_assert(global_rows % nr == 0 && global_cols % nc == 0);
840 HYPRE_Int block_rows = local_rows / nr;
841 HYPRE_Int block_cols = local_cols / nc;
842 HYPRE_Int num_blocks = nr * nc;
845 HYPRE_Int *row_block_num = mfem_hypre_TAlloc_host(HYPRE_Int, local_rows);
846 HYPRE_Int *col_block_num = mfem_hypre_TAlloc_host(HYPRE_Int, local_cols);
848 for (i = 0; i < local_rows; i++)
850 row_block_num[i] = interleaved_rows ? (i % nr) : (i / block_rows);
852 for (i = 0; i < local_cols; i++)
854 col_block_num[i] = interleaved_cols ? (i % nc) : (i / block_cols);
860 hypre_ParCSRCommHandle *comm_handle;
864 hypre_ParCSRCommPkg *comm_pkg = hypre_ParCSRMatrixCommPkg(A);
867 hypre_MatvecCommPkgCreate(A);
868 comm_pkg = hypre_ParCSRMatrixCommPkg(A);
872 HYPRE_Int *count = mfem_hypre_CTAlloc_host(HYPRE_Int, nc);
875 HYPRE_BigInt first_col = hypre_ParCSRMatrixFirstColDiag(A) / nc;
876 for (i = 0; i < local_cols; i++)
878 block_global_col[i] = first_col + count[col_block_num[i]]++;
880 mfem_hypre_TFree_host(count);
883 HYPRE_Int num_sends = hypre_ParCSRCommPkgNumSends(comm_pkg);
884 int_buf_data = mfem_hypre_CTAlloc_host(
886 hypre_ParCSRCommPkgSendMapStart(comm_pkg, num_sends));
887 HYPRE_Int start, index = 0;
888 for (i = 0; i < num_sends; i++)
890 start = hypre_ParCSRCommPkgSendMapStart(comm_pkg, i);
891 for (j = start; j < hypre_ParCSRCommPkgSendMapStart(comm_pkg, i+1); j++)
893 k = hypre_ParCSRCommPkgSendMapElmt(comm_pkg, j);
894 int_buf_data[index++] = col_block_num[k] + nc*block_global_col[k];
898 mfem_hypre_TFree_host(block_global_col);
900 #if MFEM_HYPRE_VERSION < 21600
905 comm_handle = hypre_ParCSRCommHandleCreate(job, comm_pkg, int_buf_data,
910 HYPRE_Int num_procs = 1;
911 if (!hypre_ParCSRMatrixAssumedPartition(A))
913 hypre_MPI_Comm_size(comm, &num_procs);
918 for (i = 0; i <= num_procs; i++)
920 row_starts[i] = hypre_ParCSRMatrixRowStarts(A)[i] / nr;
921 col_starts[i] = hypre_ParCSRMatrixColStarts(A)[i] / nc;
924 for (i = 0; i < num_blocks; i++)
926 blocks[i] = hypre_ParCSRMatrixCreate(comm,
927 global_rows/nr, global_cols/nc,
928 row_starts, col_starts, 0, 0, 0);
932 hypre_CSRMatrix **csr_blocks = mfem_hypre_TAlloc_host(hypre_CSRMatrix*,
934 hypre_CSRMatrixSplit(Adiag, nr, nc, row_block_num, col_block_num,
937 for (i = 0; i < num_blocks; i++)
939 mfem_hypre_TFree_host(hypre_ParCSRMatrixDiag(blocks[i]));
940 hypre_ParCSRMatrixDiag(blocks[i]) = csr_blocks[i];
944 hypre_ParCSRCommHandleDestroy(comm_handle);
945 mfem_hypre_TFree_host(int_buf_data);
948 HYPRE_Int *offd_col_block_num_nc = mfem_hypre_TAlloc_host(HYPRE_Int,
952 for (i = 0; i < offd_cols; i++)
954 offd_global_col[i] = offd_col_block_num[i] / nc;
955 offd_col_block_num_nc[i] = offd_col_block_num[i] % nc;
958 mfem_hypre_TFree_host(offd_col_block_num);
961 hypre_CSRMatrixSplit(Aoffd, nr, nc, row_block_num, offd_col_block_num_nc,
964 for (i = 0; i < num_blocks; i++)
966 mfem_hypre_TFree_host(hypre_ParCSRMatrixOffd(blocks[i]));
967 hypre_ParCSRMatrixOffd(blocks[i]) = csr_blocks[i];
970 mfem_hypre_TFree_host(csr_blocks);
971 mfem_hypre_TFree_host(col_block_num);
972 mfem_hypre_TFree_host(row_block_num);
975 for (
int bi = 0; bi < nr; bi++)
977 for (
int bj = 0; bj < nc; bj++)
979 hypre_ParCSRMatrix *block = blocks[bi*nc + bj];
980 hypre_CSRMatrix *block_offd = hypre_ParCSRMatrixOffd(block);
981 HYPRE_Int block_offd_cols = hypre_CSRMatrixNumCols(block_offd);
985 for (i = j = 0; i < offd_cols; i++)
987 HYPRE_Int bn = offd_col_block_num_nc[i];
988 if (bn == bj) { block_col_map[j++] = offd_global_col[i]; }
990 hypre_assert(j == block_offd_cols);
992 hypre_ParCSRMatrixColMapOffd(block) = block_col_map;
996 mfem_hypre_TFree_host(offd_global_col);
997 mfem_hypre_TFree_host(offd_col_block_num_nc);
1000 for (i = 0; i < num_blocks; i++)
1002 hypre_ParCSRMatrixSetNumNonzeros(blocks[i]);
1003 hypre_MatvecCommPkgCreate(blocks[i]);
1005 hypre_ParCSRMatrixOwnsData(blocks[i]) = 1;
1007 #if MFEM_HYPRE_VERSION <= 22200
1009 hypre_ParCSRMatrixOwnsRowStarts(blocks[i]) = !i;
1010 hypre_ParCSRMatrixOwnsColStarts(blocks[i]) = !i;
1014 #if MFEM_HYPRE_VERSION > 22200
1015 mfem_hypre_TFree_host(row_starts);
1016 mfem_hypre_TFree_host(col_starts);
1021 void hypre_CSRMatrixAbsMatvec(hypre_CSRMatrix *A,
1027 HYPRE_Real *A_data = hypre_CSRMatrixData(A);
1028 HYPRE_Int *A_i = hypre_CSRMatrixI(A);
1029 HYPRE_Int *A_j = hypre_CSRMatrixJ(A);
1030 HYPRE_Int num_rows = hypre_CSRMatrixNumRows(A);
1032 HYPRE_Int *A_rownnz = hypre_CSRMatrixRownnz(A);
1033 HYPRE_Int num_rownnz = hypre_CSRMatrixNumRownnz(A);
1035 HYPRE_Real *x_data = x;
1036 HYPRE_Real *y_data = y;
1038 HYPRE_Real temp, tempx;
1044 HYPRE_Real xpar=0.7;
1052 for (i = 0; i < num_rows; i++)
1063 temp = beta /
alpha;
1069 for (i = 0; i < num_rows; i++)
1076 for (i = 0; i < num_rows; i++)
1090 if (num_rownnz < xpar*(num_rows))
1092 for (i = 0; i < num_rownnz; i++)
1097 for (jj = A_i[m]; jj < A_i[m+1]; jj++)
1099 tempx += std::abs(A_data[jj])*x_data[A_j[jj]];
1106 for (i = 0; i < num_rows; i++)
1109 for (jj = A_i[i]; jj < A_i[i+1]; jj++)
1111 tempx += std::abs(A_data[jj])*x_data[A_j[jj]];
1123 for (i = 0; i < num_rows; i++)
1132 void hypre_CSRMatrixAbsMatvecT(hypre_CSRMatrix *A,
1138 HYPRE_Real *A_data = hypre_CSRMatrixData(A);
1139 HYPRE_Int *A_i = hypre_CSRMatrixI(A);
1140 HYPRE_Int *A_j = hypre_CSRMatrixJ(A);
1141 HYPRE_Int num_rows = hypre_CSRMatrixNumRows(A);
1142 HYPRE_Int num_cols = hypre_CSRMatrixNumCols(A);
1144 HYPRE_Real *x_data = x;
1145 HYPRE_Real *y_data = y;
1153 for (i = 0; i < num_cols; i++)
1164 temp = beta /
alpha;
1170 for (i = 0; i < num_cols; i++)
1177 for (i = 0; i < num_cols; i++)
1188 for (i = 0; i < num_rows; i++)
1190 for (jj = A_i[i]; jj < A_i[i+1]; jj++)
1193 y_data[j] += std::abs(A_data[jj]) * x_data[i];
1203 for (i = 0; i < num_cols; i++)
1211 void hypre_CSRMatrixBooleanMatvec(hypre_CSRMatrix *A,
1218 HYPRE_Int *A_i = hypre_CSRMatrixI(A);
1219 HYPRE_Int *A_j = hypre_CSRMatrixJ(A);
1220 HYPRE_Int num_rows = hypre_CSRMatrixNumRows(A);
1222 HYPRE_Int *A_rownnz = hypre_CSRMatrixRownnz(A);
1223 HYPRE_Int num_rownnz = hypre_CSRMatrixNumRownnz(A);
1225 HYPRE_Bool *x_data = x;
1226 HYPRE_Bool *y_data = y;
1228 HYPRE_Bool temp, tempx;
1234 HYPRE_Real xpar=0.7;
1242 #ifdef HYPRE_USING_OPENMP
1243 #pragma omp parallel for private(i) HYPRE_SMP_SCHEDULE
1245 for (i = 0; i < num_rows; i++)
1247 y_data[i] = y_data[i] && beta;
1258 #ifdef HYPRE_USING_OPENMP
1259 #pragma omp parallel for private(i) HYPRE_SMP_SCHEDULE
1261 for (i = 0; i < num_rows; i++)
1277 if (num_rownnz < xpar*(num_rows))
1279 #ifdef HYPRE_USING_OPENMP
1280 #pragma omp parallel for private(i,jj,m,tempx) HYPRE_SMP_SCHEDULE
1282 for (i = 0; i < num_rownnz; i++)
1287 for (jj = A_i[m]; jj < A_i[m+1]; jj++)
1290 tempx = tempx || x_data[A_j[jj]];
1292 y_data[m] = y_data[m] || tempx;
1297 #ifdef HYPRE_USING_OPENMP
1298 #pragma omp parallel for private(i,jj,temp) HYPRE_SMP_SCHEDULE
1300 for (i = 0; i < num_rows; i++)
1303 for (jj = A_i[i]; jj < A_i[i+1]; jj++)
1306 temp = temp || x_data[A_j[jj]];
1308 y_data[i] = y_data[i] || temp;
1319 void hypre_CSRMatrixBooleanMatvecT(hypre_CSRMatrix *A,
1326 HYPRE_Int *A_i = hypre_CSRMatrixI(A);
1327 HYPRE_Int *A_j = hypre_CSRMatrixJ(A);
1328 HYPRE_Int num_rows = hypre_CSRMatrixNumRows(A);
1329 HYPRE_Int num_cols = hypre_CSRMatrixNumCols(A);
1331 HYPRE_Bool *x_data = x;
1332 HYPRE_Bool *y_data = y;
1342 for (i = 0; i < num_cols; i++)
1366 for (i = 0; i < num_rows; i++)
1370 for (jj = A_i[i]; jj < A_i[i+1]; jj++)
1382 hypre_ParCSRCommHandle *
1383 hypre_ParCSRCommHandleCreate_bool(HYPRE_Int job,
1384 hypre_ParCSRCommPkg *comm_pkg,
1385 HYPRE_Bool *send_data,
1386 HYPRE_Bool *recv_data)
1388 HYPRE_Int num_sends = hypre_ParCSRCommPkgNumSends(comm_pkg);
1389 HYPRE_Int num_recvs = hypre_ParCSRCommPkgNumRecvs(comm_pkg);
1390 MPI_Comm comm = hypre_ParCSRCommPkgComm(comm_pkg);
1392 hypre_ParCSRCommHandle *comm_handle;
1393 HYPRE_Int num_requests;
1394 hypre_MPI_Request *requests;
1397 HYPRE_Int my_id, num_procs;
1398 HYPRE_Int ip, vec_start, vec_len;
1400 num_requests = num_sends + num_recvs;
1401 requests = mfem_hypre_CTAlloc_host(hypre_MPI_Request, num_requests);
1403 hypre_MPI_Comm_size(comm, &num_procs);
1404 hypre_MPI_Comm_rank(comm, &my_id);
1411 HYPRE_Bool *d_send_data = (HYPRE_Bool *) send_data;
1412 HYPRE_Bool *d_recv_data = (HYPRE_Bool *) recv_data;
1413 for (i = 0; i < num_recvs; i++)
1415 ip = hypre_ParCSRCommPkgRecvProc(comm_pkg, i);
1416 vec_start = hypre_ParCSRCommPkgRecvVecStart(comm_pkg, i);
1417 vec_len = hypre_ParCSRCommPkgRecvVecStart(comm_pkg, i+1)-vec_start;
1418 hypre_MPI_Irecv(&d_recv_data[vec_start], vec_len, HYPRE_MPI_BOOL,
1419 ip, 0, comm, &requests[j++]);
1421 for (i = 0; i < num_sends; i++)
1423 vec_start = hypre_ParCSRCommPkgSendMapStart(comm_pkg, i);
1424 vec_len = hypre_ParCSRCommPkgSendMapStart(comm_pkg, i+1)-vec_start;
1425 ip = hypre_ParCSRCommPkgSendProc(comm_pkg, i);
1426 hypre_MPI_Isend(&d_send_data[vec_start], vec_len, HYPRE_MPI_BOOL,
1427 ip, 0, comm, &requests[j++]);
1433 HYPRE_Bool *d_send_data = (HYPRE_Bool *) send_data;
1434 HYPRE_Bool *d_recv_data = (HYPRE_Bool *) recv_data;
1435 for (i = 0; i < num_sends; i++)
1437 vec_start = hypre_ParCSRCommPkgSendMapStart(comm_pkg, i);
1438 vec_len = hypre_ParCSRCommPkgSendMapStart(comm_pkg, i+1)-vec_start;
1439 ip = hypre_ParCSRCommPkgSendProc(comm_pkg, i);
1440 hypre_MPI_Irecv(&d_recv_data[vec_start], vec_len, HYPRE_MPI_BOOL,
1441 ip, 0, comm, &requests[j++]);
1443 for (i = 0; i < num_recvs; i++)
1445 ip = hypre_ParCSRCommPkgRecvProc(comm_pkg, i);
1446 vec_start = hypre_ParCSRCommPkgRecvVecStart(comm_pkg, i);
1447 vec_len = hypre_ParCSRCommPkgRecvVecStart(comm_pkg, i+1)-vec_start;
1448 hypre_MPI_Isend(&d_send_data[vec_start], vec_len, HYPRE_MPI_BOOL,
1449 ip, 0, comm, &requests[j++]);
1458 comm_handle = mfem_hypre_CTAlloc_host(hypre_ParCSRCommHandle, 1);
1460 hypre_ParCSRCommHandleCommPkg(comm_handle) = comm_pkg;
1461 hypre_ParCSRCommHandleSendData(comm_handle) = send_data;
1462 hypre_ParCSRCommHandleRecvData(comm_handle) = recv_data;
1463 hypre_ParCSRCommHandleNumRequests(comm_handle) = num_requests;
1464 hypre_ParCSRCommHandleRequests(comm_handle) = requests;
1470 void hypre_ParCSRMatrixAbsMatvec(hypre_ParCSRMatrix *A,
1476 hypre_ParCSRCommHandle *comm_handle;
1477 hypre_ParCSRCommPkg *comm_pkg = hypre_ParCSRMatrixCommPkg(A);
1478 hypre_CSRMatrix *diag = hypre_ParCSRMatrixDiag(A);
1479 hypre_CSRMatrix *offd = hypre_ParCSRMatrixOffd(A);
1481 HYPRE_Int num_cols_offd = hypre_CSRMatrixNumCols(offd);
1482 HYPRE_Int num_sends, i, j,
index;
1484 HYPRE_Real *x_tmp, *x_buf;
1486 x_tmp = mfem_hypre_CTAlloc_host(HYPRE_Real, num_cols_offd);
1494 hypre_MatvecCommPkgCreate(A);
1495 comm_pkg = hypre_ParCSRMatrixCommPkg(A);
1498 num_sends = hypre_ParCSRCommPkgNumSends(comm_pkg);
1499 x_buf = mfem_hypre_CTAlloc_host(
1500 HYPRE_Real, hypre_ParCSRCommPkgSendMapStart(comm_pkg, num_sends));
1503 for (i = 0; i < num_sends; i++)
1505 j = hypre_ParCSRCommPkgSendMapStart(comm_pkg, i);
1506 for ( ; j < hypre_ParCSRCommPkgSendMapStart(comm_pkg, i+1); j++)
1508 x_buf[index++] = x[hypre_ParCSRCommPkgSendMapElmt(comm_pkg, j)];
1512 comm_handle = hypre_ParCSRCommHandleCreate(1, comm_pkg, x_buf, x_tmp);
1514 hypre_CSRMatrixAbsMatvec(diag, alpha, x, beta, y);
1516 hypre_ParCSRCommHandleDestroy(comm_handle);
1520 hypre_CSRMatrixAbsMatvec(offd, alpha, x_tmp, 1.0, y);
1523 mfem_hypre_TFree_host(x_buf);
1524 mfem_hypre_TFree_host(x_tmp);
1528 void hypre_ParCSRMatrixAbsMatvecT(hypre_ParCSRMatrix *A,
1534 hypre_ParCSRCommHandle *comm_handle;
1535 hypre_ParCSRCommPkg *comm_pkg = hypre_ParCSRMatrixCommPkg(A);
1536 hypre_CSRMatrix *diag = hypre_ParCSRMatrixDiag(A);
1537 hypre_CSRMatrix *offd = hypre_ParCSRMatrixOffd(A);
1541 HYPRE_Int num_cols_offd = hypre_CSRMatrixNumCols(offd);
1543 HYPRE_Int i, j, jj, end, num_sends;
1545 y_tmp = mfem_hypre_TAlloc_host(HYPRE_Real, num_cols_offd);
1553 hypre_MatvecCommPkgCreate(A);
1554 comm_pkg = hypre_ParCSRMatrixCommPkg(A);
1557 num_sends = hypre_ParCSRCommPkgNumSends(comm_pkg);
1558 y_buf = mfem_hypre_CTAlloc_host(
1559 HYPRE_Real, hypre_ParCSRCommPkgSendMapStart(comm_pkg, num_sends));
1565 #if MFEM_HYPRE_VERSION >= 21100 && 0
1569 hypre_CSRMatrixAbsMatvec(A->offdT, alpha, x, 0., y_tmp);
1574 hypre_CSRMatrixAbsMatvecT(offd, alpha, x, 0., y_tmp);
1578 comm_handle = hypre_ParCSRCommHandleCreate(2, comm_pkg, y_tmp, y_buf);
1582 #if MFEM_HYPRE_VERSION >= 21100 && 0
1586 hypre_CSRMatrixAbsMatvec(A->diagT, alpha, x, beta, y);
1591 hypre_CSRMatrixAbsMatvecT(diag, alpha, x, beta, y);
1594 hypre_ParCSRCommHandleDestroy(comm_handle);
1596 for (i = 0; i < num_sends; i++)
1598 end = hypre_ParCSRCommPkgSendMapStart(comm_pkg, i+1);
1599 for (j = hypre_ParCSRCommPkgSendMapStart(comm_pkg, i); j < end; j++)
1601 jj = hypre_ParCSRCommPkgSendMapElmt(comm_pkg, j);
1606 mfem_hypre_TFree_host(y_buf);
1607 mfem_hypre_TFree_host(y_tmp);
1611 void hypre_ParCSRMatrixBooleanMatvec(hypre_ParCSRMatrix *A,
1617 hypre_ParCSRCommHandle *comm_handle;
1618 hypre_ParCSRCommPkg *comm_pkg = hypre_ParCSRMatrixCommPkg(A);
1619 hypre_CSRMatrix *diag = hypre_ParCSRMatrixDiag(A);
1620 hypre_CSRMatrix *offd = hypre_ParCSRMatrixOffd(A);
1622 HYPRE_Int num_cols_offd = hypre_CSRMatrixNumCols(offd);
1623 HYPRE_Int num_sends, i, j,
index;
1625 HYPRE_Bool *x_tmp, *x_buf;
1627 x_tmp = mfem_hypre_CTAlloc_host(HYPRE_Bool, num_cols_offd);
1635 hypre_MatvecCommPkgCreate(A);
1636 comm_pkg = hypre_ParCSRMatrixCommPkg(A);
1639 num_sends = hypre_ParCSRCommPkgNumSends(comm_pkg);
1640 x_buf = mfem_hypre_CTAlloc_host(
1641 HYPRE_Bool, hypre_ParCSRCommPkgSendMapStart(comm_pkg, num_sends));
1644 for (i = 0; i < num_sends; i++)
1646 j = hypre_ParCSRCommPkgSendMapStart(comm_pkg, i);
1647 for ( ; j < hypre_ParCSRCommPkgSendMapStart(comm_pkg, i+1); j++)
1649 x_buf[index++] = x[hypre_ParCSRCommPkgSendMapElmt(comm_pkg, j)];
1653 comm_handle = hypre_ParCSRCommHandleCreate_bool(1, comm_pkg, x_buf, x_tmp);
1655 hypre_CSRMatrixBooleanMatvec(diag, alpha, x, beta, y);
1657 hypre_ParCSRCommHandleDestroy(comm_handle);
1661 hypre_CSRMatrixBooleanMatvec(offd, alpha, x_tmp, 1, y);
1664 mfem_hypre_TFree_host(x_buf);
1665 mfem_hypre_TFree_host(x_tmp);
1669 void hypre_ParCSRMatrixBooleanMatvecT(hypre_ParCSRMatrix *A,
1675 hypre_ParCSRCommHandle *comm_handle;
1676 hypre_ParCSRCommPkg *comm_pkg = hypre_ParCSRMatrixCommPkg(A);
1677 hypre_CSRMatrix *diag = hypre_ParCSRMatrixDiag(A);
1678 hypre_CSRMatrix *offd = hypre_ParCSRMatrixOffd(A);
1682 HYPRE_Int num_cols_offd = hypre_CSRMatrixNumCols(offd);
1684 HYPRE_Int i, j, jj, end, num_sends;
1686 y_tmp = mfem_hypre_TAlloc_host(HYPRE_Bool, num_cols_offd);
1694 hypre_MatvecCommPkgCreate(A);
1695 comm_pkg = hypre_ParCSRMatrixCommPkg(A);
1698 num_sends = hypre_ParCSRCommPkgNumSends(comm_pkg);
1699 y_buf = mfem_hypre_CTAlloc_host(
1700 HYPRE_Bool, hypre_ParCSRCommPkgSendMapStart(comm_pkg, num_sends));
1706 #if MFEM_HYPRE_VERSION >= 21100 && 0
1710 hypre_CSRMatrixBooleanMatvec(A->offdT, alpha, x, 0, y_tmp);
1715 hypre_CSRMatrixBooleanMatvecT(offd, alpha, x, 0, y_tmp);
1719 comm_handle = hypre_ParCSRCommHandleCreate_bool(2, comm_pkg, y_tmp, y_buf);
1723 #if MFEM_HYPRE_VERSION >= 21100 && 0
1727 hypre_CSRMatrixBooleanMatvec(A->diagT, alpha, x, beta, y);
1732 hypre_CSRMatrixBooleanMatvecT(diag, alpha, x, beta, y);
1735 hypre_ParCSRCommHandleDestroy(comm_handle);
1737 for (i = 0; i < num_sends; i++)
1739 end = hypre_ParCSRCommPkgSendMapStart(comm_pkg, i+1);
1740 for (j = hypre_ParCSRCommPkgSendMapStart(comm_pkg, i); j < end; j++)
1742 jj = hypre_ParCSRCommPkgSendMapElmt(comm_pkg, j);
1743 y[jj] = y[jj] || y_buf[j];
1747 mfem_hypre_TFree_host(y_buf);
1748 mfem_hypre_TFree_host(y_tmp);
1752 hypre_CSRMatrixSum(hypre_CSRMatrix *A,
1756 HYPRE_Complex *A_data = hypre_CSRMatrixData(A);
1757 HYPRE_Int *A_i = hypre_CSRMatrixI(A);
1758 HYPRE_Int *A_j = hypre_CSRMatrixJ(A);
1759 HYPRE_Int nrows_A = hypre_CSRMatrixNumRows(A);
1760 HYPRE_Int ncols_A = hypre_CSRMatrixNumCols(A);
1761 HYPRE_Complex *B_data = hypre_CSRMatrixData(B);
1762 HYPRE_Int *B_i = hypre_CSRMatrixI(B);
1763 HYPRE_Int *B_j = hypre_CSRMatrixJ(B);
1764 HYPRE_Int nrows_B = hypre_CSRMatrixNumRows(B);
1765 HYPRE_Int ncols_B = hypre_CSRMatrixNumCols(B);
1767 HYPRE_Int ia, j, pos;
1770 if (nrows_A != nrows_B || ncols_A != ncols_B)
1775 marker = mfem_hypre_CTAlloc_host(HYPRE_Int, ncols_A);
1776 for (ia = 0; ia < ncols_A; ia++)
1781 for (ia = 0; ia < nrows_A; ia++)
1783 for (j = A_i[ia]; j < A_i[ia+1]; j++)
1788 for (j = B_i[ia]; j < B_i[ia+1]; j++)
1790 pos = marker[B_j[j]];
1795 A_data[pos] += beta * B_data[j];
1799 mfem_hypre_TFree_host(marker);
1803 hypre_ParCSRMatrix *
1804 hypre_ParCSRMatrixAdd(hypre_ParCSRMatrix *A,
1805 hypre_ParCSRMatrix *B)
1807 MPI_Comm comm = hypre_ParCSRMatrixComm(A);
1808 hypre_CSRMatrix *A_diag = hypre_ParCSRMatrixDiag(A);
1809 hypre_CSRMatrix *A_offd = hypre_ParCSRMatrixOffd(A);
1810 HYPRE_BigInt *A_cmap = hypre_ParCSRMatrixColMapOffd(A);
1811 HYPRE_Int A_cmap_size = hypre_CSRMatrixNumCols(A_offd);
1812 hypre_CSRMatrix *B_diag = hypre_ParCSRMatrixDiag(B);
1813 hypre_CSRMatrix *B_offd = hypre_ParCSRMatrixOffd(B);
1814 HYPRE_BigInt *B_cmap = hypre_ParCSRMatrixColMapOffd(B);
1815 HYPRE_Int B_cmap_size = hypre_CSRMatrixNumCols(B_offd);
1816 hypre_ParCSRMatrix *C;
1817 hypre_CSRMatrix *C_diag;
1818 hypre_CSRMatrix *C_offd;
1821 HYPRE_Int cmap_differ;
1825 if (A_cmap_size != B_cmap_size)
1831 for (im = 0; im < A_cmap_size; im++)
1833 if (A_cmap[im] != B_cmap[im])
1841 if ( cmap_differ == 0 )
1848 C_diag = hypre_CSRMatrixAdd(A_diag, B_diag);
1853 C_offd = hypre_CSRMatrixAdd(A_offd, B_offd);
1856 hypre_CSRMatrixDestroy(C_diag);
1860 C_cmap = mfem_hypre_TAlloc_host(
HYPRE_BigInt, A_cmap_size);
1861 for (im = 0; im < A_cmap_size; im++)
1863 C_cmap[im] = A_cmap[im];
1866 C = hypre_ParCSRMatrixCreate(comm,
1867 hypre_ParCSRMatrixGlobalNumRows(A),
1868 hypre_ParCSRMatrixGlobalNumCols(A),
1869 hypre_ParCSRMatrixRowStarts(A),
1870 hypre_ParCSRMatrixColStarts(A),
1871 hypre_CSRMatrixNumCols(C_offd),
1872 hypre_CSRMatrixNumNonzeros(C_diag),
1873 hypre_CSRMatrixNumNonzeros(C_offd));
1877 hypre_CSRMatrixDestroy(hypre_ParCSRMatrixDiag(C));
1878 hypre_CSRMatrixDestroy(hypre_ParCSRMatrixOffd(C));
1879 hypre_ParCSRMatrixDiag(C) = C_diag;
1880 hypre_ParCSRMatrixOffd(C) = C_offd;
1882 hypre_ParCSRMatrixColMapOffd(C) = C_cmap;
1890 hypre_CSRMatrix * csr_A;
1891 hypre_CSRMatrix * csr_B;
1892 hypre_CSRMatrix * csr_C_temp;
1895 csr_A = hypre_MergeDiagAndOffd(A);
1898 csr_B = hypre_MergeDiagAndOffd(B);
1901 csr_C_temp = hypre_CSRMatrixAdd(csr_A, csr_B);
1904 ierr += hypre_CSRMatrixDestroy(csr_A);
1905 ierr += hypre_CSRMatrixDestroy(csr_B);
1908 C = hypre_ParCSRMatrixCreate(hypre_ParCSRMatrixComm(A),
1909 hypre_ParCSRMatrixGlobalNumRows(A),
1910 hypre_ParCSRMatrixGlobalNumCols(A),
1911 hypre_ParCSRMatrixRowStarts(A),
1912 hypre_ParCSRMatrixColStarts(A),
1919 ierr += GenerateDiagAndOffd(csr_C_temp, C,
1920 hypre_ParCSRMatrixFirstColDiag(A),
1921 hypre_ParCSRMatrixLastColDiag(A));
1924 ierr += hypre_CSRMatrixDestroy(csr_C_temp);
1926 MFEM_VERIFY(ierr == 0,
"");
1932 hypre_CSRMatrixReorder(hypre_ParCSRMatrixDiag(C));
1935 hypre_ParCSRMatrixSetDataOwner(C, 1);
1937 #if MFEM_HYPRE_VERSION <= 22200
1939 hypre_ParCSRMatrixSetRowStartsOwner(C, 0);
1940 hypre_ParCSRMatrixSetColStartsOwner(C, 0);
1947 hypre_ParCSRMatrixSum(hypre_ParCSRMatrix *A,
1949 hypre_ParCSRMatrix *B)
1951 hypre_CSRMatrix *A_diag = hypre_ParCSRMatrixDiag(A);
1952 hypre_CSRMatrix *A_offd = hypre_ParCSRMatrixOffd(A);
1953 hypre_CSRMatrix *B_diag = hypre_ParCSRMatrixDiag(B);
1954 hypre_CSRMatrix *B_offd = hypre_ParCSRMatrixOffd(B);
1955 HYPRE_Int ncols_B_offd = hypre_CSRMatrixNumCols(B_offd);
1958 error = hypre_CSRMatrixSum(A_diag, beta, B_diag);
1959 if (ncols_B_offd > 0)
1961 error = error ? error : hypre_CSRMatrixSum(A_offd, beta, B_offd);
1968 hypre_CSRMatrixSetConstantValues(hypre_CSRMatrix *A,
1969 HYPRE_Complex value)
1971 HYPRE_Complex *A_data = hypre_CSRMatrixData(A);
1972 HYPRE_Int A_nnz = hypre_CSRMatrixNumNonzeros(A);
1975 for (ia = 0; ia < A_nnz; ia++)
1984 hypre_ParCSRMatrixSetConstantValues(hypre_ParCSRMatrix *A,
1985 HYPRE_Complex value)
1987 internal::hypre_CSRMatrixSetConstantValues(hypre_ParCSRMatrixDiag(A), value);
1988 internal::hypre_CSRMatrixSetConstantValues(hypre_ParCSRMatrixOffd(A), value);
1997 #endif // MFEM_USE_MPI
int index(int i, int j, int nx, int ny)