MumpsParallelSolver.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: 2006/04/13 20:58:07 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/system_of_eqn/linearSOE/mumps/MumpsParallelSolver.cpp,v $
00024 
00025 // Written: fmk 
00026 // Created: 02/06
00027                                                                         
00028 // Description: This file contains the implementation of MumpsParallelSolver
00029 
00030 #include <MumpsParallelSolver.h>
00031 #include <MumpsParallelSOE.h>
00032 #include <Channel.h>
00033 #include <FEM_ObjectBroker.h>
00034 #include <OPS_Globals.h>
00035 
00036 #define ICNTL(I) icntl[(I)-1] /* macro s.t. indices match documentation */
00037 
00038 extern "C" {
00039 #include <mpi.h>
00040 }
00041 
00042 MumpsParallelSolver::MumpsParallelSolver()
00043   :LinearSOESolver(SOLVER_TAGS_MumpsParallelSolver),
00044    theMumpsSOE(0)
00045 {
00046   init = false;
00047 }
00048 
00049 MumpsParallelSolver::MumpsParallelSolver(int mpi_comm, int ICNTL7)
00050   :LinearSOESolver(SOLVER_TAGS_MumpsParallelSolver),
00051    theMumpsSOE(0)
00052 {
00053   init = false;
00054 }
00055 
00056 
00057 MumpsParallelSolver::~MumpsParallelSolver()
00058 {
00059   id.job=-2; 
00060   dmumps_c(&id); /* Terminate instance */
00061 }
00062 
00063 int
00064 MumpsParallelSolver::solve(void)
00065 {
00066   int n = theMumpsSOE->size;
00067   int nnz = theMumpsSOE->nnz;
00068   int *rowA = theMumpsSOE->rowA;
00069   int *colA = theMumpsSOE->colA;
00070   double *A = theMumpsSOE->A;
00071   double *X = theMumpsSOE->X;
00072   double *B = theMumpsSOE->B;
00073 
00074   // parallel solver; distributed i/p matrix A
00075   id.ICNTL(5)=0; id.ICNTL(18)=3; 
00076 
00077   // No outputs 
00078   id.ICNTL(1)=-1; id.ICNTL(2)=-1; id.ICNTL(3)=-1; id.ICNTL(4)=0;
00079   
00080   // increment row and col A values by 1 for mumps fortran indexing
00081   for (int i=0; i<nnz; i++) {
00082     rowA[i]++;
00083     colA[i]++;
00084   }
00085   
00086   if (rank == 0) {
00087     id.n   = n; 
00088     for (int i=0; i<n; i++) {
00089       X[i] = B[i];
00090     }
00091     id.rhs = X;
00092   } 
00093 
00094   // factor the matrix
00095   id.nz_loc  = nnz; 
00096   id.irn_loc = rowA;
00097   id.jcn_loc = colA;
00098   id.a_loc   = A; 
00099 
00100   if (theMumpsSOE->factored == false) {
00101 
00102     // Call the MUMPS package to factor & solve the system
00103     id.job = 5;
00104     dmumps_c(&id);
00105     theMumpsSOE->factored = true;
00106 
00107   } else {
00108 
00109     // Call the MUMPS package to solve the system
00110     id.job = 3;
00111     dmumps_c(&id);
00112   }     
00113 
00114   int info = id.infog[0];
00115   if (info != 0) {      
00116     opserr << "WARNING MumpsParallelSolver::solve(void)- ";
00117     opserr << " Error " << info << " returned in substitution dmumps()\n";
00118     return info;
00119   }
00120 
00121   // decrement row and col A values by 1 to return to C++ indexing
00122   for (int i=0; i<nnz; i++) {
00123     rowA[i]--;
00124     colA[i]--;
00125   }
00126 
00127   return 0;
00128 }
00129 
00130 
00131 int
00132 MumpsParallelSolver::setSize()
00133 {
00134   if (init == false) {
00135     id.job=-1; 
00136     id.par=1; 
00137     id.sym=theMumpsSOE->matType; 
00138     
00139     id.comm_fortran=MPI_COMM_WORLD;
00140     dmumps_c(&id);
00141     
00142     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
00143     MPI_Comm_size(MPI_COMM_WORLD, &np);
00144     init = true;
00145   }
00146 
00147   // parallel solver; distributed i/p matrix A
00148   id.ICNTL(5)=0; id.ICNTL(18)=3; 
00149 
00150   // No outputs 
00151   id.ICNTL(1)=-1; id.ICNTL(2)=-1; id.ICNTL(3)=-1; id.ICNTL(4)=0;
00152 
00153   int nnz = theMumpsSOE->nnz;
00154   int *rowA = theMumpsSOE->rowA;
00155   int *colA = theMumpsSOE->colA;
00156   
00157   // increment row and col A values by 1 for mumps fortran indexing
00158   for (int i=0; i<nnz; i++) {
00159     rowA[i]++;
00160     colA[i]++;
00161   }
00162 
00163   // analyze the matrix
00164   id.n   = theMumpsSOE->size; 
00165   id.nz_loc  = theMumpsSOE->nnz; 
00166   id.irn_loc = theMumpsSOE->rowA;
00167   id.jcn_loc = theMumpsSOE->colA;
00168   id.a_loc = theMumpsSOE->A;
00169 
00170   // Call the MUMPS package to analyze the system
00171   id.job = 1;
00172   dmumps_c(&id);
00173 
00174   // decrement row and col A values by 1 to return to C++ indexing
00175   for (int i=0; i<nnz; i++) {
00176     rowA[i]--;
00177     colA[i]--;
00178   }
00179 
00180   int info = id.infog[0];
00181   if (info != 0) {      
00182     opserr << "WARNING MumpsParallelSolver::setSize(void)- ";
00183     opserr << " Error " << info << " returned in substitution dmumps()\n";
00184     return info;
00185   }
00186   
00187   return info;
00188 }
00189 
00190 int
00191 MumpsParallelSolver::sendSelf(int cTag, Channel &theChannel)
00192 {
00193   // nothing to do
00194   return 0;
00195 }
00196 
00197 int
00198 MumpsParallelSolver::recvSelf(int ctag,
00199                       Channel &theChannel, 
00200                       FEM_ObjectBroker &theBroker)
00201 {
00202   // nothing to do
00203   return 0;
00204 }
00205 
00206 int 
00207 MumpsParallelSolver::setLinearSOE(MumpsParallelSOE &theSOE)
00208 {
00209   theMumpsSOE = &theSOE;
00210   return 0;
00211 }
00212 
00213 
00214 
00215 
00216 
00217 
00218 
00219 
00220 
00221 
00222 
00223 
00224 

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