📄 dutil.c.bak
字号:
/* * -- Distributed SuperLU routine (version 2.0) -- * Lawrence Berkeley National Lab, Univ. of California Berkeley. * March 15, 2003 * *//* Copyright (c) 1994 by Xerox Corporation. All rights reserved. THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED OR IMPLIED. ANY USE IS AT YOUR OWN RISK. Permission is hereby granted to use or copy this program for any purpose, provided the above notices are retained on all copies. Permission to modify the code and to distribute modified code is granted, provided the above notices are retained, and a notice that the code was modified is included with the above copyright notice.*/#include <math.h>#include "superlu_ddefs.h"voiddCreate_CompCol_Matrix_dist(SuperMatrix *A, int_t m, int_t n, int_t nnz, double *nzval, int_t *rowind, int_t *colptr, Stype_t stype, Dtype_t dtype, Mtype_t mtype){ NCformat *Astore; A->Stype = stype; A->Dtype = dtype; A->Mtype = mtype; A->nrow = m; A->ncol = n; A->Store = (void *) SUPERLU_MALLOC( sizeof(NCformat) ); if ( !(A->Store) ) ABORT("SUPERLU_MALLOC fails for A->Store"); Astore = (NCformat *) A->Store; Astore->nnz = nnz; Astore->nzval = nzval; Astore->rowind = rowind; Astore->colptr = colptr;}voiddCreate_CompRowLoc_Matrix_dist(SuperMatrix *A, int_t m, int_t n, int_t nnz_loc, int_t m_loc, int_t fst_row, double *nzval, int_t *colind, int_t *rowptr, Stype_t stype, Dtype_t dtype, Mtype_t mtype){ NRformat_loc *Astore; A->Stype = stype; A->Dtype = dtype; A->Mtype = mtype; A->nrow = m; A->ncol = n; A->Store = (void *) SUPERLU_MALLOC( sizeof(NRformat_loc) ); if ( !(A->Store) ) ABORT("SUPERLU_MALLOC fails for A->Store"); Astore = (NRformat_loc *) A->Store; Astore->nnz_loc = nnz_loc; Astore->fst_row = fst_row; Astore->m_loc = m_loc; Astore->nzval = nzval; Astore->colind = colind; Astore->rowptr = rowptr;}/* * Convert a row compressed storage into a column compressed storage. */voiddCompRow_to_CompCol_dist(int_t m, int_t n, int_t nnz, double *a, int_t *colind, int_t *rowptr, double **at, int_t **rowind, int_t **colptr){ register int i, j, col, relpos; int_t *marker; /* Allocate storage for another copy of the matrix. */ *at = (double *) doubleMalloc_dist(nnz); *rowind = intMalloc_dist(nnz); *colptr = intMalloc_dist(n+1); marker = intCalloc_dist(n); /* Get counts of each column of A, and set up column pointers */ for (i = 0; i < m; ++i) for (j = rowptr[i]; j < rowptr[i+1]; ++j) ++marker[colind[j]]; (*colptr)[0] = 0; for (j = 0; j < n; ++j) { (*colptr)[j+1] = (*colptr)[j] + marker[j]; marker[j] = (*colptr)[j]; } /* Transfer the matrix into the compressed column storage. */ for (i = 0; i < m; ++i) { for (j = rowptr[i]; j < rowptr[i+1]; ++j) { col = colind[j]; relpos = marker[col]; (*rowind)[relpos] = i; (*at)[relpos] = a[j]; ++marker[col]; } } SUPERLU_FREE(marker);}/* Copy matrix A into matrix B. */voiddCopy_CompCol_Matrix_dist(SuperMatrix *A, SuperMatrix *B){ NCformat *Astore, *Bstore; int ncol, nnz, i; B->Stype = A->Stype; B->Dtype = A->Dtype; B->Mtype = A->Mtype; B->nrow = A->nrow;; B->ncol = ncol = A->ncol; Astore = (NCformat *) A->Store; Bstore = (NCformat *) B->Store; Bstore->nnz = nnz = Astore->nnz; for (i = 0; i < nnz; ++i) ((double *)Bstore->nzval)[i] = ((double *)Astore->nzval)[i]; for (i = 0; i < nnz; ++i) Bstore->rowind[i] = Astore->rowind[i]; for (i = 0; i <= ncol; ++i) Bstore->colptr[i] = Astore->colptr[i];}void dPrint_CompCol_Matrix_dist(SuperMatrix *A){ NCformat *Astore; register int i; double *dp; printf("\nCompCol matrix: "); printf("Stype %d, Dtype %d, Mtype %d\n", A->Stype,A->Dtype,A->Mtype); Astore = (NCformat *) A->Store; printf("nrow %d, ncol %d, nnz %d\n", A->nrow,A->ncol,Astore->nnz); if ( (dp = (double *) Astore->nzval) != NULL ) { printf("nzval:\n"); for (i = 0; i < Astore->nnz; ++i) printf("%f ", dp[i]); } printf("\nrowind:\n"); for (i = 0; i < Astore->nnz; ++i) printf("%d ", Astore->rowind[i]); printf("\ncolptr:\n"); for (i = 0; i <= A->ncol; ++i) printf("%d ", Astore->colptr[i]); printf("\nend CompCol matrix.\n");}void dPrint_Dense_Matrix_dist(SuperMatrix *A){ DNformat *Astore; register int i; double *dp; printf("\nDense matrix: "); printf("Stype %d, Dtype %d, Mtype %d\n", A->Stype,A->Dtype,A->Mtype); Astore = (DNformat *) A->Store; dp = (double *) Astore->nzval; printf("nrow %d, ncol %d, lda %d\n", A->nrow,A->ncol,Astore->lda); printf("\nnzval: "); for (i = 0; i < A->nrow; ++i) printf("%f ", dp[i]); printf("\nend Dense matrix.\n");}int dPrint_CompRowLoc_Matrix_dist(SuperMatrix *A){ NRformat_loc *Astore; int_t i, nnz_loc, m_loc; double *dp; printf("\n==== CompRowLoc matrix: "); printf("Stype %d, Dtype %d, Mtype %d\n", A->Stype,A->Dtype,A->Mtype); Astore = (NRformat_loc *) A->Store; printf("nrow %d, ncol %d\n", A->nrow,A->ncol); nnz_loc = Astore->nnz_loc; m_loc = Astore->m_loc; printf("nnz_loc %d, m_loc %d, fst_row %d\n", nnz_loc, m_loc, Astore->fst_row); PrintInt10("rowptr", m_loc+1, Astore->rowptr); PrintInt10("colind", nnz_loc, Astore->colind); if ( (dp = (double *) Astore->nzval) != NULL ) PrintDouble5("nzval", nnz_loc, dp); printf("==== end CompRowLoc matrix\n");}int file_dPrint_CompRowLoc_Matrix_dist(FILE *fp, SuperMatrix *A){ NRformat_loc *Astore; int_t i, nnz_loc, m_loc; double *dp; fprintf(fp, "\n==== CompRowLoc matrix: "); fprintf(fp, "Stype %d, Dtype %d, Mtype %d\n", A->Stype,A->Dtype,A->Mtype); Astore = (NRformat_loc *) A->Store; fprintf(fp, "nrow %d, ncol %d\n", A->nrow, A->ncol); nnz_loc = Astore->nnz_loc; m_loc = Astore->m_loc; fprintf(fp, "nnz_loc %d, m_loc %d, fst_row %d\n", nnz_loc, m_loc, Astore->fst_row); file_PrintInt10(fp, "rowptr", m_loc+1, Astore->rowptr); file_PrintInt10(fp, "colind", nnz_loc, Astore->colind); if ( (dp = (double *) Astore->nzval) != NULL ) file_PrintDouble5(fp, "nzval", nnz_loc, dp); fprintf(fp, "==== end CompRowLoc matrix\n");}voiddCreate_Dense_Matrix_dist(SuperMatrix *X, int_t m, int_t n, double *x, int_t ldx, Stype_t stype, Dtype_t dtype, Mtype_t mtype){ DNformat *Xstore; X->Stype = stype; X->Dtype = dtype; X->Mtype = mtype; X->nrow = m; X->ncol = n; X->Store = (void *) SUPERLU_MALLOC( sizeof(DNformat) ); if ( !(X->Store) ) ABORT("SUPERLU_MALLOC fails for X->Store"); Xstore = (DNformat *) X->Store; Xstore->lda = ldx; Xstore->nzval = (double *) x;}voiddCopy_Dense_Matrix_dist(int_t M, int_t N, double *X, int_t ldx, double *Y, int_t ldy){/* * Purpose * ======= * * Copies a two-dimensional matrix X to another matrix Y. */ int i, j; for (j = 0; j < N; ++j) for (i = 0; i < M; ++i) Y[i + j*ldy] = X[i + j*ldx];}voiddCreate_SuperNode_Matrix_dist(SuperMatrix *L, int_t m, int_t n, int_t nnz, double *nzval, int_t *nzval_colptr, int_t *rowind, int_t *rowind_colptr, int_t *col_to_sup, int_t *sup_to_col, Stype_t stype, Dtype_t dtype, Mtype_t mtype){ SCformat *Lstore; L->Stype = stype; L->Dtype = dtype; L->Mtype = mtype; L->nrow = m; L->ncol = n; L->Store = (void *) SUPERLU_MALLOC( sizeof(SCformat) ); if ( !(L->Store) ) ABORT("SUPERLU_MALLOC fails for L->Store"); Lstore = L->Store; Lstore->nnz = nnz; Lstore->nsuper = col_to_sup[n]; Lstore->nzval = nzval; Lstore->nzval_colptr = nzval_colptr; Lstore->rowind = rowind; Lstore->rowind_colptr = rowind_colptr; Lstore->col_to_sup = col_to_sup; Lstore->sup_to_col = sup_to_col;}voiddGenXtrue_dist(int_t n, int_t nrhs, double *x, int_t ldx){ int i, j; for (j = 0; j < nrhs; ++j) for (i = 0; i < n; ++i) { if ( i % 2 ) x[i + j*ldx] = 1.0;/* + (double)(i+1.)/n;*/ else x[i + j*ldx] = 1.0; }}/* * Let rhs[i] = sum of i-th row of A, so the solution vector is all 1's */voiddFillRHS_dist(char *trans, int_t nrhs, double *x, int_t ldx, SuperMatrix *A, double *rhs, int_t ldb){ double one = 1.0; double zero = 0.0; sp_dgemm_dist(trans, "N", A->nrow, nrhs, A->ncol, one, A, x, ldx, zero, rhs, ldb);}/* * Fills a double precision array with a given value. */void dfill_dist(double *a, int_t alen, double dval){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -