EpetraExt_ZoltanOrder_CrsGraph.cpp

Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //     EpetraExt: Epetra Extended - Linear Algebra Services Package
00005 //                 Copyright (2001) 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 #ifdef ZOLTAN_ORDER
00030 
00031 #include <EpetraExt_ZoltanOrder_CrsGraph.h>
00032 
00033 #include <EpetraExt_Transpose_CrsGraph.h>
00034 
00035 #include <EpetraExt_ZoltanQuery.h>
00036 #include <Zoltan_LoadBalance.h>
00037 
00038 #include <Epetra_CrsGraph.h>
00039 #include <Epetra_Map.h>
00040 #include <Epetra_Import.h>
00041 
00042 #include <Epetra_MpiComm.h>
00043 
00044 #include <vector>
00045 #include <set>
00046 
00047 using std::vector;
00048 using std::set;
00049 
00050 namespace EpetraExt {
00051 
00052 ZoltanOrder_CrsGraph::
00053 ~ZoltanOrder_CrsGraph()
00054 {
00055   if( newObj_ ) delete newObj_;
00056   if( NewRowMap_ ) delete NewRowMap_;
00057 }
00058 
00059 ZoltanOrder_CrsGraph::NewTypeRef
00060 ZoltanOrder_CrsGraph::
00061 operator()( OriginalTypeRef orig )
00062 {
00063   origObj_ = &orig;
00064 
00065   int err;
00066 
00067   //Setup Load Balance Object
00068   float version;
00069   char * dummy = 0;
00070   Zoltan::LoadBalance LB( 0, &dummy, &version );
00071   err = LB.Create( dynamic_cast<const Epetra_MpiComm&>(orig.Comm()).Comm() );
00072   LB.Set_Param( "ORDER_METHOD", "METIS" );
00073   LB.Set_Param( "ORDER_TYPE", "LOCAL" );
00074 
00075   //Setup Query Object
00076   CrsGraph_Transpose transposeTransform;
00077   Epetra_CrsGraph & TransGraph = transposeTransform( orig );
00078   ZoltanQuery Query( orig, &TransGraph, true );
00079   if( err == ZOLTAN_OK ) err = LB.Set_QueryObject( &Query );
00080 
00081   if( err != ZOLTAN_OK )
00082   { cout << "Setup of Zoltan Load Balancing Objects FAILED!\n"; exit(0); }
00083 
00084   //Generate Reorder
00085   int num_elements = orig.RowMap().NumMyElements();
00086   int num_gid_entries, num_lid_entries;
00087   vector<ZOLTAN_ID_TYPE> global_ids(num_elements,0);
00088   vector<ZOLTAN_ID_TYPE> local_ids(num_elements,0);
00089   vector<int> rank(num_elements);
00090   vector<int> iperm(num_elements);
00091 
00092   orig.Comm().Barrier();
00093   err = LB.Order( &num_gid_entries,
00094                    &num_lid_entries,
00095                    num_elements,
00096                    &global_ids[0],
00097                    &local_ids[0],
00098                    &rank[0],
00099                    &iperm[0] );
00100   orig.Comm().Barrier();
00101 
00102 #ifdef EDT_ZOLTANORDER_DEBUG
00103 cout << "------------------------------\n";
00104 cout << "#GIDs: " << num_gid_entries << endl;
00105 cout << "#LIDs: " << num_lid_entries << endl;
00106 cout << "GIDs and LIDs\n";
00107 for( int i = 0; i < num_elements; ++i ) cout << global_ids[i] << " " << local_ids[i] << endl;
00108 cout << "Rank and Perm\n";
00109 for( int i = 0; i < num_elements; ++i ) cout << rank[i] << " " << iperm[i] << endl;
00110 cout << "------------------------------\n";
00111 #endif
00112 
00113   //Generate New Row Map
00114   vector<int> gids(num_elements);
00115   for( int i = 0; i < num_elements; ++i )
00116     gids[ (num_elements-1) - rank[i] ] = global_ids[i];
00117   NewRowMap_ = new Epetra_Map( orig.RowMap().NumGlobalElements(),
00118                                            num_elements,
00119                                            &gids[0],
00120                                            orig.RowMap().IndexBase(),
00121                                            orig.RowMap().Comm() );
00122 
00123   //Create Importer
00124   Epetra_Import Importer( *NewRowMap_, orig.RowMap() );
00125 
00126   //Create New Graph
00127   Epetra_CrsGraph * NewGraph( new Epetra_CrsGraph( Copy, *NewRowMap_, 0 ) );
00128   NewGraph->Import( orig, Importer, Insert );
00129   NewGraph->FillComplete( true );
00130   
00131   newObj_ = NewGraph;
00132 
00133   return NewGraph;
00134 }
00135 
00136 } // namespace EpetraExt
00137 
00138 #endif //ZOLTAN_ORDER

Generated on Thu Sep 18 12:31:44 2008 for EpetraExt by doxygen 1.3.9.1