⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dmemory.c

📁 SuperLU 2.2版本。对大型、稀疏、非对称的线性系统的直接求解
💻 C
字号:
/* * -- Distributed SuperLU routine (version 1.0) -- * Lawrence Berkeley National Lab, Univ. of California Berkeley. * September 1, 1999 * */#include "superlu_ddefs.h"/* Variables external to this file */extern LU_stack_t stack;void *duser_malloc_dist(int_t bytes, int_t which_end){    void *buf;        if ( StackFull(bytes) ) return (NULL);    if ( which_end == HEAD ) {	buf = (char*) stack.array + stack.top1;	stack.top1 += bytes;    } else {	stack.top2 -= bytes;	buf = (char*) stack.array + stack.top2;    }        stack.used += bytes;    return buf;}void duser_free_dist(int_t bytes, int_t which_end){    if ( which_end == HEAD ) {	stack.top1 -= bytes;    } else {	stack.top2 += bytes;    }    stack.used -= bytes;}/* * mem_usage consists of the following fields: *    - for_lu (float) *      The amount of space used in bytes for the L\U data structures. *    - total (float) *      The amount of space needed in bytes to perform factorization. *    - expansions (int) *      Number of memory expansions during the LU factorization. */int_t dQuerySpace_dist(int_t n, LUstruct_t *LUstruct, gridinfo_t *grid,		       mem_usage_t *mem_usage){    register int_t dword, gb, iword, k, maxsup, nb, nsupers;    int_t *index, *xsup;    int iam, mycol, myrow;    Glu_persist_t *Glu_persist = LUstruct->Glu_persist;    LocalLU_t *Llu = LUstruct->Llu;    iam = grid->iam;    myrow = MYROW( iam, grid );    mycol = MYCOL( iam, grid );    iword = sizeof(int_t);    dword = sizeof(double);    maxsup = sp_ienv_dist(3);    nsupers = Glu_persist->supno[n-1] + 1;    xsup = Glu_persist->xsup;    mem_usage->for_lu = 0;    /* For L factor */    nb = CEILING( nsupers, grid->npcol ); /* Number of local column blocks */    for (k = 0; k < nb; ++k) {	gb = k * grid->npcol + mycol; /* Global block number. */	if ( gb < nsupers ) {	    index = Llu->Lrowind_bc_ptr[k];	    if ( index ) {		mem_usage->for_lu += (float)		    ((BC_HEADER + index[0]*LB_DESCRIPTOR + index[1]) * iword);		mem_usage->for_lu += (float)(index[1]*SuperSize( gb )*dword);	    }	}    }    /* For U factor */    nb = CEILING( nsupers, grid->nprow ); /* Number of local row blocks */    for (k = 0; k < nb; ++k) {	gb = k * grid->nprow + myrow; /* Global block number. */	if ( gb < nsupers ) {	    index = Llu->Ufstnz_br_ptr[k];	    if ( index ) {		mem_usage->for_lu += (float)(index[2] * iword);		mem_usage->for_lu += (float)(index[1] * dword);	    }	}    }    /* Working storage to support factorization */    mem_usage->total = mem_usage->for_lu;    mem_usage->total +=	(float)(( Llu->bufmax[0] + Llu->bufmax[2] ) * iword +		( Llu->bufmax[1] + Llu->bufmax[3] + maxsup ) * dword );    /**** another buffer to use mpi_irecv in pdgstrf_irecv.c ****/    mem_usage->total +=	(float)( Llu->bufmax[0] * iword +  Llu->bufmax[1] * dword );    mem_usage->total += (float)( maxsup * maxsup + maxsup) * iword;    k = CEILING( nsupers, grid->nprow );    mem_usage->total += (float)(2 * k * iword);    return 0;} /* dQuerySpace_dist *//* * Allocate storage for original matrix A */voiddallocateA_dist(int_t n, int_t nnz, double **a, int_t **asub, int_t **xa){    *a    = (double *) doubleMalloc_dist(nnz);    *asub = (int_t *) intMalloc_dist(nnz);    *xa   = (int_t *) intMalloc_dist(n+1);}double *doubleMalloc_dist(int_t n){    double *buf;    buf = (double *) SUPERLU_MALLOC( SUPERLU_MAX(1, n) * sizeof(double) );     return (buf);}double *doubleCalloc_dist(int_t n){    double *buf;    register int_t i;    double zero = 0.0;    buf = (double *) SUPERLU_MALLOC( SUPERLU_MAX(1, n) * sizeof(double));    if ( !buf ) return (buf);    for (i = 0; i < n; ++i) buf[i] = zero;    return (buf);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -