Ifpack_ex_Reordering.cpp

Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //                IFPACK
00005 //                 Copyright (2004) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 
00029 #include "Ifpack_ConfigDefs.h"
00030 #ifdef HAVE_MPI
00031 #include "Epetra_MpiComm.h"
00032 #else
00033 #include "Epetra_SerialComm.h"
00034 #endif
00035 #include "Epetra_Map.h"
00036 #include "Epetra_CrsMatrix.h"
00037 #include "Ifpack_Reordering.h"
00038 #include "Ifpack_RCMReordering.h"
00039 #include "Ifpack_ReorderFilter.h"
00040 #include "Ifpack_Utils.h"
00041 #include "Teuchos_RefCountPtr.hpp"
00042 
00043 //==============================================================================
00044 int main(int argc, char *argv[])
00045 {
00046 
00047 #ifdef HAVE_MPI
00048   MPI_Init(&argc,&argv);
00049   Epetra_MpiComm Comm(MPI_COMM_WORLD);
00050 #else
00051   Epetra_SerialComm Comm;
00052 #endif
00053 
00054   // only one process
00055   if (Comm.NumProc() != 1) {
00056 #ifdef HAVE_MPI
00057     MPI_Finalize();
00058 #endif
00059     if (Comm.MyPID() == 0)
00060       cout << "Please run this test with one process only" << endl;
00061     // return success not to break the tests
00062     exit(EXIT_SUCCESS);
00063   }
00064 
00065   // ======================================================== //
00066   // now create the famous "upper arrow" matrix, which        //
00067   // should be reordered as a "lower arrow". Sparsity pattern //
00068   // will be printed on screen.                               //
00069   // ======================================================== //
00070   
00071   int NumPoints = 16;
00072   
00073   Epetra_Map Map(-1,NumPoints,0,Comm);
00074   
00075   vector<int> Indices(NumPoints);
00076   vector<double> Values(NumPoints);
00077 
00078   Teuchos::RefCountPtr<Epetra_CrsMatrix> A = Teuchos::rcp( new Epetra_CrsMatrix(Copy,Map,0) );
00079   for (int i = 0 ; i < NumPoints ; ++i) {
00080     
00081     int NumEntries;
00082     if (i == 0) {
00083       NumEntries = NumPoints;
00084       for (int j = 0 ; j < NumPoints ; ++j) {
00085   Indices[j] = j;
00086   Values[j] = 1.0;
00087       }
00088     }
00089     else {
00090       NumEntries = 2;
00091       Indices[0] = 0;
00092       Indices[1] = i;
00093       Values[0] = 1.0;
00094       Values[1] = 1.0;
00095     }
00096 
00097     A->InsertGlobalValues(i, NumEntries, &Values[0], &Indices[0]);
00098   }
00099 
00100   A->FillComplete();
00101 
00102   // print the sparsity to file, postscript format
00104 
00105   // create the reordering...
00106   Teuchos::RefCountPtr<Ifpack_RCMReordering> Reorder = Teuchos::rcp( new Ifpack_RCMReordering() );
00107   // and compute is on A
00108   IFPACK_CHK_ERR(Reorder->Compute(*A));
00109 
00110   // cout information
00111   cout << *Reorder;
00112 
00113   // create a reordered matrix
00114   Ifpack_ReorderFilter ReordA(A, Reorder);
00115 
00116   // print the sparsity to file, postscript format
00118 
00119 #ifdef HAVE_MPI
00120   MPI_Finalize(); 
00121 #endif
00122   return(EXIT_SUCCESS);
00123 
00124 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Wed Apr 13 10:05:34 2011 for Ifpack Package Browser (Single Doxygen Collection) by  doxygen 1.6.3