ThreadedSuperLU.cpp

Go to the documentation of this file.
00001 /* ****************************************************************** **
00002 **    OpenSees - Open System for Earthquake Engineering Simulation    **
00003 **          Pacific Earthquake Engineering Research Center            **
00004 **                                                                    **
00005 **                                                                    **
00006 ** (C) Copyright 1999, The Regents of the University of California    **
00007 ** All Rights Reserved.                                               **
00008 **                                                                    **
00009 ** Commercial use of this program without express permission of the   **
00010 ** University of California, Berkeley, is strictly prohibited.  See   **
00011 ** file 'COPYRIGHT'  in main directory for information on usage and   **
00012 ** redistribution,  and for a DISCLAIMER OF ALL WARRANTIES.           **
00013 **                                                                    **
00014 ** Developed by:                                                      **
00015 **   Frank McKenna (fmckenna@ce.berkeley.edu)                         **
00016 **   Gregory L. Fenves (fenves@ce.berkeley.edu)                       **
00017 **   Filip C. Filippou (filippou@ce.berkeley.edu)                     **
00018 **                                                                    **
00019 ** ****************************************************************** */
00020                                                                         
00021 // $Revision: 1.3 $
00022 // $Date: 2003/02/14 23:02:03 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/system_of_eqn/linearSOE/sparseGEN/ThreadedSuperLU.cpp,v $
00024                                                                         
00025                                                                         
00026 // File: ~/system_of_eqn/linearSOE/sparseGEN/ThreadedSuperLU.h
00027 //
00028 // Written: fmk 
00029 // Created: 11/96
00030 // Revision: A
00031 //
00032 // Description: This file contains the class definition for 
00033 // ThreadedSuperLU. It solves the FullGenLinSOE object by calling
00034 // SuperLU_MT routines.
00035 //
00036 // What: "@(#) ThreadedSuperLU.h, revA"
00037 
00038 #include <ThreadedSuperLU.h>
00039 #include <SparseGenColLinSOE.h>
00040 #include <f2c.h>
00041 #include <math.h>
00042 #include <Channel.h>
00043 #include <FEM_ObjectBroker.h>
00044 
00045 ThreadedSuperLU::
00046 ThreadedSuperLU(int numT, int perm, int relx, 
00047                              int panel, double thrsh) 
00048 :SparseGenColLinSolver(SOLVER_TAGS_ThreadedSuperLU),
00049  perm_r(0),perm_c(0), 
00050  etree(0), sizePerm(0),
00051  relax(relx), permSpec(perm), panelSize(panel),
00052  thresh(thrsh), numThreads(numT), 
00053  refact(NO), usepr(NO), fact(DOFACT), work(NULL), lwork(0)
00054 {
00055   refact = NO;
00056   fact = DOFACT;
00057   usepr = NO;
00058   work = NULL;
00059   lwork = 0;
00060 }
00061 
00062 
00063 ThreadedSuperLU::~ThreadedSuperLU()
00064 {
00065   if (perm_r != 0)
00066         delete [] perm_r;
00067   if (perm_c != 0)
00068         delete [] perm_c;
00069   if (etree != 0)
00070         delete [] etree;
00071   if (lwork >= 0) {
00072     Destroy_SuperNode_SCP(&L);
00073     Destroy_CompCol_NCP(&U);
00074   }
00075   StatFree(&gStat);
00076 }
00077 
00078 int
00079 ThreadedSuperLU::solve(void)
00080 {
00081     if (theSOE == 0) {
00082         opserr << "WARNING ThreadedSuperLU::solve(void)- ";
00083         opserr << " No LinearSOE object has been set\n";
00084         return -1;
00085     }
00086     
00087     int n = theSOE->size;
00088     
00089     // check for quick return
00090     if (n == 0)
00091         return 0;
00092 
00093     if (sizePerm == 0) {
00094         opserr << "WARNING ThreadedSuperLU::solve(void)- ";
00095         opserr << " size for row and col permutations 0 - has setSize() been called?\n";
00096         return -1;
00097     }
00098 
00099     // first copy B into X
00100     double *Xptr = theSOE->X;
00101     double *Bptr = theSOE->B;
00102     for (int i=0; i<n; i++)
00103         *(Xptr++) = *(Bptr++);
00104 
00105     if (theSOE->factored == false) {
00106         // factor the matrix
00107         int info;
00108 
00109         StatInit(n, numThreads, &gStat);
00110 
00111         pdgstrf_init(numThreads, refact, panelSize, relax, thresh, usepr,
00112                      0.0, perm_c, perm_r, work, lwork, &A, &AC, 
00113                      &pdgstrf_options, &gStat);
00114 
00115         pdgstrf(&pdgstrf_options, &AC, perm_r, &L, &U, &gStat, &info);
00116 
00117         if (info != 0) {        
00118            opserr << "WARNING ThreadedSuperLU::solve(void)- ";
00119            opserr << " Error " << info << " returned in factorization dgstrf()\n";
00120            return info;
00121         }
00122 
00123         refact = YES;   
00124         theSOE->factored = true;
00125     }   
00126 
00127     // do forward and backward substitution
00128     trans = NOTRANS;
00129     int info;
00130     dgstrs (trans, &L, &U, perm_r, perm_c, &B, &gStat, &info);    
00131 
00132     if (info != 0) {    
00133        opserr << "WARNING ThreadedSuperLU::solve(void)- ";
00134        opserr << " Error " << info << " returned in substitution dgstrs()\n";
00135        return info;
00136     }
00137 
00138     return 0;
00139 }
00140 
00141 
00142 
00143 
00144 int
00145 ThreadedSuperLU::setSize()
00146 {
00147     int n = theSOE->size;
00148     if (n > 0) {
00149 
00150       // create space for the permutation vectors 
00151       // and the elimination tree
00152       if (sizePerm < n) {
00153 
00154         if (perm_r != 0)
00155           delete [] perm_r;
00156         perm_r = new int[n];            
00157 
00158         if (perm_c != 0)
00159           delete [] perm_c;
00160         perm_c = new int[n];            
00161 
00162         if (etree != 0)
00163           delete [] etree;
00164         etree = new int[n];             
00165 
00166         if (perm_r == 0 || perm_c == 0 || etree == 0) {
00167           opserr << "WARNING ThreadedSuperLU::setSize()";
00168           opserr << " - ran out of memory\n";
00169           sizePerm = 0;
00170           return -1;
00171         }               
00172         sizePerm = n;
00173       }
00174 
00175       // initialisation
00176       StatAlloc(n, numThreads, panelSize, relax, &gStat);
00177 
00178       // create the SuperMatrixMT A     
00179       dCreate_CompCol_Matrix(&A, n, n, theSOE->nnz, theSOE->A, 
00180                              theSOE->rowA, theSOE->colStartA, 
00181                              NC, _D, GE);
00182 
00183       // obtain and apply column permutation to give SuperMatrixMT AC
00184       get_perm_c(permSpec, &A, perm_c);
00185       //      sp_preorder(refact, &A, perm_c, etree, &AC);
00186 
00187       // create the rhs SuperMatrixMT B 
00188       dCreate_Dense_Matrix(&B, n, 1, theSOE->X, n, DN, _D, GE);
00189         
00190       // set the refact variable to 'N' after first factorization with new size 
00191       // can set to 'Y'.
00192       refact = NO;
00193 
00194     } else if (n == 0)
00195         return 0;
00196     else {
00197         opserr << "WARNING ThreadedSuperLU::setSize()";
00198         opserr << " - order of system <  0\n";
00199         return -1;      
00200     }
00201         
00202     return 0;
00203 }
00204 
00205 int
00206 ThreadedSuperLU::sendSelf(int cTag, Channel &theChannel)
00207 {
00208     // nothing to do
00209     return 0;
00210 }
00211 
00212 int
00213 ThreadedSuperLU::recvSelf(int cTag, 
00214                           Channel &theChannel, 
00215                           FEM_ObjectBroker &theBroker)
00216 {
00217     // nothing to do
00218     return 0;
00219 }
00220 

Generated on Mon Oct 23 15:05:29 2006 for OpenSees by doxygen 1.5.0