12 #include "../config/config.hpp"
13 #include "../general/error.hpp"
37 void hypre_CSRMatrixEliminateAXB(hypre_CSRMatrix *A,
38 HYPRE_Int nrows_to_eliminate,
39 HYPRE_Int *rows_to_eliminate,
44 HYPRE_Int irow, jcol, ibeg, iend, pos;
47 HYPRE_Int *Ai = hypre_CSRMatrixI(A);
48 HYPRE_Int *Aj = hypre_CSRMatrixJ(A);
49 HYPRE_Real *Adata = hypre_CSRMatrixData(A);
50 HYPRE_Int nrows = hypre_CSRMatrixNumRows(A);
52 HYPRE_Real *Xdata = hypre_VectorData(X);
53 HYPRE_Real *Bdata = hypre_VectorData(B);
56 for (i = 0; i < nrows; i++)
60 for (j = ibeg; j < iend; j++)
63 pos = hypre_BinarySearch(rows_to_eliminate, jcol, nrows_to_eliminate);
68 Bdata[i] -= a * Xdata[jcol];
74 for (i = 0; i < nrows_to_eliminate; i++)
76 irow = rows_to_eliminate[i];
79 for (j = ibeg; j < iend; j++)
98 void hypre_CSRMatrixEliminateOffdColsAXB(hypre_CSRMatrix *A,
99 HYPRE_Int ncols_to_eliminate,
100 HYPRE_Int *eliminate_cols,
101 HYPRE_Real *eliminate_coefs,
105 HYPRE_Int ibeg, iend, pos;
108 HYPRE_Int *Ai = hypre_CSRMatrixI(A);
109 HYPRE_Int *Aj = hypre_CSRMatrixJ(A);
110 HYPRE_Real *Adata = hypre_CSRMatrixData(A);
111 HYPRE_Int nrows = hypre_CSRMatrixNumRows(A);
113 HYPRE_Real *Bdata = hypre_VectorData(B);
115 for (i = 0; i < nrows; i++)
119 for (j = ibeg; j < iend; j++)
121 pos = hypre_BinarySearch(eliminate_cols, Aj[j], ncols_to_eliminate);
126 Bdata[i] -= a * eliminate_coefs[pos];
137 void hypre_CSRMatrixEliminateOffdRowsAXB(hypre_CSRMatrix *A,
138 HYPRE_Int nrows_to_eliminate,
139 HYPRE_Int *rows_to_eliminate)
141 HYPRE_Int *Ai = hypre_CSRMatrixI(A);
142 HYPRE_Real *Adata = hypre_CSRMatrixData(A);
145 HYPRE_Int irow, ibeg, iend;
147 for (i = 0; i < nrows_to_eliminate; i++)
149 irow = rows_to_eliminate[i];
152 for (j = ibeg; j < iend; j++)
183 void hypre_ParCSRMatrixEliminateAXB(hypre_ParCSRMatrix *A,
184 HYPRE_Int num_rowscols_to_elim,
185 HYPRE_Int *rowscols_to_elim,
189 hypre_CSRMatrix *diag = hypre_ParCSRMatrixDiag(A);
190 hypre_CSRMatrix *offd = hypre_ParCSRMatrixOffd(A);
191 HYPRE_Int diag_nrows = hypre_CSRMatrixNumRows(diag);
192 HYPRE_Int offd_ncols = hypre_CSRMatrixNumCols(offd);
194 hypre_Vector *Xlocal = hypre_ParVectorLocalVector(X);
195 hypre_Vector *Blocal = hypre_ParVectorLocalVector(B);
197 HYPRE_Real *Bdata = hypre_VectorData(Blocal);
198 HYPRE_Real *Xdata = hypre_VectorData(Xlocal);
200 HYPRE_Int num_offd_cols_to_elim;
201 HYPRE_Int *offd_cols_to_elim;
202 HYPRE_Real *eliminate_coefs;
205 hypre_ParCSRCommHandle *comm_handle;
206 hypre_ParCSRCommPkg *comm_pkg;
208 HYPRE_Int
index, start;
209 HYPRE_Int i, j, k, irow;
211 HYPRE_Real *eliminate_row = mfem_hypre_CTAlloc(HYPRE_Real, diag_nrows);
212 HYPRE_Real *eliminate_col = mfem_hypre_CTAlloc(HYPRE_Real, offd_ncols);
213 HYPRE_Real *buf_data, coef;
216 comm_pkg = hypre_ParCSRMatrixCommPkg(A);
219 hypre_MatvecCommPkgCreate(A);
220 comm_pkg = hypre_ParCSRMatrixCommPkg(A);
226 for (i = 0; i < diag_nrows; i++)
228 eliminate_row[i] = std::numeric_limits<HYPRE_Real>::quiet_NaN();
230 for (i = 0; i < num_rowscols_to_elim; i++)
232 irow = rowscols_to_elim[i];
233 eliminate_row[irow] = Xdata[irow];
238 num_sends = hypre_ParCSRCommPkgNumSends(comm_pkg);
239 buf_data = mfem_hypre_CTAlloc(HYPRE_Real,
240 hypre_ParCSRCommPkgSendMapStart(comm_pkg,
243 for (i = 0; i < num_sends; i++)
245 start = hypre_ParCSRCommPkgSendMapStart(comm_pkg, i);
246 for (j = start; j < hypre_ParCSRCommPkgSendMapStart(comm_pkg, i+1); j++)
248 k = hypre_ParCSRCommPkgSendMapElmt(comm_pkg,j);
249 buf_data[index++] = eliminate_row[k];
252 comm_handle = hypre_ParCSRCommHandleCreate(1, comm_pkg,
253 buf_data, eliminate_col);
256 hypre_CSRMatrixEliminateAXB(diag, num_rowscols_to_elim, rowscols_to_elim,
260 hypre_ParCSRCommHandleDestroy(comm_handle);
263 num_offd_cols_to_elim = 0;
264 for (i = 0; i < offd_ncols; i++)
266 coef = eliminate_col[i];
269 num_offd_cols_to_elim++;
273 offd_cols_to_elim = mfem_hypre_CTAlloc(HYPRE_Int, num_offd_cols_to_elim);
274 eliminate_coefs = mfem_hypre_CTAlloc(HYPRE_Real, num_offd_cols_to_elim);
277 num_offd_cols_to_elim = 0;
278 for (i = 0; i < offd_ncols; i++)
280 coef = eliminate_col[i];
283 offd_cols_to_elim[num_offd_cols_to_elim] = i;
284 eliminate_coefs[num_offd_cols_to_elim] = coef;
285 num_offd_cols_to_elim++;
289 mfem_hypre_TFree(buf_data);
290 mfem_hypre_TFree(eliminate_col);
291 mfem_hypre_TFree(eliminate_row);
294 hypre_CSRMatrixEliminateOffdColsAXB(offd, num_offd_cols_to_elim,
296 eliminate_coefs, Blocal);
298 hypre_CSRMatrixEliminateOffdRowsAXB(offd, num_rowscols_to_elim,
302 for (
int i = 0; i < num_rowscols_to_elim; i++)
304 irow = rowscols_to_elim[i];
305 Bdata[irow] = Xdata[irow];
308 mfem_hypre_TFree(offd_cols_to_elim);
309 mfem_hypre_TFree(eliminate_coefs);
322 void hypre_CSRMatrixElimCreate(hypre_CSRMatrix *A,
324 HYPRE_Int nrows, HYPRE_Int *rows,
325 HYPRE_Int ncols, HYPRE_Int *cols,
329 HYPRE_Int A_beg, A_end;
331 HYPRE_Int *A_i = hypre_CSRMatrixI(A);
332 HYPRE_Int *A_j = hypre_CSRMatrixJ(A);
333 HYPRE_Int A_rows = hypre_CSRMatrixNumRows(A);
335 hypre_CSRMatrixI(Ae) = mfem_hypre_TAlloc(HYPRE_Int, A_rows+1);
337 HYPRE_Int *Ae_i = hypre_CSRMatrixI(Ae);
340 for (i = 0; i < A_rows; i++)
347 if (hypre_BinarySearch(rows, i, nrows) >= 0)
350 nnz += A_end - A_beg;
354 for (j = A_beg; j < A_end; j++)
356 col_mark[A_j[j]] = 1;
363 for (j = A_beg; j < A_end; j++)
366 if (hypre_BinarySearch(cols, col, ncols) >= 0)
369 if (col_mark) { col_mark[col] = 1; }
376 hypre_CSRMatrixJ(Ae) = mfem_hypre_TAlloc(HYPRE_Int, nnz);
377 hypre_CSRMatrixData(Ae) = mfem_hypre_TAlloc(HYPRE_Real, nnz);
378 hypre_CSRMatrixNumNonzeros(Ae) = nnz;
388 void hypre_CSRMatrixEliminateRowsCols(hypre_CSRMatrix *A,
390 HYPRE_Int nrows, HYPRE_Int *rows,
391 HYPRE_Int ncols, HYPRE_Int *cols,
392 int diag, HYPRE_Int* col_remap)
394 HYPRE_Int i, j, k, col;
395 HYPRE_Int A_beg, Ae_beg, A_end;
398 HYPRE_Int *A_i = hypre_CSRMatrixI(A);
399 HYPRE_Int *A_j = hypre_CSRMatrixJ(A);
400 HYPRE_Real *A_data = hypre_CSRMatrixData(A);
401 HYPRE_Int A_rows = hypre_CSRMatrixNumRows(A);
403 HYPRE_Int *Ae_i = hypre_CSRMatrixI(Ae);
404 HYPRE_Int *Ae_j = hypre_CSRMatrixJ(Ae);
405 HYPRE_Real *Ae_data = hypre_CSRMatrixData(Ae);
407 for (i = 0; i < A_rows; i++)
413 if (hypre_BinarySearch(rows, i, nrows) >= 0)
416 for (j = A_beg, k = Ae_beg; j < A_end; j++, k++)
419 Ae_j[k] = col_remap ? col_remap[col] : col;
420 a = (diag && col == i) ? 1.0 : 0.0;
421 Ae_data[k] = A_data[j] -
a;
428 for (j = A_beg, k = Ae_beg; j < A_end; j++)
431 if (hypre_BinarySearch(cols, col, ncols) >= 0)
433 Ae_j[k] = col_remap ? col_remap[col] : col;
434 Ae_data[k] = A_data[j];
446 void hypre_CSRMatrixEliminateRows(hypre_CSRMatrix *A,
447 HYPRE_Int nrows,
const HYPRE_Int *rows)
449 HYPRE_Int irow, i, j;
450 HYPRE_Int A_beg, A_end;
452 HYPRE_Int *A_i = hypre_CSRMatrixI(A);
453 HYPRE_Real *A_data = hypre_CSRMatrixData(A);
455 for (i = 0; i < nrows; i++)
461 for (j = A_beg; j < A_end; j++)
484 void hypre_ParCSRMatrixEliminateAAe(hypre_ParCSRMatrix *A,
485 hypre_ParCSRMatrix **Ae,
486 HYPRE_Int num_rowscols_to_elim,
487 HYPRE_Int *rowscols_to_elim,
492 hypre_CSRMatrix *A_diag = hypre_ParCSRMatrixDiag(A);
493 hypre_CSRMatrix *A_offd = hypre_ParCSRMatrixOffd(A);
494 HYPRE_Int A_diag_ncols = hypre_CSRMatrixNumCols(A_diag);
495 HYPRE_Int A_offd_ncols = hypre_CSRMatrixNumCols(A_offd);
497 *Ae = hypre_ParCSRMatrixCreate(hypre_ParCSRMatrixComm(A),
498 hypre_ParCSRMatrixGlobalNumRows(A),
499 hypre_ParCSRMatrixGlobalNumCols(A),
500 hypre_ParCSRMatrixRowStarts(A),
501 hypre_ParCSRMatrixColStarts(A),
504 hypre_ParCSRMatrixSetRowStartsOwner(*Ae, 0);
505 hypre_ParCSRMatrixSetColStartsOwner(*Ae, 0);
507 hypre_CSRMatrix *Ae_diag = hypre_ParCSRMatrixDiag(*Ae);
508 hypre_CSRMatrix *Ae_offd = hypre_ParCSRMatrixOffd(*Ae);
509 HYPRE_Int Ae_offd_ncols;
511 HYPRE_Int num_offd_cols_to_elim;
512 HYPRE_Int *offd_cols_to_elim;
514 HYPRE_Int *A_col_map_offd = hypre_ParCSRMatrixColMapOffd(A);
515 HYPRE_Int *Ae_col_map_offd;
518 HYPRE_Int *col_remap;
522 hypre_ParCSRCommHandle *comm_handle;
523 hypre_ParCSRCommPkg *comm_pkg;
524 HYPRE_Int num_sends, *int_buf_data;
525 HYPRE_Int
index, start;
527 HYPRE_Int *eliminate_diag_col = mfem_hypre_CTAlloc(HYPRE_Int, A_diag_ncols);
528 HYPRE_Int *eliminate_offd_col = mfem_hypre_CTAlloc(HYPRE_Int, A_offd_ncols);
531 comm_pkg = hypre_ParCSRMatrixCommPkg(A);
534 hypre_MatvecCommPkgCreate(A);
535 comm_pkg = hypre_ParCSRMatrixCommPkg(A);
539 for (i = 0; i < A_diag_ncols; i++)
541 eliminate_diag_col[i] = 0;
543 for (i = 0; i < num_rowscols_to_elim; i++)
545 eliminate_diag_col[rowscols_to_elim[i]] = 1;
550 num_sends = hypre_ParCSRCommPkgNumSends(comm_pkg);
551 int_buf_data = mfem_hypre_CTAlloc(
553 hypre_ParCSRCommPkgSendMapStart(comm_pkg, num_sends));
555 for (i = 0; i < num_sends; i++)
557 start = hypre_ParCSRCommPkgSendMapStart(comm_pkg, i);
558 for (j = start; j < hypre_ParCSRCommPkgSendMapStart(comm_pkg, i+1); j++)
560 k = hypre_ParCSRCommPkgSendMapElmt(comm_pkg, j);
561 int_buf_data[index++] = eliminate_diag_col[k];
564 comm_handle = hypre_ParCSRCommHandleCreate(11, comm_pkg,
565 int_buf_data, eliminate_offd_col);
570 hypre_CSRMatrixElimCreate(A_diag, Ae_diag,
572 num_rowscols_to_elim, rowscols_to_elim,
575 hypre_CSRMatrixEliminateRowsCols(A_diag, Ae_diag,
577 num_rowscols_to_elim, rowscols_to_elim,
582 hypre_CSRMatrixElimCreate(A_diag, Ae_diag,
583 num_rowscols_to_elim, rowscols_to_elim,
584 num_rowscols_to_elim, rowscols_to_elim,
587 hypre_CSRMatrixEliminateRowsCols(A_diag, Ae_diag,
588 num_rowscols_to_elim, rowscols_to_elim,
589 num_rowscols_to_elim, rowscols_to_elim,
593 hypre_CSRMatrixReorder(Ae_diag);
596 hypre_ParCSRCommHandleDestroy(comm_handle);
599 num_offd_cols_to_elim = 0;
600 for (i = 0; i < A_offd_ncols; i++)
602 if (eliminate_offd_col[i]) { num_offd_cols_to_elim++; }
605 offd_cols_to_elim = mfem_hypre_CTAlloc(HYPRE_Int, num_offd_cols_to_elim);
608 num_offd_cols_to_elim = 0;
609 for (i = 0; i < A_offd_ncols; i++)
611 if (eliminate_offd_col[i])
613 offd_cols_to_elim[num_offd_cols_to_elim++] = i;
617 mfem_hypre_TFree(int_buf_data);
618 mfem_hypre_TFree(eliminate_offd_col);
619 mfem_hypre_TFree(eliminate_diag_col);
623 col_mark = mfem_hypre_CTAlloc(HYPRE_Int, A_offd_ncols);
624 col_remap = mfem_hypre_CTAlloc(HYPRE_Int, A_offd_ncols);
628 hypre_CSRMatrixElimCreate(A_offd, Ae_offd,
630 num_offd_cols_to_elim, offd_cols_to_elim,
633 for (i = k = 0; i < A_offd_ncols; i++)
635 if (col_mark[i]) { col_remap[i] = k++; }
638 hypre_CSRMatrixEliminateRowsCols(A_offd, Ae_offd,
640 num_offd_cols_to_elim, offd_cols_to_elim,
645 hypre_CSRMatrixElimCreate(A_offd, Ae_offd,
646 num_rowscols_to_elim, rowscols_to_elim,
647 num_offd_cols_to_elim, offd_cols_to_elim,
650 for (i = k = 0; i < A_offd_ncols; i++)
652 if (col_mark[i]) { col_remap[i] = k++; }
655 hypre_CSRMatrixEliminateRowsCols(A_offd, Ae_offd,
656 num_rowscols_to_elim, rowscols_to_elim,
657 num_offd_cols_to_elim, offd_cols_to_elim,
663 for (i = 0; i < A_offd_ncols; i++)
665 if (col_mark[i]) { Ae_offd_ncols++; }
668 Ae_col_map_offd = mfem_hypre_CTAlloc(HYPRE_Int, Ae_offd_ncols);
671 for (i = 0; i < A_offd_ncols; i++)
675 Ae_col_map_offd[Ae_offd_ncols++] = A_col_map_offd[i];
679 hypre_ParCSRMatrixColMapOffd(*Ae) = Ae_col_map_offd;
680 hypre_CSRMatrixNumCols(Ae_offd) = Ae_offd_ncols;
682 mfem_hypre_TFree(col_remap);
683 mfem_hypre_TFree(col_mark);
684 mfem_hypre_TFree(offd_cols_to_elim);
686 hypre_ParCSRMatrixSetNumNonzeros(*Ae);
687 hypre_MatvecCommPkgCreate(*Ae);
692 void hypre_ParCSRMatrixEliminateRows(hypre_ParCSRMatrix *A,
693 HYPRE_Int num_rows_to_elim,
694 const HYPRE_Int *rows_to_elim)
696 hypre_CSRMatrix *A_diag = hypre_ParCSRMatrixDiag(A);
697 hypre_CSRMatrix *A_offd = hypre_ParCSRMatrixOffd(A);
698 hypre_CSRMatrixEliminateRows(A_diag, num_rows_to_elim, rows_to_elim);
699 hypre_CSRMatrixEliminateRows(A_offd, num_rows_to_elim, rows_to_elim);
707 void hypre_CSRMatrixSplit(hypre_CSRMatrix *A,
708 HYPRE_Int nr, HYPRE_Int nc,
709 HYPRE_Int *row_block_num, HYPRE_Int *col_block_num,
710 hypre_CSRMatrix **blocks)
712 HYPRE_Int i, j, k, bi, bj;
714 HYPRE_Int* A_i = hypre_CSRMatrixI(A);
715 HYPRE_Int* A_j = hypre_CSRMatrixJ(A);
716 HYPRE_Complex* A_data = hypre_CSRMatrixData(A);
718 HYPRE_Int A_rows = hypre_CSRMatrixNumRows(A);
719 HYPRE_Int A_cols = hypre_CSRMatrixNumCols(A);
721 HYPRE_Int *num_rows = mfem_hypre_CTAlloc(HYPRE_Int, nr);
722 HYPRE_Int *num_cols = mfem_hypre_CTAlloc(HYPRE_Int, nc);
724 HYPRE_Int *block_row = mfem_hypre_TAlloc(HYPRE_Int, A_rows);
725 HYPRE_Int *block_col = mfem_hypre_TAlloc(HYPRE_Int, A_cols);
727 for (i = 0; i < A_rows; i++)
729 block_row[i] = num_rows[row_block_num[i]]++;
731 for (j = 0; j < A_cols; j++)
733 block_col[j] = num_cols[col_block_num[j]]++;
737 for (i = 0; i < nr; i++)
739 for (j = 0; j < nc; j++)
741 hypre_CSRMatrix *B = hypre_CSRMatrixCreate(num_rows[i], num_cols[j], 0);
742 hypre_CSRMatrixI(B) = mfem_hypre_CTAlloc(HYPRE_Int, num_rows[i] + 1);
743 blocks[i*nc + j] = B;
748 for (i = 0; i < A_rows; i++)
750 bi = row_block_num[i];
751 for (j = A_i[i]; j < A_i[i+1]; j++)
753 bj = col_block_num[A_j[j]];
754 hypre_CSRMatrix *B = blocks[bi*nc + bj];
755 hypre_CSRMatrixI(B)[block_row[i] + 1]++;
760 for (k = 0; k < nr*nc; k++)
762 hypre_CSRMatrix *B = blocks[k];
763 HYPRE_Int* B_i = hypre_CSRMatrixI(B);
765 HYPRE_Int nnz = 0, rs;
766 for (
int k = 1; k <= hypre_CSRMatrixNumRows(B); k++)
768 rs = B_i[k], B_i[k] = nnz, nnz += rs;
771 hypre_CSRMatrixJ(B) = mfem_hypre_TAlloc(HYPRE_Int, nnz);
772 hypre_CSRMatrixData(B) = mfem_hypre_TAlloc(HYPRE_Complex, nnz);
773 hypre_CSRMatrixNumNonzeros(B) = nnz;
777 for (i = 0; i < A_rows; i++)
779 bi = row_block_num[i];
780 for (j = A_i[i]; j < A_i[i+1]; j++)
783 bj = col_block_num[k];
784 hypre_CSRMatrix *B = blocks[bi*nc + bj];
785 HYPRE_Int *bii = hypre_CSRMatrixI(B) + block_row[i] + 1;
786 hypre_CSRMatrixJ(B)[*bii] = block_col[k];
787 hypre_CSRMatrixData(B)[*bii] = A_data[j];
792 mfem_hypre_TFree(block_col);
793 mfem_hypre_TFree(block_row);
795 mfem_hypre_TFree(num_cols);
796 mfem_hypre_TFree(num_rows);
800 void hypre_ParCSRMatrixSplit(hypre_ParCSRMatrix *A,
801 HYPRE_Int nr, HYPRE_Int nc,
802 hypre_ParCSRMatrix **blocks,
803 int interleaved_rows,
int interleaved_cols)
807 MPI_Comm comm = hypre_ParCSRMatrixComm(A);
809 hypre_CSRMatrix *Adiag = hypre_ParCSRMatrixDiag(A);
810 hypre_CSRMatrix *Aoffd = hypre_ParCSRMatrixOffd(A);
812 HYPRE_Int global_rows = hypre_ParCSRMatrixGlobalNumRows(A);
813 HYPRE_Int global_cols = hypre_ParCSRMatrixGlobalNumCols(A);
815 HYPRE_Int local_rows = hypre_CSRMatrixNumRows(Adiag);
816 HYPRE_Int local_cols = hypre_CSRMatrixNumCols(Adiag);
817 HYPRE_Int offd_cols = hypre_CSRMatrixNumCols(Aoffd);
819 hypre_assert(local_rows % nr == 0 && local_cols % nc == 0);
820 hypre_assert(global_rows % nr == 0 && global_cols % nc == 0);
822 HYPRE_Int block_rows = local_rows / nr;
823 HYPRE_Int block_cols = local_cols / nc;
824 HYPRE_Int num_blocks = nr * nc;
827 HYPRE_Int *row_block_num = mfem_hypre_TAlloc(HYPRE_Int, local_rows);
828 HYPRE_Int *col_block_num = mfem_hypre_TAlloc(HYPRE_Int, local_cols);
830 for (i = 0; i < local_rows; i++)
832 row_block_num[i] = interleaved_rows ? (i % nr) : (i / block_rows);
834 for (i = 0; i < local_cols; i++)
836 col_block_num[i] = interleaved_cols ? (i % nc) : (i / block_cols);
840 HYPRE_Int* offd_col_block_num = mfem_hypre_TAlloc(HYPRE_Int, offd_cols);
841 hypre_ParCSRCommHandle *comm_handle;
842 HYPRE_Int *int_buf_data;
845 hypre_ParCSRCommPkg *comm_pkg = hypre_ParCSRMatrixCommPkg(A);
848 hypre_MatvecCommPkgCreate(A);
849 comm_pkg = hypre_ParCSRMatrixCommPkg(A);
853 HYPRE_Int *count = mfem_hypre_CTAlloc(HYPRE_Int, nc);
854 HYPRE_Int *block_global_col = mfem_hypre_TAlloc(HYPRE_Int, local_cols);
855 HYPRE_Int first_col = hypre_ParCSRMatrixFirstColDiag(A) / nc;
856 for (i = 0; i < local_cols; i++)
858 block_global_col[i] = first_col + count[col_block_num[i]]++;
860 mfem_hypre_TFree(count);
863 HYPRE_Int num_sends = hypre_ParCSRCommPkgNumSends(comm_pkg);
864 int_buf_data = mfem_hypre_CTAlloc(
866 hypre_ParCSRCommPkgSendMapStart(comm_pkg, num_sends));
867 HYPRE_Int start, index = 0;
868 for (i = 0; i < num_sends; i++)
870 start = hypre_ParCSRCommPkgSendMapStart(comm_pkg, i);
871 for (j = start; j < hypre_ParCSRCommPkgSendMapStart(comm_pkg, i+1); j++)
873 k = hypre_ParCSRCommPkgSendMapElmt(comm_pkg, j);
874 int_buf_data[index++] = col_block_num[k] + nc*block_global_col[k];
877 mfem_hypre_TFree(block_global_col);
879 comm_handle = hypre_ParCSRCommHandleCreate(11, comm_pkg, int_buf_data,
884 HYPRE_Int num_procs = 1;
885 if (!hypre_ParCSRMatrixAssumedPartition(A))
887 hypre_MPI_Comm_size(comm, &num_procs);
890 HYPRE_Int *row_starts = mfem_hypre_TAlloc(HYPRE_Int, num_procs+1);
891 HYPRE_Int *col_starts = mfem_hypre_TAlloc(HYPRE_Int, num_procs+1);
892 for (i = 0; i <= num_procs; i++)
894 row_starts[i] = hypre_ParCSRMatrixRowStarts(A)[i] / nr;
895 col_starts[i] = hypre_ParCSRMatrixColStarts(A)[i] / nc;
898 for (i = 0; i < num_blocks; i++)
900 blocks[i] = hypre_ParCSRMatrixCreate(comm,
901 global_rows/nr, global_cols/nc,
902 row_starts, col_starts, 0, 0, 0);
906 hypre_CSRMatrix **csr_blocks = mfem_hypre_TAlloc(hypre_CSRMatrix*, nr*nc);
907 hypre_CSRMatrixSplit(Adiag, nr, nc, row_block_num, col_block_num,
910 for (i = 0; i < num_blocks; i++)
912 mfem_hypre_TFree(hypre_ParCSRMatrixDiag(blocks[i]));
913 hypre_ParCSRMatrixDiag(blocks[i]) = csr_blocks[i];
917 hypre_ParCSRCommHandleDestroy(comm_handle);
918 mfem_hypre_TFree(int_buf_data);
921 HYPRE_Int* offd_global_col = mfem_hypre_TAlloc(HYPRE_Int, offd_cols);
922 for (i = 0; i < offd_cols; i++)
924 offd_global_col[i] = offd_col_block_num[i] / nc;
925 offd_col_block_num[i] %= nc;
929 hypre_CSRMatrixSplit(Aoffd, nr, nc, row_block_num, offd_col_block_num,
932 for (i = 0; i < num_blocks; i++)
934 mfem_hypre_TFree(hypre_ParCSRMatrixOffd(blocks[i]));
935 hypre_ParCSRMatrixOffd(blocks[i]) = csr_blocks[i];
938 mfem_hypre_TFree(csr_blocks);
939 mfem_hypre_TFree(col_block_num);
940 mfem_hypre_TFree(row_block_num);
943 for (
int bi = 0; bi < nr; bi++)
945 for (
int bj = 0; bj < nc; bj++)
947 hypre_ParCSRMatrix *block = blocks[bi*nc + bj];
948 hypre_CSRMatrix *block_offd = hypre_ParCSRMatrixOffd(block);
949 HYPRE_Int block_offd_cols = hypre_CSRMatrixNumCols(block_offd);
951 HYPRE_Int *block_col_map = mfem_hypre_TAlloc(HYPRE_Int,
953 for (i = j = 0; i < offd_cols; i++)
955 HYPRE_Int bn = offd_col_block_num[i];
956 if (bn == bj) { block_col_map[j++] = offd_global_col[i]; }
958 hypre_assert(j == block_offd_cols);
960 hypre_ParCSRMatrixColMapOffd(block) = block_col_map;
964 mfem_hypre_TFree(offd_global_col);
965 mfem_hypre_TFree(offd_col_block_num);
968 for (i = 0; i < num_blocks; i++)
970 hypre_ParCSRMatrixSetNumNonzeros(blocks[i]);
971 hypre_MatvecCommPkgCreate(blocks[i]);
973 hypre_ParCSRMatrixOwnsData(blocks[i]) = 1;
976 hypre_ParCSRMatrixOwnsRowStarts(blocks[i]) = !i;
977 hypre_ParCSRMatrixOwnsColStarts(blocks[i]) = !i;
982 void hypre_CSRMatrixAbsMatvec(hypre_CSRMatrix *A,
988 HYPRE_Real *A_data = hypre_CSRMatrixData(A);
989 HYPRE_Int *A_i = hypre_CSRMatrixI(A);
990 HYPRE_Int *A_j = hypre_CSRMatrixJ(A);
991 HYPRE_Int num_rows = hypre_CSRMatrixNumRows(A);
993 HYPRE_Int *A_rownnz = hypre_CSRMatrixRownnz(A);
994 HYPRE_Int num_rownnz = hypre_CSRMatrixNumRownnz(A);
996 HYPRE_Real *x_data = x;
997 HYPRE_Real *y_data = y;
999 HYPRE_Real temp, tempx;
1005 HYPRE_Real xpar=0.7;
1013 for (i = 0; i < num_rows; i++)
1024 temp = beta /
alpha;
1030 for (i = 0; i < num_rows; i++)
1037 for (i = 0; i < num_rows; i++)
1051 if (num_rownnz < xpar*(num_rows))
1053 for (i = 0; i < num_rownnz; i++)
1058 for (jj = A_i[m]; jj < A_i[m+1]; jj++)
1060 tempx += std::abs(A_data[jj])*x_data[A_j[jj]];
1067 for (i = 0; i < num_rows; i++)
1070 for (jj = A_i[i]; jj < A_i[i+1]; jj++)
1072 tempx += std::abs(A_data[jj])*x_data[A_j[jj]];
1084 for (i = 0; i < num_rows; i++)
1093 void hypre_CSRMatrixAbsMatvecT(hypre_CSRMatrix *A,
1099 HYPRE_Real *A_data = hypre_CSRMatrixData(A);
1100 HYPRE_Int *A_i = hypre_CSRMatrixI(A);
1101 HYPRE_Int *A_j = hypre_CSRMatrixJ(A);
1102 HYPRE_Int num_rows = hypre_CSRMatrixNumRows(A);
1103 HYPRE_Int num_cols = hypre_CSRMatrixNumCols(A);
1105 HYPRE_Real *x_data = x;
1106 HYPRE_Real *y_data = y;
1114 for (i = 0; i < num_cols; i++)
1125 temp = beta /
alpha;
1131 for (i = 0; i < num_cols; i++)
1138 for (i = 0; i < num_cols; i++)
1149 for (i = 0; i < num_rows; i++)
1151 for (jj = A_i[i]; jj < A_i[i+1]; jj++)
1154 y_data[j] += std::abs(A_data[jj]) * x_data[i];
1164 for (i = 0; i < num_cols; i++)
1172 void hypre_CSRMatrixBooleanMatvec(hypre_CSRMatrix *A,
1179 HYPRE_Int *A_i = hypre_CSRMatrixI(A);
1180 HYPRE_Int *A_j = hypre_CSRMatrixJ(A);
1181 HYPRE_Int num_rows = hypre_CSRMatrixNumRows(A);
1183 HYPRE_Int *A_rownnz = hypre_CSRMatrixRownnz(A);
1184 HYPRE_Int num_rownnz = hypre_CSRMatrixNumRownnz(A);
1186 HYPRE_Bool *x_data = x;
1187 HYPRE_Bool *y_data = y;
1189 HYPRE_Bool temp, tempx;
1195 HYPRE_Real xpar=0.7;
1203 #ifdef HYPRE_USING_OPENMP
1204 #pragma omp parallel for private(i) HYPRE_SMP_SCHEDULE
1206 for (i = 0; i < num_rows; i++)
1208 y_data[i] = y_data[i] && beta;
1219 #ifdef HYPRE_USING_OPENMP
1220 #pragma omp parallel for private(i) HYPRE_SMP_SCHEDULE
1222 for (i = 0; i < num_rows; i++)
1238 if (num_rownnz < xpar*(num_rows))
1240 #ifdef HYPRE_USING_OPENMP
1241 #pragma omp parallel for private(i,jj,m,tempx) HYPRE_SMP_SCHEDULE
1243 for (i = 0; i < num_rownnz; i++)
1248 for (jj = A_i[m]; jj < A_i[m+1]; jj++)
1251 tempx = tempx || x_data[A_j[jj]];
1253 y_data[m] = y_data[m] || tempx;
1258 #ifdef HYPRE_USING_OPENMP
1259 #pragma omp parallel for private(i,jj,temp) HYPRE_SMP_SCHEDULE
1261 for (i = 0; i < num_rows; i++)
1264 for (jj = A_i[i]; jj < A_i[i+1]; jj++)
1267 temp = temp || x_data[A_j[jj]];
1269 y_data[i] = y_data[i] || temp;
1280 void hypre_CSRMatrixBooleanMatvecT(hypre_CSRMatrix *A,
1287 HYPRE_Int *A_i = hypre_CSRMatrixI(A);
1288 HYPRE_Int *A_j = hypre_CSRMatrixJ(A);
1289 HYPRE_Int num_rows = hypre_CSRMatrixNumRows(A);
1290 HYPRE_Int num_cols = hypre_CSRMatrixNumCols(A);
1292 HYPRE_Bool *x_data = x;
1293 HYPRE_Bool *y_data = y;
1303 for (i = 0; i < num_cols; i++)
1327 for (i = 0; i < num_rows; i++)
1331 for (jj = A_i[i]; jj < A_i[i+1]; jj++)
1343 hypre_ParCSRCommHandle *
1344 hypre_ParCSRCommHandleCreate_bool(HYPRE_Int job,
1345 hypre_ParCSRCommPkg *comm_pkg,
1346 HYPRE_Bool *send_data,
1347 HYPRE_Bool *recv_data)
1349 HYPRE_Int num_sends = hypre_ParCSRCommPkgNumSends(comm_pkg);
1350 HYPRE_Int num_recvs = hypre_ParCSRCommPkgNumRecvs(comm_pkg);
1351 MPI_Comm comm = hypre_ParCSRCommPkgComm(comm_pkg);
1353 hypre_ParCSRCommHandle *comm_handle;
1354 HYPRE_Int num_requests;
1355 hypre_MPI_Request *requests;
1358 HYPRE_Int my_id, num_procs;
1359 HYPRE_Int ip, vec_start, vec_len;
1361 num_requests = num_sends + num_recvs;
1362 requests = mfem_hypre_CTAlloc(hypre_MPI_Request, num_requests);
1364 hypre_MPI_Comm_size(comm, &num_procs);
1365 hypre_MPI_Comm_rank(comm, &my_id);
1372 HYPRE_Bool *d_send_data = (HYPRE_Bool *) send_data;
1373 HYPRE_Bool *d_recv_data = (HYPRE_Bool *) recv_data;
1374 for (i = 0; i < num_recvs; i++)
1376 ip = hypre_ParCSRCommPkgRecvProc(comm_pkg, i);
1377 vec_start = hypre_ParCSRCommPkgRecvVecStart(comm_pkg, i);
1378 vec_len = hypre_ParCSRCommPkgRecvVecStart(comm_pkg, i+1)-vec_start;
1379 hypre_MPI_Irecv(&d_recv_data[vec_start], vec_len, HYPRE_MPI_BOOL,
1380 ip, 0, comm, &requests[j++]);
1382 for (i = 0; i < num_sends; i++)
1384 vec_start = hypre_ParCSRCommPkgSendMapStart(comm_pkg, i);
1385 vec_len = hypre_ParCSRCommPkgSendMapStart(comm_pkg, i+1)-vec_start;
1386 ip = hypre_ParCSRCommPkgSendProc(comm_pkg, i);
1387 hypre_MPI_Isend(&d_send_data[vec_start], vec_len, HYPRE_MPI_BOOL,
1388 ip, 0, comm, &requests[j++]);
1394 HYPRE_Bool *d_send_data = (HYPRE_Bool *) send_data;
1395 HYPRE_Bool *d_recv_data = (HYPRE_Bool *) recv_data;
1396 for (i = 0; i < num_sends; i++)
1398 vec_start = hypre_ParCSRCommPkgSendMapStart(comm_pkg, i);
1399 vec_len = hypre_ParCSRCommPkgSendMapStart(comm_pkg, i+1)-vec_start;
1400 ip = hypre_ParCSRCommPkgSendProc(comm_pkg, i);
1401 hypre_MPI_Irecv(&d_recv_data[vec_start], vec_len, HYPRE_MPI_BOOL,
1402 ip, 0, comm, &requests[j++]);
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_Isend(&d_send_data[vec_start], vec_len, HYPRE_MPI_BOOL,
1410 ip, 0, comm, &requests[j++]);
1419 comm_handle = mfem_hypre_CTAlloc(hypre_ParCSRCommHandle, 1);
1421 hypre_ParCSRCommHandleCommPkg(comm_handle) = comm_pkg;
1422 hypre_ParCSRCommHandleSendData(comm_handle) = send_data;
1423 hypre_ParCSRCommHandleRecvData(comm_handle) = recv_data;
1424 hypre_ParCSRCommHandleNumRequests(comm_handle) = num_requests;
1425 hypre_ParCSRCommHandleRequests(comm_handle) = requests;
1431 void hypre_ParCSRMatrixAbsMatvec(hypre_ParCSRMatrix *A,
1437 hypre_ParCSRCommHandle *comm_handle;
1438 hypre_ParCSRCommPkg *comm_pkg = hypre_ParCSRMatrixCommPkg(A);
1439 hypre_CSRMatrix *diag = hypre_ParCSRMatrixDiag(A);
1440 hypre_CSRMatrix *offd = hypre_ParCSRMatrixOffd(A);
1442 HYPRE_Int num_cols_offd = hypre_CSRMatrixNumCols(offd);
1443 HYPRE_Int num_sends, i, j,
index;
1445 HYPRE_Real *x_tmp, *x_buf;
1447 x_tmp = mfem_hypre_CTAlloc(HYPRE_Real, num_cols_offd);
1455 hypre_MatvecCommPkgCreate(A);
1456 comm_pkg = hypre_ParCSRMatrixCommPkg(A);
1459 num_sends = hypre_ParCSRCommPkgNumSends(comm_pkg);
1460 x_buf = mfem_hypre_CTAlloc(
1461 HYPRE_Real, hypre_ParCSRCommPkgSendMapStart(comm_pkg, num_sends));
1464 for (i = 0; i < num_sends; i++)
1466 j = hypre_ParCSRCommPkgSendMapStart(comm_pkg, i);
1467 for ( ; j < hypre_ParCSRCommPkgSendMapStart(comm_pkg, i+1); j++)
1469 x_buf[index++] = x[hypre_ParCSRCommPkgSendMapElmt(comm_pkg, j)];
1473 comm_handle = hypre_ParCSRCommHandleCreate(1, comm_pkg, x_buf, x_tmp);
1475 hypre_CSRMatrixAbsMatvec(diag, alpha, x, beta, y);
1477 hypre_ParCSRCommHandleDestroy(comm_handle);
1481 hypre_CSRMatrixAbsMatvec(offd, alpha, x_tmp, 1.0, y);
1484 mfem_hypre_TFree(x_buf);
1485 mfem_hypre_TFree(x_tmp);
1489 void hypre_ParCSRMatrixAbsMatvecT(hypre_ParCSRMatrix *A,
1495 hypre_ParCSRCommHandle *comm_handle;
1496 hypre_ParCSRCommPkg *comm_pkg = hypre_ParCSRMatrixCommPkg(A);
1497 hypre_CSRMatrix *diag = hypre_ParCSRMatrixDiag(A);
1498 hypre_CSRMatrix *offd = hypre_ParCSRMatrixOffd(A);
1502 HYPRE_Int num_cols_offd = hypre_CSRMatrixNumCols(offd);
1504 HYPRE_Int i, j, jj, end, num_sends;
1506 y_tmp = mfem_hypre_TAlloc(HYPRE_Real, num_cols_offd);
1514 hypre_MatvecCommPkgCreate(A);
1515 comm_pkg = hypre_ParCSRMatrixCommPkg(A);
1518 num_sends = hypre_ParCSRCommPkgNumSends(comm_pkg);
1519 y_buf = mfem_hypre_CTAlloc(
1520 HYPRE_Real, hypre_ParCSRCommPkgSendMapStart(comm_pkg, num_sends));
1524 #if MFEM_HYPRE_VERSION >= 21100
1528 hypre_CSRMatrixAbsMatvec(A->offdT, alpha, x, 0., y_tmp);
1533 hypre_CSRMatrixAbsMatvecT(offd, alpha, x, 0., y_tmp);
1537 comm_handle = hypre_ParCSRCommHandleCreate(2, comm_pkg, y_tmp, y_buf);
1539 #if MFEM_HYPRE_VERSION >= 21100
1543 hypre_CSRMatrixAbsMatvec(A->diagT, alpha, x, beta, y);
1548 hypre_CSRMatrixAbsMatvecT(diag, alpha, x, beta, y);
1551 hypre_ParCSRCommHandleDestroy(comm_handle);
1553 for (i = 0; i < num_sends; i++)
1555 end = hypre_ParCSRCommPkgSendMapStart(comm_pkg, i+1);
1556 for (j = hypre_ParCSRCommPkgSendMapStart(comm_pkg, i); j < end; j++)
1558 jj = hypre_ParCSRCommPkgSendMapElmt(comm_pkg, j);
1563 mfem_hypre_TFree(y_buf);
1564 mfem_hypre_TFree(y_tmp);
1568 void hypre_ParCSRMatrixBooleanMatvec(hypre_ParCSRMatrix *A,
1574 hypre_ParCSRCommHandle *comm_handle;
1575 hypre_ParCSRCommPkg *comm_pkg = hypre_ParCSRMatrixCommPkg(A);
1576 hypre_CSRMatrix *diag = hypre_ParCSRMatrixDiag(A);
1577 hypre_CSRMatrix *offd = hypre_ParCSRMatrixOffd(A);
1579 HYPRE_Int num_cols_offd = hypre_CSRMatrixNumCols(offd);
1580 HYPRE_Int num_sends, i, j,
index;
1582 HYPRE_Bool *x_tmp, *x_buf;
1584 x_tmp = mfem_hypre_CTAlloc(HYPRE_Bool, num_cols_offd);
1592 hypre_MatvecCommPkgCreate(A);
1593 comm_pkg = hypre_ParCSRMatrixCommPkg(A);
1596 num_sends = hypre_ParCSRCommPkgNumSends(comm_pkg);
1597 x_buf = mfem_hypre_CTAlloc(
1598 HYPRE_Bool, hypre_ParCSRCommPkgSendMapStart(comm_pkg, num_sends));
1601 for (i = 0; i < num_sends; i++)
1603 j = hypre_ParCSRCommPkgSendMapStart(comm_pkg, i);
1604 for ( ; j < hypre_ParCSRCommPkgSendMapStart(comm_pkg, i+1); j++)
1606 x_buf[index++] = x[hypre_ParCSRCommPkgSendMapElmt(comm_pkg, j)];
1610 comm_handle = hypre_ParCSRCommHandleCreate_bool(1, comm_pkg, x_buf, x_tmp);
1612 hypre_CSRMatrixBooleanMatvec(diag, alpha, x, beta, y);
1614 hypre_ParCSRCommHandleDestroy(comm_handle);
1618 hypre_CSRMatrixBooleanMatvec(offd, alpha, x_tmp, 1, y);
1621 mfem_hypre_TFree(x_buf);
1622 mfem_hypre_TFree(x_tmp);
1626 void hypre_ParCSRMatrixBooleanMatvecT(hypre_ParCSRMatrix *A,
1632 hypre_ParCSRCommHandle *comm_handle;
1633 hypre_ParCSRCommPkg *comm_pkg = hypre_ParCSRMatrixCommPkg(A);
1634 hypre_CSRMatrix *diag = hypre_ParCSRMatrixDiag(A);
1635 hypre_CSRMatrix *offd = hypre_ParCSRMatrixOffd(A);
1639 HYPRE_Int num_cols_offd = hypre_CSRMatrixNumCols(offd);
1641 HYPRE_Int i, j, jj, end, num_sends;
1643 y_tmp = mfem_hypre_TAlloc(HYPRE_Bool, num_cols_offd);
1651 hypre_MatvecCommPkgCreate(A);
1652 comm_pkg = hypre_ParCSRMatrixCommPkg(A);
1655 num_sends = hypre_ParCSRCommPkgNumSends(comm_pkg);
1656 y_buf = mfem_hypre_CTAlloc(
1657 HYPRE_Bool, hypre_ParCSRCommPkgSendMapStart(comm_pkg, num_sends));
1661 #if MFEM_HYPRE_VERSION >= 21100
1665 hypre_CSRMatrixBooleanMatvec(A->offdT, alpha, x, 0, y_tmp);
1670 hypre_CSRMatrixBooleanMatvecT(offd, alpha, x, 0, y_tmp);
1674 comm_handle = hypre_ParCSRCommHandleCreate_bool(2, comm_pkg, y_tmp, y_buf);
1676 #if MFEM_HYPRE_VERSION >= 21100
1680 hypre_CSRMatrixBooleanMatvec(A->diagT, alpha, x, beta, y);
1685 hypre_CSRMatrixBooleanMatvecT(diag, alpha, x, beta, y);
1688 hypre_ParCSRCommHandleDestroy(comm_handle);
1690 for (i = 0; i < num_sends; i++)
1692 end = hypre_ParCSRCommPkgSendMapStart(comm_pkg, i+1);
1693 for (j = hypre_ParCSRCommPkgSendMapStart(comm_pkg, i); j < end; j++)
1695 jj = hypre_ParCSRCommPkgSendMapElmt(comm_pkg, j);
1696 y[jj] = y[jj] || y_buf[j];
1700 mfem_hypre_TFree(y_buf);
1701 mfem_hypre_TFree(y_tmp);
1705 hypre_CSRMatrixSum(hypre_CSRMatrix *A,
1709 HYPRE_Complex *A_data = hypre_CSRMatrixData(A);
1710 HYPRE_Int *A_i = hypre_CSRMatrixI(A);
1711 HYPRE_Int *A_j = hypre_CSRMatrixJ(A);
1712 HYPRE_Int nrows_A = hypre_CSRMatrixNumRows(A);
1713 HYPRE_Int ncols_A = hypre_CSRMatrixNumCols(A);
1714 HYPRE_Complex *B_data = hypre_CSRMatrixData(B);
1715 HYPRE_Int *B_i = hypre_CSRMatrixI(B);
1716 HYPRE_Int *B_j = hypre_CSRMatrixJ(B);
1717 HYPRE_Int nrows_B = hypre_CSRMatrixNumRows(B);
1718 HYPRE_Int ncols_B = hypre_CSRMatrixNumCols(B);
1720 HYPRE_Int ia, j, pos;
1723 if (nrows_A != nrows_B || ncols_A != ncols_B)
1728 marker = mfem_hypre_CTAlloc(HYPRE_Int, ncols_A);
1729 for (ia = 0; ia < ncols_A; ia++)
1734 for (ia = 0; ia < nrows_A; ia++)
1736 for (j = A_i[ia]; j < A_i[ia+1]; j++)
1741 for (j = B_i[ia]; j < B_i[ia+1]; j++)
1743 pos = marker[B_j[j]];
1748 A_data[pos] += beta * B_data[j];
1752 mfem_hypre_TFree(marker);
1756 hypre_ParCSRMatrix *
1757 hypre_ParCSRMatrixAdd(hypre_ParCSRMatrix *A,
1758 hypre_ParCSRMatrix *B)
1760 MPI_Comm comm = hypre_ParCSRMatrixComm(A);
1761 hypre_CSRMatrix *A_diag = hypre_ParCSRMatrixDiag(A);
1762 hypre_CSRMatrix *A_offd = hypre_ParCSRMatrixOffd(A);
1763 HYPRE_Int *A_cmap = hypre_ParCSRMatrixColMapOffd(A);
1764 HYPRE_Int A_cmap_size = hypre_CSRMatrixNumCols(A_offd);
1765 hypre_CSRMatrix *B_diag = hypre_ParCSRMatrixDiag(B);
1766 hypre_CSRMatrix *B_offd = hypre_ParCSRMatrixOffd(B);
1767 HYPRE_Int *B_cmap = hypre_ParCSRMatrixColMapOffd(B);
1768 HYPRE_Int B_cmap_size = hypre_CSRMatrixNumCols(B_offd);
1769 hypre_ParCSRMatrix *C;
1770 hypre_CSRMatrix *C_diag;
1771 hypre_CSRMatrix *C_offd;
1774 HYPRE_Int cmap_differ;
1778 if (A_cmap_size != B_cmap_size)
1784 for (im = 0; im < A_cmap_size; im++)
1786 if (A_cmap[im] != B_cmap[im])
1794 if ( cmap_differ == 0 )
1801 C_diag = hypre_CSRMatrixAdd(A_diag, B_diag);
1806 C_offd = hypre_CSRMatrixAdd(A_offd, B_offd);
1809 hypre_CSRMatrixDestroy(C_diag);
1813 C_cmap = mfem_hypre_TAlloc(HYPRE_Int, A_cmap_size);
1814 for (im = 0; im < A_cmap_size; im++)
1816 C_cmap[im] = A_cmap[im];
1819 C = hypre_ParCSRMatrixCreate(comm,
1820 hypre_ParCSRMatrixGlobalNumRows(A),
1821 hypre_ParCSRMatrixGlobalNumCols(A),
1822 hypre_ParCSRMatrixRowStarts(A),
1823 hypre_ParCSRMatrixColStarts(A),
1824 hypre_CSRMatrixNumCols(C_offd),
1825 hypre_CSRMatrixNumNonzeros(C_diag),
1826 hypre_CSRMatrixNumNonzeros(C_offd));
1830 hypre_CSRMatrixDestroy(hypre_ParCSRMatrixDiag(C));
1831 hypre_CSRMatrixDestroy(hypre_ParCSRMatrixOffd(C));
1832 hypre_ParCSRMatrixDiag(C) = C_diag;
1833 hypre_ParCSRMatrixOffd(C) = C_offd;
1835 hypre_ParCSRMatrixColMapOffd(C) = C_cmap;
1843 hypre_CSRMatrix * csr_A;
1844 hypre_CSRMatrix * csr_B;
1845 hypre_CSRMatrix * csr_C_temp;
1848 csr_A = hypre_MergeDiagAndOffd(A);
1851 csr_B = hypre_MergeDiagAndOffd(B);
1854 csr_C_temp = hypre_CSRMatrixAdd(csr_A,csr_B);
1857 ierr += hypre_CSRMatrixDestroy(csr_A);
1858 ierr += hypre_CSRMatrixDestroy(csr_B);
1861 C = hypre_ParCSRMatrixCreate(hypre_ParCSRMatrixComm(A),
1862 hypre_ParCSRMatrixGlobalNumRows(A),
1863 hypre_ParCSRMatrixGlobalNumCols(A),
1864 hypre_ParCSRMatrixRowStarts(A),
1865 hypre_ParCSRMatrixColStarts(A),
1872 ierr += GenerateDiagAndOffd(csr_C_temp, C,
1873 hypre_ParCSRMatrixFirstColDiag(A),
1874 hypre_ParCSRMatrixLastColDiag(A));
1877 ierr += hypre_CSRMatrixDestroy(csr_C_temp);
1879 MFEM_VERIFY(ierr == 0,
"");
1885 hypre_CSRMatrixReorder(hypre_ParCSRMatrixDiag(C));
1888 hypre_ParCSRMatrixSetDataOwner(C, 1);
1890 hypre_ParCSRMatrixSetRowStartsOwner(C, 0);
1891 hypre_ParCSRMatrixSetColStartsOwner(C, 0);
1897 hypre_ParCSRMatrixSum(hypre_ParCSRMatrix *A,
1899 hypre_ParCSRMatrix *B)
1901 hypre_CSRMatrix *A_diag = hypre_ParCSRMatrixDiag(A);
1902 hypre_CSRMatrix *A_offd = hypre_ParCSRMatrixOffd(A);
1903 hypre_CSRMatrix *B_diag = hypre_ParCSRMatrixDiag(B);
1904 hypre_CSRMatrix *B_offd = hypre_ParCSRMatrixOffd(B);
1905 HYPRE_Int ncols_B_offd = hypre_CSRMatrixNumCols(B_offd);
1908 error = hypre_CSRMatrixSum(A_diag, beta, B_diag);
1909 if (ncols_B_offd > 0)
1911 error = error ? error : hypre_CSRMatrixSum(A_offd, beta, B_offd);
1918 hypre_CSRMatrixSetConstantValues(hypre_CSRMatrix *A,
1919 HYPRE_Complex value)
1921 HYPRE_Complex *A_data = hypre_CSRMatrixData(A);
1922 HYPRE_Int A_nnz = hypre_CSRMatrixNumNonzeros(A);
1925 for (ia = 0; ia < A_nnz; ia++)
1934 hypre_ParCSRMatrixSetConstantValues(hypre_ParCSRMatrix *A,
1935 HYPRE_Complex value)
1937 hypre_CSRMatrixSetConstantValues(hypre_ParCSRMatrixDiag(A), value);
1938 hypre_CSRMatrixSetConstantValues(hypre_ParCSRMatrixOffd(A), value);
1947 #endif // MFEM_USE_MPI
int index(int i, int j, int nx, int ny)