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>
69 class LightweightCrsMatrix;
121 virtual bool Filled() = 0;
123 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
124 virtual int InsertGlobalValues(
int GlobalRow,
int NumEntries,
double* Values,
int* Indices) = 0;
126 virtual int SumIntoGlobalValues(
int GlobalRow,
int NumEntries,
double* Values,
int* Indices) = 0;
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);
161 template<
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_;
185 template<
typename int_type>
189 template<
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);
209 template<
typename int_type>
212 template<
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
243 LightweightMap(
long long NumGlobalElements,
int NumMyElements,
const long long * MyGlobalElements,
int IndexBase,
bool GenerateHash=
true);
244 LightweightMap(
long long NumGlobalElements,
int NumMyElements,
const long long * MyGlobalElements,
long long IndexBase,
bool GenerateHash=
true);
251 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
253 int GID(
int LID)
const;
256 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
257 int LID(
long long GID)
const;
259 long long GID64(
int LID)
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
297 void Construct_int(
int NumGlobalElements,
int NumMyElements,
const int * MyGlobalElements,
long long IndexBase,
bool GenerateHash=
true);
299 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
300 void Construct_LL(
long long NumGlobalElements,
int NumMyElements,
const long long * MyGlobalElements,
long long IndexBase,
bool GenerateHash=
true);
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
404 template<>
inline std::vector<int>& LightweightCrsMatrix::getcolind() {
return colind_; }
406 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
407 template<>
inline std::vector<long long>& LightweightCrsMatrix::getcolind() {
return colind_LL_; }
411 template<
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;
int SumIntoGlobalValues(int_type GlobalRow, int NumEntries, double *Values, int_type *Indices)
LightweightCrsMatrix * importMatrix
RemoteOnlyImport(const Epetra_Import &Importer, LightweightMap &RemoteOnlyTargetMap)
Epetra_HashTable< long long > * LIDHash_LL_
Epetra_BlockMap * RowMapEP_
std::vector< int > targetMapToOrigRow
long long * MyGlobalElements64() const
virtual ~CrsWrapper_GraphBuilder()
virtual int SumIntoGlobalValues(int GlobalRow, int NumEntries, double *Values, int *Indices)=0
void MyGlobalElementsPtr(int *&MyGlobalElementList) const
void PrintMultiplicationStatistics(Epetra_Import *Transfer, const std::string &label)
bool SameAs(const Epetra_BlockMap &Map) const
LightweightMap * RowMapLW_
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)
const Epetra_Map * rowMap
long long GID64(int LID) const
virtual int InsertGlobalValues(int GlobalRow, int NumEntries, double *Values, int *Indices)=0
std::vector< int > colind_
void printMultiplicationStatistics(Epetra_Import *Transfer, const std::string &label)
std::vector< int > ExportPIDs_
const Epetra_Map & ColMap() const
const Epetra_CrsMatrix * origMatrix
const Epetra_Map & RowMap() const
const Epetra_Map & RowMap() const
int NumMyElements() const
const Epetra_Map * origRowMap
int InsertGlobalValues(int GlobalRow, int NumEntries, double *Values, int *Indices)
std::vector< int > targetMapToImportRow
virtual const Epetra_Map & RowMap() const =0
int NumMyElements() const
LightweightMap & operator=(const LightweightMap &map)
virtual ~CrsWrapper_Epetra_CrsMatrix()
const Epetra_Map * domainMap
int SumIntoGlobalValues(int GlobalRow, int NumEntries, double *Values, int *Indices)
const Epetra_Map & RowMap() const
std::vector< double > vals_
CrsWrapper_Epetra_CrsMatrix(Epetra_CrsMatrix &epetracrsmatrix)
const Epetra_Comm & Comm() const
std::vector< int > MyGlobalElements_int_
const Epetra_BlockMap & SourceMap() const
long long IndexBase64() const
int * MyGlobalElements() const
virtual int NumProc() const =0
const LightweightMap & TargetMap() const
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)
CrsWrapper_GraphBuilder(const Epetra_Map &emap)
const Epetra_Map & DomainMap() const
virtual ~CrsMatrixStruct()
bool GlobalIndicesInt() const
Epetra_HashTable< int > * LIDHash_int_
std::vector< long long > MyGlobalElements_LL_
LightweightCrsMatrix(const Epetra_CrsMatrix &A, RemoteOnlyImport &RowImporter, bool SortGhosts=false, const char *label=0)
Epetra_Distributor & Distributor()
std::map< int_type, std::set< int_type > * > & get_graph()
std::vector< int > ColMapOwningPIDs_
std::vector< int > ExportLIDs_
std::vector< int > rowptr_
const Epetra_Map * colMap
const Epetra_BlockMap * importColMap
void insert_matrix_locations(CrsWrapper_GraphBuilder< int_type > &graphbuilder, Epetra_CrsMatrix &C)
int dumpCrsMatrixStruct(const CrsMatrixStruct &M)
int import_only(const Epetra_CrsMatrix &M, const Epetra_Map &targetMap, CrsMatrixStruct &Mview, const Epetra_Import *prototypeImporter)
int InsertGlobalValues(int_type GlobalRow, int NumEntries, double *Values, int_type *Indices)
std::vector< long long > colind_LL_
bool GlobalIndicesLongLong() const
std::pair< int_type, int_type > get_col_range(const Epetra_Map &emap)