ActorPetscSOE.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.2 $
00022 // $Date: 2003/02/14 23:02:02 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/system_of_eqn/linearSOE/petsc/ActorPetscSOE.cpp,v $
00024                                                                         
00025                                                                         
00026 // File: ~/system_of_eqn/linearSOE/petsc/ActorPetscSOE.C
00027 //
00028 // Written: fmk & om
00029 // Created: 7/98
00030 // Revision: A
00031 //
00032 // Description: This file contains the implementation for BandGenLinSOE
00033 
00034 
00035 #include "ActorPetscSOE.h"
00036 #include "PetscSolver.h"
00037 #include "PetscSOE.h"
00038 #include <Matrix.h>
00039 #include <Graph.h>
00040 #include <Vertex.h>
00041 #include <VertexIter.h>
00042 #include <f2c.h>
00043 #include <math.h>
00044 #include <Channel.h>
00045 #include <FEM_ObjectBroker.h>
00046 
00047 ActorPetscSOE::ActorPetscSOE(PetscSolver &theSOESolver, int blockSize)
00048   :myRank(0), theSOE(0), theSolver(&theSOESolver), recvBuffer(0)
00049 {
00050 
00051   MPI_Comm_rank(PETSC_COMM_WORLD, &myRank);
00052   MPI_Comm_size(PETSC_COMM_WORLD, &numProcessors);
00053   //  MPI_Comm_dup(PETSC_COMM_WORLD, &theComm);
00054   if (myRank == 0) {
00055     opserr << " ActorPetscSOE::ActorPetscSOE - must be rank 0\n";
00056   }
00057   recvBuffer = (void *)(&recvData[0]);
00058   MPI_Barrier(PETSC_COMM_WORLD);
00059 
00060 /***************
00061   // recv data on the PetscSolver & determine KSP and PC type
00062   MPI_Bcast(recvBuffer, 3, MPI_INT, 0, PETSC_COMM_WORLD);    
00063 
00064   int method = recvData[0];
00065   int preconditioner = recvData[1];
00066 
00067   KSPType petscMethod =0;
00068   PCType petscPre =0;
00069   if (method == 1)
00070     petscMethod = KSPCG;
00071   else if (method == 2)
00072     petscMethod = KSPGMRES;
00073   else if (method == 3)
00074     petscMethod = KSPBCGS;
00075   else if (method == 4)
00076     petscMethod = KSPCGS;
00077   else if (method == 5)
00078     petscMethod = KSPTFQMR;
00079   else if (method == 6)
00080     petscMethod = KSPTCQMR;
00081   else if (method == 7)
00082     petscMethod = KSPCR;
00083   else if (method == 8)
00084     petscMethod = KSPLSQR;
00085   else if (method == 9)
00086     petscMethod = KSPRICHARDSON;
00087   else if (method == 10)
00088     petscMethod = KSPCHEBYCHEV;
00089   else if (method == 11)
00090     petscMethod = KSPPREONLY;
00091   else {
00092     opserr << "ActorPetscSOE::ActorPetscSOE - unknown KSP method\n";
00093   }
00094 
00095   if (preconditioner == 1)
00096     petscPre = PCNONE;
00097   else if (preconditioner == 2)
00098     petscPre = PCJACOBI;  
00099   else if (preconditioner == 3)
00100     petscPre = PCSOR;  
00101   else if (preconditioner == 4)
00102     petscPre = PCEISENSTAT;  
00103   else if (preconditioner == 5)
00104     petscPre = PCBJACOBI;  
00105   else if (preconditioner == 6)
00106     petscPre = PCASM;  
00107   else if (preconditioner == 7)
00108     petscPre = PCILU;  
00109   else if (preconditioner == 8)
00110     petscPre = PCICC;  
00111   else if (preconditioner == 9)
00112     petscPre = PCBGS;  
00113   else if (preconditioner == 10)
00114     petscPre = PCMG;  
00115   else if (preconditioner == 11)
00116     petscPre = PCSHELL;  
00117   else if (preconditioner == 12)
00118     petscPre = PCLU;  
00119   else {
00120     opserr << "ActorPetscSOE::ActorPetscSOE - unknown PC method\n";
00121   }
00122 
00123   // construct the PetscSolver and PetscSOE
00124   if ((petscMethod != 0) && (petscPre != 0)) {
00125     theSolver = new PetscSolver(petscMethod, petscPre);
00126     theSOE = new PetscSOE(*theSolver);
00127   }
00128   *********/
00129 
00130   theSOE = new PetscSOE(*theSolver, blockSize);
00131 }
00132 
00133 
00134     
00135 ActorPetscSOE::~ActorPetscSOE()
00136 {
00137   //  if (theSOE != 0)
00138   //    delete theSOE;
00139 }
00140 
00141 
00142 int 
00143 ActorPetscSOE::run(void)
00144 {
00145   int flag = 1;
00146   int tag, low, high, ierr, n, numRows;
00147   double *theData;
00148   int dnz = 0;
00149   int onz = 0;
00150   int *dnnz = PETSC_NULL;
00151   int *onnz = PETSC_NULL;
00152   MPI_Status status;
00153   void *buffer = 0;
00154   
00155   while (flag != 0) {
00156     MPI_Bcast(recvBuffer, 3, MPI_INT, 0, PETSC_COMM_WORLD);  
00157     flag = recvData[0];
00158     switch(flag) {
00159 
00160     case 0:
00161       MPI_Barrier(PETSC_COMM_WORLD);
00162       break;
00163 
00164     case 1:
00165       if (theSOE == 0)
00166         return -1;
00167       theSOE->isFactored = recvData[1];
00168       theSOE->solve();
00169       break;
00170 
00171     case 2:
00172       if (theSOE == 0)
00173         return -1;
00174       tag = 100;
00175       MPI_Recv(recvBuffer, 3, MPI_INT, 0, tag, PETSC_COMM_WORLD, &status);
00176 
00177       numRows = recvData[1];
00178       n = recvData[2];
00179       onnz = new int[numRows];
00180       dnnz = new int[numRows];
00181       buffer = (void *)dnnz;
00182       tag = 101;
00183       MPI_Recv(buffer, numRows, MPI_INT, 0, tag, PETSC_COMM_WORLD, &status);
00184 
00185       buffer = (void *)onnz;
00186       tag = 102;
00187       MPI_Recv(buffer, numRows, MPI_INT, 0, tag, PETSC_COMM_WORLD, &status);
00188 
00189       MPI_Bcast(recvBuffer, 3, MPI_INT, 0, PETSC_COMM_WORLD);  
00190       theSOE->setSizeParallel(numRows, n, dnz, dnnz, onz, onnz);        
00191       break;
00192 
00193     case 3:
00194       if (theSOE == 0)
00195         return -1;
00196       theSOE->zeroA();
00197       break;
00198 
00199     case 4:
00200       if (theSOE == 0)
00201         return -1;
00202       theSOE->zeroB();
00203       break;
00204 
00205     case 5:
00206       if (theSOE == 0)
00207         return -1;
00208       tag = 99;
00209       ierr = VecGetOwnershipRange(theSOE->x, &low, &high); CHKERRA(ierr);
00210       recvData[0] = low; recvData[1] = high;
00211       MPI_Send(recvBuffer, 2, MPI_INT, 0, tag, PETSC_COMM_WORLD);
00212       ierr = VecGetArray(theSOE->x, &theData); CHKERRA(ierr);       
00213       MPI_Send(theData, high-low, MPI_DOUBLE, 0, tag, PETSC_COMM_WORLD); 
00214       ierr = VecRestoreArray(theSOE->x, &theData); CHKERRA(ierr);             
00215       break;
00216 
00217     case 6:
00218       if (theSOE == 0)
00219         return -1;
00220       // some work here
00221 
00222     default:
00223       opserr << "ActorPetscSOE::invalid action " << flag << " received\n";
00224     }
00225   }
00226   return 0;
00227 }
00228 
00229 
00230 
00231 

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