/[escript]/trunk/paso/src/MKL.c
ViewVC logotype

Contents of /trunk/paso/src/MKL.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3299 - (show annotations)
Sun Oct 24 23:44:18 2010 UTC (8 years, 11 months ago) by gross
File MIME type: text/plain
File size: 6346 byte(s)
some fixes
1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2010 by University of Queensland
5 * Earth Systems Science Computational Center (ESSCC)
6 * http://www.uq.edu.au/esscc
7 *
8 * Primary Business: Queensland, Australia
9 * Licensed under the Open Software License version 3.0
10 * http://www.opensource.org/licenses/osl-3.0.php
11 *
12 *******************************************************/
13
14
15 /**************************************************************/
16
17 /* Paso: interface to the Intel MKL library */
18
19 /**************************************************************/
20
21 /* Copyrights by ACcESS Australia 2006 */
22 /* Author: l.gross@uq.edu.au */
23
24 /**************************************************************/
25
26 #include "Paso.h"
27 #include "MKL.h"
28 #ifdef _OPENMP
29 #include <omp.h>
30 #endif
31
32 /**************************************************************/
33
34 /* free any extra stuff possibly used by the MKL library */
35
36 void Paso_MKL_free(Paso_SparseMatrix* A) {
37 #ifdef MKL
38 index_t i;
39 if ((A->solver_p!=NULL) && (A->solver_package=PASO_MKL) ) {
40 _INTEGER_t mtype = MKL_MTYPE_UNSYM;
41 _INTEGER_t n = A->numRows;
42 _INTEGER_t maxfct=1; /* number of factorizations on the same pattern */
43 _INTEGER_t mnum =1; /* factoriztion to be handeled in this call */
44 _INTEGER_t msglvl=0; /* message level */
45 _INTEGER_t nrhs=1; /* number of right hand sides */
46 _INTEGER_t idum; /* dummy integer */
47 _DOUBLE_PRECISION_t ddum; /* dummy float */
48 _INTEGER_t error=MKL_ERROR_NO; /* error code */
49 _INTEGER_t iparm[64]; /* parameters */
50 for (i=0;i<64;++i) iparm[i]=0;
51
52 _INTEGER_t phase = MKL_PHASE_RELEASE_MEMORY;
53 PARDISO ((_MKL_DSS_HANDLE_t *)(A->solver_p), &maxfct, &mnum, &mtype, &phase,
54 &n, A->val, A->pattern->ptr, A->pattern->index, &idum, &nrhs,
55 iparm, &msglvl,&ddum, &ddum, &error);
56 MEMFREE(A->solver_p);
57 if (error != MKL_ERROR_NO) Esys_setError(TYPE_ERROR,"memory release in PARDISO library failed.");
58 }
59 #endif
60 }
61
62 /* call the solver: */
63
64 void Paso_MKL(Paso_SparseMatrix* A,
65 double* out,
66 double* in,
67 index_t reordering,
68 dim_t numRefinements,
69 bool_t verbose)
70 {
71
72 #ifdef MKL
73 double time0;
74 index_t i;
75
76 if (! (A->type & (MATRIX_FORMAT_OFFSET1 + MATRIX_FORMAT_BLK1)) ) {
77 Esys_setError(TYPE_ERROR,"Paso_MKL: MKL requires CSR format with index offset 1 and block size 1.");
78 return;
79 }
80
81 _INTEGER_t mtype = MKL_MTYPE_UNSYM;
82 _INTEGER_t n = A->numRows;
83 _INTEGER_t maxfct=1; /* number of factorizations on the same pattern */
84 _INTEGER_t mnum =1; /* factoriztion to be handeled in this call */
85 _INTEGER_t msglvl=0; /* message level */
86 _INTEGER_t nrhs=1; /* number of right hand sides */
87 _INTEGER_t idum; /* dummy integer */
88 _DOUBLE_PRECISION_t ddum; /* dummy float */
89 _INTEGER_t phase = MKL_PHASE_SYMBOLIC_FACTORIZATION;
90
91 _INTEGER_t error=MKL_ERROR_NO; /* error code */
92 _INTEGER_t iparm[64]; /* parameters */
93 _MKL_DSS_HANDLE_t* pt = (_MKL_DSS_HANDLE_t *)(A->solver_p);
94 /* set iparm */
95 for (i=0;i<64;++i) iparm[i]=0;
96 iparm[0] = 1; /* no default settings*/
97 switch (reordering) {
98 case PASO_MINIMUM_FILL_IN:
99 iparm[1]=MKL_REORDERING_MINIMUM_DEGREE;
100 break;
101 default:
102 iparm[1]=MKL_REORDERING_NESTED_DISSECTION;
103 break;
104 }
105 #ifdef _OPENMP
106 iparm[2] =omp_get_max_threads();
107 #else
108 iparm[2] = 1;
109 #endif
110 iparm[5] = 0; /* store solution into output array */
111 iparm[7] = numRefinements; /* maximum number of refinements */
112 iparm[9] = 13; /* 10**(-iparm[9]) preturbation of pivot elements */
113 iparm[10] = 1; /* rescaling the matrix before factorization started */
114 iparm[17] =0; /* =-1 report number of non-zeroes */
115 iparm[18] =0; /* =-1 report flops */
116
117 if (pt==NULL) {
118 /* allocate address pointer */
119 pt=MEMALLOC(64,_MKL_DSS_HANDLE_t);
120 if (Esys_checkPtr(pt)) return;
121 A->solver_p=(void*) pt;
122 A->solver_package=PASO_MKL;
123 for (i=0;i<64;++i) pt[i]=NULL;
124 time0=Esys_timer();
125 /* symbolic factorization */
126 phase = MKL_PHASE_SYMBOLIC_FACTORIZATION;
127 PARDISO (pt, &maxfct, &mnum, &mtype, &phase,
128 &n, A->val, A->pattern->ptr, A->pattern->index, &idum, &nrhs,
129 iparm, &msglvl, in, out, &error);
130 if (error != MKL_ERROR_NO) {
131 if (verbose) printf("MKL: symbolic factorization factorization failed.\n");
132 Esys_setError(VALUE_ERROR,"symbolic factorization in PARDISO library failed.");
133 Paso_MKL_free(A);
134 } else {
135 /* LDU factorization */
136 phase = MKL_PHASE_FACTORIZATION;
137 PARDISO(pt, &maxfct, &mnum, &mtype, &phase,
138 &n, A->val, A->pattern->ptr, A->pattern->index, &idum, &nrhs,
139 iparm, &msglvl, in, out, &error);
140 if (error != MKL_ERROR_NO) {
141 if (verbose) printf("MKL: LDU factorization failed.\n");
142 Esys_setError(ZERO_DIVISION_ERROR,"factorization in PARDISO library failed. Most likely the matrix is singular.");
143 Paso_MKL_free(A);
144 }
145 if (verbose) printf("MKL: LDU factorization completed (time = %e).\n",Esys_timer()-time0);
146 }
147 }
148 /* forward backward substitution\ */
149 if (Esys_noError()) {
150 time0=Esys_timer();
151 phase = MKL_PHASE_SOLVE;
152 PARDISO (pt, &maxfct, &mnum, &mtype, &phase,
153 &n, A->val, A->pattern->ptr, A->pattern->index, &idum, &nrhs,
154 iparm, &msglvl, in, out, &error);
155 if (verbose) printf("MKL: solve completed.\n");
156 if (error != MKL_ERROR_NO) {
157 if (verbose) printf("MKL: forward/backward substitution failed.\n");
158 Esys_setError(VALUE_ERROR,"forward/backward substitution in PARDISO library failed. Most likely the matrix is singular.");
159 } else {
160 if (verbose) printf("MKL: forward/backward substitution completed (time = %e).\n",Esys_timer()-time0);
161 }
162 }
163 #else
164 Esys_setError(SYSTEM_ERROR,"Paso_MKL:MKL is not avialble.");
165 #endif
166 }

  ViewVC Help
Powered by ViewVC 1.1.26