42#ifndef EPETRAEXT_MMHELPERS_H 
   43#define EPETRAEXT_MMHELPERS_H 
   45#if defined(EpetraExt_SHOW_DEPRECATED_WARNINGS) 
   47#warning "The EpetraExt package is deprecated" 
   52#include "Epetra_ConfigDefs.h" 
   53#include "Epetra_DistObject.h" 
   54#include "Epetra_Map.h" 
   55#include "Teuchos_RCP.hpp" 
   56#include "Epetra_Comm.h" 
   57#include "Epetra_Import.h" 
   58#include "Epetra_CrsMatrix.h" 
   59#include <Teuchos_TimeMonitor.hpp> 
   69class LightweightCrsMatrix;
 
  123#ifndef EPETRA_NO_32BIT_GLOBAL_INDICES 
  129#ifndef EPETRA_NO_64BIT_GLOBAL_INDICES 
  130  virtual int InsertGlobalValues(
long long GlobalRow, 
int NumEntries, 
double* Values, 
long long* Indices) = 0;
 
  132  virtual int SumIntoGlobalValues(
long long GlobalRow, 
int NumEntries, 
double* Values, 
long long* Indices) = 0;
 
 
  146#ifndef EPETRA_NO_32BIT_GLOBAL_INDICES 
  151#ifndef EPETRA_NO_64BIT_GLOBAL_INDICES 
  152  int InsertGlobalValues(
long long GlobalRow, 
int NumEntries, 
double* Values, 
long long* Indices);
 
  153  int SumIntoGlobalValues(
long long GlobalRow, 
int NumEntries, 
double* Values, 
long long* Indices);
 
 
  161template<
typename int_type>
 
  171  int InsertGlobalValues(int_type GlobalRow, 
int NumEntries, 
double* Values, int_type* Indices);
 
  172  int SumIntoGlobalValues(int_type GlobalRow, 
int NumEntries, 
double* Values, int_type* Indices);
 
  174  std::map<int_type,std::set<int_type>*>& 
get_graph();
 
  179  std::map<int_type,std::set<int_type>*> graph_;
 
 
  185template<
typename int_type>
 
  189template<
typename int_type>
 
  191                        const std::vector<int_type>& proc_col_ranges,
 
  192                        std::vector<int_type>& send_rows,
 
  193                        std::vector<int>& rows_per_send_proc);
 
  195#ifndef EPETRA_NO_32BIT_GLOBAL_INDICES 
  197                        const std::vector<int>& proc_col_ranges,
 
  198                        std::vector<int>& send_rows,
 
  199                        std::vector<int>& rows_per_send_proc);
 
  202#ifndef EPETRA_NO_64BIT_GLOBAL_INDICES 
  204                        const std::vector<long long>& proc_col_ranges,
 
  205                        std::vector<long long>& send_rows,
 
  206                        std::vector<int>& rows_per_send_proc);
 
  209template<
typename int_type>
 
  212template<
typename int_type>
 
  222#ifndef EPETRA_NO_32BIT_GLOBAL_INDICES 
  226#ifndef EPETRA_NO_64BIT_GLOBAL_INDICES 
 
  239#ifndef EPETRA_NO_32BIT_GLOBAL_INDICES 
  242#ifndef EPETRA_NO_64BIT_GLOBAL_INDICES 
  251#ifndef EPETRA_NO_32BIT_GLOBAL_INDICES 
  256#ifndef EPETRA_NO_64BIT_GLOBAL_INDICES 
  257  int  LID(
long long GID) 
const;
 
  262#if defined(EPETRA_NO_32BIT_GLOBAL_INDICES) && defined(EPETRA_NO_64BIT_GLOBAL_INDICES) 
  265  int  LID(
long long GID)
 const { 
return -1; }
 
  268#ifndef EPETRA_NO_32BIT_GLOBAL_INDICES 
  273    throw "EpetraExt::LightweightMap::IndexBase: IndexBase cannot fit an int.";
 
 
  278#ifndef EPETRA_NO_64BIT_GLOBAL_INDICES 
  296#ifndef EPETRA_NO_32BIT_GLOBAL_INDICES 
  299#ifndef EPETRA_NO_64BIT_GLOBAL_INDICES 
 
  360#ifndef EPETRA_NO_64BIT_GLOBAL_INDICES 
  382  template <
typename ImportType, 
typename int_type>
 
  383    void Construct(
const Epetra_CrsMatrix & A, ImportType & RowImporter,
bool SortGhosts=
false, 
const char * label=0);
 
  387    int MakeColMapAndReindex(std::vector<int> owningPIDs,std::vector<GO> Gcolind,
bool SortGhosts=
false, 
const char * label=0);
 
  389  template<
typename int_type>
 
  390  std::vector<int_type>& getcolind();
 
  392  template<
typename ImportType, 
typename int_type>
 
  393  int PackAndPrepareReverseComm(
const Epetra_CrsMatrix & SourceMatrix, ImportType & RowImporter,
 
  394        std::vector<int> &ReverseSendSizes, std::vector<int_type> &ReverseSendBuffer);
 
  396  template<
typename ImportType, 
typename int_type>
 
  397  int MakeExportLists(
const Epetra_CrsMatrix & SourceMatrix, ImportType & RowImporter,
 
  398          std::vector<int> &ReverseRecvSizes, 
const int_type *ReverseRecvBuffer,
 
  399          std::vector<int> & ExportPIDs, std::vector<int> & ExportLIDs);
 
 
  403#ifndef EPETRA_NO_32BIT_GLOBAL_INDICES 
  404template<> 
inline std::vector<int>& LightweightCrsMatrix::getcolind() { 
return colind_; }
 
  406#ifndef EPETRA_NO_64BIT_GLOBAL_INDICES 
  407template<> 
inline std::vector<long long>& LightweightCrsMatrix::getcolind() { 
return colind_LL_; }
 
  411template<
typename int_type>
 
  415                const Epetra_Import * prototypeImporter=0,
bool SortGhosts=
false,
 
  416    const char * label=0)
 
  427#ifdef ENABLE_MMM_TIMINGS 
  429  if(label) tpref = std::string(label);
 
  430  using Teuchos::TimeMonitor;
 
  431  Teuchos::RCP<Teuchos::TimeMonitor> MM = Teuchos::rcp(
new TimeMonitor(*TimeMonitor::getNewTimer(tpref + std::string(
"EpetraExt: MMM Ionly Setup"))));
 
  442  Mview.
rowMap       = &targetMap;
 
  451  if(Mrowmap.
SameAs(targetMap)) {
 
  457  else if(prototypeImporter && prototypeImporter->SourceMap().SameAs(M.
RowMap()) && prototypeImporter->TargetMap().SameAs(targetMap)){
 
  458    numRemote = prototypeImporter->NumRemoteIDs();
 
  463    const int * PermuteToLIDs   = prototypeImporter->PermuteToLIDs();
 
  464    const int * PermuteFromLIDs = prototypeImporter->PermuteFromLIDs();
 
  465    const int * RemoteLIDs      = prototypeImporter->RemoteLIDs();
 
  467    for(i=0; i<prototypeImporter->NumSameIDs();i++)
 
  471    for(i=0; i<prototypeImporter->NumPermuteIDs();i++)
 
  474    for(i=0; i<prototypeImporter->NumRemoteIDs();i++)
 
  479    throw std::runtime_error(
"import_only: This routine only works if you either have the right map or no prototypeImporter");
 
  483      std::cerr << 
"EpetraExt::MatrixMatrix::Multiply ERROR, numProcs < 2 but " 
  484           << 
"attempting to import remote matrix rows."<<std::endl;
 
  492#ifdef ENABLE_MMM_TIMINGS 
  493  MM = Teuchos::rcp(
new TimeMonitor(*TimeMonitor::getNewTimer(tpref + std::string(
"EpetraExt: MMM Ionly Import-1"))));
 
  495  const int * RemoteLIDs = prototypeImporter->RemoteLIDs();
 
  498  int_type* MremoteRows = numRemote>0 ? 
new int_type[prototypeImporter->NumRemoteIDs()] : 0;
 
  499  for(i=0; i<prototypeImporter->NumRemoteIDs(); i++)
 
  500    MremoteRows[i] = (int_type) targetMap.GID64(RemoteLIDs[i]);
 
  502  LightweightMap MremoteRowMap((int_type) -1, numRemote, MremoteRows, (int_type)Mrowmap.IndexBase64());
 
  504#ifdef ENABLE_MMM_TIMINGS 
  505  MM = Teuchos::rcp(
new TimeMonitor(*TimeMonitor::getNewTimer(tpref + std::string(
"EpetraExt: MMM Ionly Import-2"))));
 
  512#ifdef ENABLE_MMM_TIMINGS 
  513  MM = Teuchos::rcp(
new TimeMonitor(*TimeMonitor::getNewTimer(tpref + std::string(
"EpetraExt: MMM Ionly Import-3"))));
 
  518#ifdef ENABLE_MMM_TIMINGS 
  519  MM = Teuchos::rcp(
new TimeMonitor(*TimeMonitor::getNewTimer(tpref + std::string(
"EpetraExt: MMM Ionly Import-4"))));
 
  522#ifdef ENABLE_MMM_STATISTICS 
  528  delete [] MremoteRows;
 
 
virtual ~CrsMatrixStruct()
 
const Epetra_CrsMatrix * origMatrix
 
const Epetra_Map * rowMap
 
std::vector< int > targetMapToImportRow
 
const Epetra_Map * colMap
 
const Epetra_Map * domainMap
 
LightweightCrsMatrix * importMatrix
 
const Epetra_BlockMap * importColMap
 
std::vector< int > targetMapToOrigRow
 
const Epetra_Map * origRowMap
 
const Epetra_Map & RowMap() const
 
int SumIntoGlobalValues(int GlobalRow, int NumEntries, double *Values, int *Indices)
 
virtual ~CrsWrapper_Epetra_CrsMatrix()
 
int InsertGlobalValues(int GlobalRow, int NumEntries, double *Values, int *Indices)
 
std::map< int_type, std::set< int_type > * > & get_graph()
 
const Epetra_Map & RowMap() const
 
virtual ~CrsWrapper_GraphBuilder()
 
int InsertGlobalValues(int_type GlobalRow, int NumEntries, double *Values, int_type *Indices)
 
int SumIntoGlobalValues(int_type GlobalRow, int NumEntries, double *Values, int_type *Indices)
 
virtual const Epetra_Map & RowMap() const =0
 
virtual int InsertGlobalValues(long long GlobalRow, int NumEntries, double *Values, long long *Indices)=0
 
virtual int SumIntoGlobalValues(long long GlobalRow, int NumEntries, double *Values, long long *Indices)=0
 
virtual int InsertGlobalValues(int GlobalRow, int NumEntries, double *Values, int *Indices)=0
 
virtual int SumIntoGlobalValues(int GlobalRow, int NumEntries, double *Values, int *Indices)=0
 
Epetra_BlockMap * RowMapEP_
 
std::vector< double > vals_
 
std::vector< int > ExportPIDs_
 
LightweightMap * RowMapLW_
 
std::vector< long long > colind_LL_
 
std::vector< int > ColMapOwningPIDs_
 
std::vector< int > colind_
 
std::vector< int > ExportLIDs_
 
std::vector< int > rowptr_
 
std::vector< long long > MyGlobalElements_LL_
 
Epetra_HashTable< int > * LIDHash_int_
 
Epetra_HashTable< long long > * LIDHash_LL_
 
std::vector< int > MyGlobalElements_int_
 
bool GlobalIndicesInt() const
 
LightweightMap & operator=(const LightweightMap &map)
 
long long GID64(int LID) const
 
long long * MyGlobalElements64() const
 
int * MyGlobalElements() const
 
long long IndexBase64() const
 
bool GlobalIndicesLongLong() const
 
void MyGlobalElementsPtr(int *&MyGlobalElementList) const
 
int NumMyElements() const
 
const LightweightMap & TargetMap() const
 
Epetra_Distributor & Distributor()
 
const Epetra_BlockMap & SourceMap() const
 
bool SameAs(const Epetra_BlockMap &Map) const
 
const Epetra_Comm & Comm() const
 
int NumMyElements() const
 
virtual int NumProc() const=0
 
const Epetra_Map & RowMap() const
 
const Epetra_Map & ColMap() const
 
const Epetra_Map & DomainMap() const
 
EpetraExt::BlockCrsMatrix: A class for constructing a distributed block matrix.
 
void insert_matrix_locations(CrsWrapper_GraphBuilder< int_type > &graphbuilder, Epetra_CrsMatrix &C)
 
void pack_outgoing_rows(const Epetra_CrsMatrix &mtx, const std::vector< int > &proc_col_ranges, std::vector< int > &send_rows, std::vector< int > &rows_per_send_proc)
 
void PrintMultiplicationStatistics(Epetra_Import *Transfer, const std::string &label)
 
void printMultiplicationStatistics(Epetra_Import *Transfer, const std::string &label)
 
int import_only(const Epetra_CrsMatrix &M, const Epetra_Map &targetMap, CrsMatrixStruct &Mview, const Epetra_Import *prototypeImporter)
 
std::pair< int_type, int_type > get_col_range(const Epetra_Map &emap)
 
int dumpCrsMatrixStruct(const CrsMatrixStruct &M)
 
void Tpack_outgoing_rows(const Epetra_CrsMatrix &mtx, const std::vector< int_type > &proc_col_ranges, std::vector< int_type > &send_rows, std::vector< int > &rows_per_send_proc)