00001 #include "spasol.h"
00002 #include <stdio.h>
00003 #include <stdlib.h>
00004
00005
00006
00007
00008
00009
00010 spasol::spasol ()
00011 {
00012 char *var;
00013
00014 nRows=0;
00015 nCols=0;
00016 nNonZeros=0;
00017 nrhs=1;
00018
00019 mtype=11;
00020
00021
00022
00023
00024
00025
00026
00027
00028 pardisoinit_(pt, &mtype, iparm);
00029
00030
00031 num_procs=1;
00032 var = getenv("OMP_NUM_THREADS");
00033 if(var != NULL)
00034 sscanf( var, "%d", &num_procs );
00035 else {
00036 printf("Assume that environment variable OMP_NUM_THREADS is set to 1");
00037
00038 }
00039 iparm[2] = num_procs;
00040
00041
00042
00043 }
00044
00045 spasol::~spasol ()
00046 {
00047
00048 }
00049
00050
00051
00052
00053 void spasol::symbfact (double *a,long *ci,long *adr,long ndof)
00054 {
00055 long i;
00056
00057
00058 nRows=ndof;
00059 nCols=ndof;
00060 nNonZeros=adr[ndof];
00061
00062
00063
00064 for(i=0;i<=ndof;i++) adr[i]++;
00065 for(i=0;i<nNonZeros;i++) ci[i]++;
00066
00067
00068
00069 for (i = 0; i < 64; i++) {
00070 iparm[i] = 0;
00071 }
00072
00073 maxfct = 1;
00074 mnum = 1;
00075 msglvl = 1;
00076 error = 0;
00077
00078
00079
00080
00081
00082 phase = 11;
00083
00084
00085
00086
00087
00088
00089
00090
00091 PARDISO (pt, &maxfct, &mnum, &mtype, &phase,
00092 (int *)&ndof, a, (int *)adr, (int *)ci, &idum, &nrhs,
00093 iparm, &msglvl, &ddum, &ddum, &error);
00094
00095
00096 if (error != 0) {
00097 fprintf(stderr,"\nERROR during symbolic factorization: %d\n.", error);
00098
00099 }
00100
00101 fprintf(stdout,"\nReordering completed ... ");
00102 fprintf(stdout,"\nPeak memory in KB = %d", iparm[14]);
00103 fprintf(stdout,"\nPermament memory in KB = %d", iparm[15]);
00104 fprintf(stdout,"\nMemory for solve in KB = %d", iparm[16]);
00105 fprintf(stdout,"\nNumber of nonzeros in factors = %d", iparm[17]);
00106 fprintf(stdout,"\nNumber of factorization MFLOPS = %d", iparm[18]);
00107
00108 fflush(stdout);
00109 }
00110
00111
00112
00113
00114 void spasol::numfact (double *a,long *ci,long*adr,long ndof)
00115 {
00116 phase = 22;
00117
00118 PARDISO (pt, &maxfct, &mnum, &mtype, &phase,
00119 (int *)&ndof, a, (int *)adr, (int *)ci, &idum, &nrhs,
00120 iparm, &msglvl, &ddum, &ddum, &error);
00121
00122 if (error != 0) {
00123 printf("\nERROR during numerical factorization: %d", error);
00124
00125 printf("\nFactorization completed ... ");
00126 fflush(stdout);
00127 }
00128
00129 }
00130
00131
00132
00133
00134 void spasol::backsubst (double *a,long *ci,long*adr,long ndof,double *x,double *y)
00135 {
00136 int i;
00137 phase = 33;
00138 iparm[7] = 1;
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166 PARDISO (pt, &maxfct, &mnum, &mtype, &phase,
00167 (int *)&ndof, a, (int *)adr, (int *)ci, &idum, &nrhs,
00168 iparm, &msglvl, y, x, &error);
00169
00170
00171 if (error != 0) {
00172 printf("\nERROR during backward substitution: %d", error);
00173
00174 }
00175 printf("\nSolve completed ... ");
00176 printf("\nThe solution of the system is: ");
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189 }
00190