Actual source code: essl.c
2: /*
3: Provides an interface to the IBM RS6000 Essl sparse solver
5: */
6: #include <../src/mat/impls/aij/seq/aij.h>
8: /* #include <essl.h> This doesn't work! */
11: void dgss(int*,int*,double*,int*,int*,int*,double*,double*,int*);
12: void dgsf(int*,int*,int*,double*,int*,int*,int*,int*,double*,double*,double*,int*);
15: typedef struct {
16: int n,nz;
17: PetscScalar *a;
18: int *ia;
19: int *ja;
20: int lna;
21: int iparm[5];
22: PetscReal rparm[5];
23: PetscReal oparm[5];
24: PetscScalar *aux;
25: int naux;
27: PetscBool CleanUpESSL;
28: } Mat_Essl;
32: PetscErrorCode MatDestroy_Essl(Mat A)
33: {
35: Mat_Essl *essl=(Mat_Essl*)A->spptr;
38: if (essl && essl->CleanUpESSL) {
39: PetscFree4(essl->a,essl->aux,essl->ia,essl->ja);
40: }
41: PetscFree(A->spptr);
42: MatDestroy_SeqAIJ(A);
43: return(0);
44: }
48: PetscErrorCode MatSolve_Essl(Mat A,Vec b,Vec x)
49: {
50: Mat_Essl *essl = (Mat_Essl*)A->spptr;
51: PetscScalar *xx;
53: int m,zero = 0;
56: VecGetLocalSize(b,&m);
57: VecCopy(b,x);
58: VecGetArray(x,&xx);
59: dgss(&zero,&A->cmap->n,essl->a,essl->ia,essl->ja,&essl->lna,xx,essl->aux,&essl->naux);
60: VecRestoreArray(x,&xx);
61: return(0);
62: }
66: PetscErrorCode MatLUFactorNumeric_Essl(Mat F,Mat A,const MatFactorInfo *info)
67: {
68: Mat_SeqAIJ *aa=(Mat_SeqAIJ*)(A)->data;
69: Mat_Essl *essl=(Mat_Essl*)(F)->spptr;
71: int i,one = 1;
74: /* copy matrix data into silly ESSL data structure (1-based Frotran style) */
75: for (i=0; i<A->rmap->n+1; i++) essl->ia[i] = aa->i[i] + 1;
76: for (i=0; i<aa->nz; i++) essl->ja[i] = aa->j[i] + 1;
77:
78: PetscMemcpy(essl->a,aa->a,(aa->nz)*sizeof(PetscScalar));
79:
80: /* set Essl options */
81: essl->iparm[0] = 1;
82: essl->iparm[1] = 5;
83: essl->iparm[2] = 1;
84: essl->iparm[3] = 0;
85: essl->rparm[0] = 1.e-12;
86: essl->rparm[1] = 1.0;
87: PetscOptionsGetReal(((PetscObject)A)->prefix,"-matessl_lu_threshold",&essl->rparm[1],PETSC_NULL);
89: dgsf(&one,&A->rmap->n,&essl->nz,essl->a,essl->ia,essl->ja,&essl->lna,essl->iparm,essl->rparm,essl->oparm,essl->aux,&essl->naux);
91: F->ops->solve = MatSolve_Essl;
92: (F)->assembled = PETSC_TRUE;
93: (F)->preallocated = PETSC_TRUE;
94: return(0);
95: }
102: PetscErrorCode MatLUFactorSymbolic_Essl(Mat B,Mat A,IS r,IS c,const MatFactorInfo *info)
103: {
104: Mat_SeqAIJ *a = (Mat_SeqAIJ*)A->data;
106: Mat_Essl *essl;
107: PetscReal f = 1.0;
110: essl = (Mat_Essl *)(B->spptr);
112: /* allocate the work arrays required by ESSL */
113: f = info->fill;
114: essl->nz = a->nz;
115: essl->lna = (int)a->nz*f;
116: essl->naux = 100 + 10*A->rmap->n;
118: /* since malloc is slow on IBM we try a single malloc */
119: PetscMalloc4(essl->lna,PetscScalar,&essl->a,essl->naux,PetscScalar,&essl->aux,essl->lna,int,&essl->ia,essl->lna,int,&essl->ja);
120: essl->CleanUpESSL = PETSC_TRUE;
122: PetscLogObjectMemory(B,essl->lna*(2*sizeof(int)+sizeof(PetscScalar)) + essl->naux*sizeof(PetscScalar));
123: B->ops->lufactornumeric = MatLUFactorNumeric_Essl;
124: return(0);
125: }
130: PetscErrorCode MatFactorGetSolverPackage_essl(Mat A,const MatSolverPackage *type)
131: {
133: *type = MATSOLVERESSL;
134: return(0);
135: }
137: /*MC
138: MATSOLVERESSL - "essl" - Provides direct solvers (LU) for sequential matrices
139: via the external package ESSL.
141: If ESSL is installed (see the manual for
142: instructions on how to declare the existence of external packages),
144: Works with MATSEQAIJ matrices
146: Level: beginner
148: .seealso: PCLU, PCFactorSetMatSolverPackage(), MatSolverPackage
149: M*/
153: PetscErrorCode MatGetFactor_seqaij_essl(Mat A,MatFactorType ftype,Mat *F)
154: {
155: Mat B;
157: Mat_Essl *essl;
160: if (A->cmap->N != A->rmap->N) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_SIZ,"matrix must be square");
161: MatCreate(((PetscObject)A)->comm,&B);
162: MatSetSizes(B,PETSC_DECIDE,PETSC_DECIDE,A->rmap->n,A->cmap->n);
163: MatSetType(B,((PetscObject)A)->type_name);
164: MatSeqAIJSetPreallocation(B,0,PETSC_NULL);
166: PetscNewLog(B,Mat_Essl,&essl);
167: B->spptr = essl;
168: B->ops->lufactorsymbolic = MatLUFactorSymbolic_Essl;
169: PetscObjectComposeFunctionDynamic((PetscObject)B,"MatFactorGetSolverPackage_C","MatFactorGetSolverPackage_essl",MatFactorGetSolverPackage_essl);
170: B->factortype = MAT_FACTOR_LU;
171: *F = B;
172: return(0);
173: }