42 #ifndef EPETRAEXT_MMHELPERS_H
43 #define EPETRAEXT_MMHELPERS_H
46 #include "Epetra_ConfigDefs.h"
47 #include "Epetra_DistObject.h"
48 #include "Epetra_Map.h"
49 #include "Teuchos_RCP.hpp"
50 #include "Epetra_Comm.h"
51 #include "Epetra_Import.h"
52 #include "Epetra_CrsMatrix.h"
53 #include <Teuchos_TimeMonitor.hpp>
63 class LightweightCrsMatrix;
115 virtual bool Filled() = 0;
117 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
118 virtual int InsertGlobalValues(
int GlobalRow,
int NumEntries,
double* Values,
int* Indices) = 0;
120 virtual int SumIntoGlobalValues(
int GlobalRow,
int NumEntries,
double* Values,
int* Indices) = 0;
123 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
124 virtual int InsertGlobalValues(
long long GlobalRow,
int NumEntries,
double* Values,
long long* Indices) = 0;
126 virtual int SumIntoGlobalValues(
long long GlobalRow,
int NumEntries,
double* Values,
long long* Indices) = 0;
140 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
145 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
146 int InsertGlobalValues(
long long GlobalRow,
int NumEntries,
double* Values,
long long* Indices);
147 int SumIntoGlobalValues(
long long GlobalRow,
int NumEntries,
double* Values,
long long* Indices);
155 template<
typename int_type>
165 int InsertGlobalValues(int_type GlobalRow,
int NumEntries,
double* Values, int_type* Indices);
166 int SumIntoGlobalValues(int_type GlobalRow,
int NumEntries,
double* Values, int_type* Indices);
168 std::map<int_type,std::set<int_type>*>&
get_graph();
173 std::map<int_type,std::set<int_type>*> graph_;
179 template<
typename int_type>
183 template<
typename int_type>
185 const std::vector<int_type>& proc_col_ranges,
186 std::vector<int_type>& send_rows,
187 std::vector<int>& rows_per_send_proc);
189 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
191 const std::vector<int>& proc_col_ranges,
192 std::vector<int>& send_rows,
193 std::vector<int>& rows_per_send_proc);
196 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
198 const std::vector<long long>& proc_col_ranges,
199 std::vector<long long>& send_rows,
200 std::vector<int>& rows_per_send_proc);
203 template<
typename int_type>
206 template<
typename int_type>
216 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
220 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
233 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
236 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
245 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
250 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
251 int LID(
long long GID)
const;
256 #if defined(EPETRA_NO_32BIT_GLOBAL_INDICES) && defined(EPETRA_NO_64BIT_GLOBAL_INDICES)
259 int LID(
long long GID)
const {
return -1; }
262 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
267 throw "EpetraExt::LightweightMap::IndexBase: IndexBase cannot fit an int.";
272 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
290 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
293 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
354 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
376 template <
typename ImportType,
typename int_type>
377 void Construct(
const Epetra_CrsMatrix & A, ImportType & RowImporter,
bool SortGhosts=
false,
const char * label=0);
381 int MakeColMapAndReindex(std::vector<int> owningPIDs,std::vector<GO> Gcolind,
bool SortGhosts=
false,
const char * label=0);
383 template<
typename int_type>
384 std::vector<int_type>& getcolind();
386 template<
typename ImportType,
typename int_type>
387 int PackAndPrepareReverseComm(
const Epetra_CrsMatrix & SourceMatrix, ImportType & RowImporter,
388 std::vector<int> &ReverseSendSizes, std::vector<int_type> &ReverseSendBuffer);
390 template<
typename ImportType,
typename int_type>
391 int MakeExportLists(
const Epetra_CrsMatrix & SourceMatrix, ImportType & RowImporter,
392 std::vector<int> &ReverseRecvSizes,
const int_type *ReverseRecvBuffer,
393 std::vector<int> & ExportPIDs, std::vector<int> & ExportLIDs);
397 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
398 template<>
inline std::vector<int>& LightweightCrsMatrix::getcolind() {
return colind_; }
400 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
401 template<>
inline std::vector<long long>& LightweightCrsMatrix::getcolind() {
return colind_LL_; }
405 template<
typename int_type>
409 const Epetra_Import * prototypeImporter=0,
bool SortGhosts=
false,
410 const char * label=0)
421 #ifdef ENABLE_MMM_TIMINGS
423 if(label) tpref = std::string(label);
424 using Teuchos::TimeMonitor;
425 Teuchos::RCP<Teuchos::TimeMonitor> MM = Teuchos::rcp(
new TimeMonitor(*TimeMonitor::getNewTimer(tpref + std::string(
"EpetraExt: MMM Ionly Setup"))));
436 Mview.
rowMap = &targetMap;
445 if(Mrowmap.
SameAs(targetMap)) {
451 else if(prototypeImporter && prototypeImporter->SourceMap().SameAs(M.
RowMap()) && prototypeImporter->TargetMap().SameAs(targetMap)){
452 numRemote = prototypeImporter->NumRemoteIDs();
457 const int * PermuteToLIDs = prototypeImporter->PermuteToLIDs();
458 const int * PermuteFromLIDs = prototypeImporter->PermuteFromLIDs();
459 const int * RemoteLIDs = prototypeImporter->RemoteLIDs();
461 for(i=0; i<prototypeImporter->NumSameIDs();i++)
465 for(i=0; i<prototypeImporter->NumPermuteIDs();i++)
468 for(i=0; i<prototypeImporter->NumRemoteIDs();i++)
473 throw std::runtime_error(
"import_only: This routine only works if you either have the right map or no prototypeImporter");
477 std::cerr <<
"EpetraExt::MatrixMatrix::Multiply ERROR, numProcs < 2 but "
478 <<
"attempting to import remote matrix rows."<<std::endl;
486 #ifdef ENABLE_MMM_TIMINGS
487 MM = Teuchos::rcp(
new TimeMonitor(*TimeMonitor::getNewTimer(tpref + std::string(
"EpetraExt: MMM Ionly Import-1"))));
489 const int * RemoteLIDs = prototypeImporter->RemoteLIDs();
492 int_type* MremoteRows = numRemote>0 ?
new int_type[prototypeImporter->NumRemoteIDs()] : 0;
493 for(i=0; i<prototypeImporter->NumRemoteIDs(); i++)
494 MremoteRows[i] = (int_type) targetMap.GID64(RemoteLIDs[i]);
496 LightweightMap MremoteRowMap((int_type) -1, numRemote, MremoteRows, (int_type)Mrowmap.IndexBase64());
498 #ifdef ENABLE_MMM_TIMINGS
499 MM = Teuchos::rcp(
new TimeMonitor(*TimeMonitor::getNewTimer(tpref + std::string(
"EpetraExt: MMM Ionly Import-2"))));
506 #ifdef ENABLE_MMM_TIMINGS
507 MM = Teuchos::rcp(
new TimeMonitor(*TimeMonitor::getNewTimer(tpref + std::string(
"EpetraExt: MMM Ionly Import-3"))));
512 #ifdef ENABLE_MMM_TIMINGS
513 MM = Teuchos::rcp(
new TimeMonitor(*TimeMonitor::getNewTimer(tpref + std::string(
"EpetraExt: MMM Ionly Import-4"))));
516 #ifdef ENABLE_MMM_STATISTICS
522 delete [] MremoteRows;