43 #include "Ifpack_Euclid.h"
44 #if defined(HAVE_EUCLID) && defined(HAVE_MPI)
48 #include "Epetra_MpiComm.h"
49 #include "Epetra_IntVector.h"
50 #include "Epetra_Import.h"
51 #include "Teuchos_ParameterList.hpp"
52 #include "Teuchos_RCP.hpp"
53 #include "getRow_dh.h"
58 Ifpack_Euclid::Ifpack_Euclid(Epetra_CrsMatrix* A):
62 IsInitialized_(false),
70 ApplyInverseTime_(0.0),
72 ApplyInverseFlops_(0.0),
84 for(
int i = 0; i < A_->NumMyRows(); i++){
87 A_->Graph().ExtractMyRowView(i, len, indices);
88 for(
int j = 0; j < len; j++){
89 indices[j] = A_->GCID(indices[j]);
95 void Ifpack_Euclid::Destroy(){
102 Parser_dhDestroy(parser_dh);
104 TimeLog_dhDestroy(tlog_dh);
106 Mem_dhDestroy(mem_dh);
110 for(
int i = 0; i < A_->NumMyRows(); i++){
113 A_->Graph().ExtractMyRowView(i, len, indices);
114 for(
int j = 0; j < len; j++){
115 indices[j] = A_->LCID(indices[j]);
121 int Ifpack_Euclid::Initialize(){
123 comm_dh = GetMpiComm();
124 MPI_Comm_size(comm_dh, &np_dh);
125 MPI_Comm_rank(comm_dh, &myid_dh);
126 Time_.ResetStartTime();
128 Mem_dhCreate(&mem_dh);
130 if (tlog_dh == NULL) {
131 TimeLog_dhCreate(&tlog_dh);
134 if (parser_dh == NULL) {
135 Parser_dhCreate(&parser_dh);
137 Parser_dhInit(parser_dh, 0, NULL);
139 Euclid_dhCreate(&eu);
141 NumInitialize_ = NumInitialize_ + 1;
142 InitializeTime_ = InitializeTime_ + Time_.ElapsedTime();
147 int Ifpack_Euclid::SetParameters(Teuchos::ParameterList& list){
149 SetLevel_ = list.get(
"SetLevel", (
int)1);
150 SetBJ_ = list.get(
"SetBJ", (
int)0);
151 SetStats_ = list.get(
"SetStats", (
int)0);
152 SetMem_ = list.get(
"SetMem", (
int)0);
153 SetSparse_ = list.get(
"SetSparse", (
double)0.0);
154 SetRowScale_ = list.get(
"SetRowScale", (
int)0);
155 SetILUT_ = list.get(
"SetILUT", (
double)0.0);
160 int Ifpack_Euclid::SetParameter(
string name,
int value){
163 for(
size_t i = 0; i < name.length(); i++){
164 name[i] = (char) tolower(name[i], loc);
166 if(name.compare(
"setlevel") == 0){
168 }
else if(name.compare(
"setbj") == 0){
170 }
else if(name.compare(
"setstats") == 0){
172 }
else if(name.compare(
"setmem") == 0){
174 }
else if(name.compare(
"setrowscale") == 0){
175 SetRowScale_ = value;
177 cout <<
"\nThe string " << name <<
" is not an available option.\n";
184 int Ifpack_Euclid::SetParameter(
string name,
double value){
187 for(
size_t i; i < name.length(); i++){
188 name[i] = (char) tolower(name[i], loc);
190 if(name.compare(
"setsparse") == 0){
192 }
else if(name.compare(
"setilut") == 0){
195 cout <<
"\nThe string " << name <<
" is not an available option.\n";
202 int Ifpack_Euclid::Compute(){
203 if(IsInitialized() ==
false){
204 IFPACK_CHK_ERR(Initialize());
206 Time_.ResetStartTime();
207 sprintf(Label_,
"IFPACK_Euclid (level=%d, bj=%d, stats=%d, mem=%d, sparse=%f, rowscale=%d, ilut=%f)",
208 SetLevel_, SetBJ_, SetStats_, SetMem_, SetSparse_, SetRowScale_, SetILUT_);
210 eu->level = SetLevel_;
212 strcpy(
"bj", eu->algo_par);
214 if(SetSparse_ != 0.0){
215 eu->sparseTolA = SetSparse_;
217 if(SetRowScale_ != 0){
221 eu->droptol = SetILUT_;
223 if(SetStats_ != 0 || SetMem_ != 0){
225 Parser_dhInsert(parser_dh,
"-eu_stats",
"1");
228 eu->A = (
void*) A_.get();
229 eu->m = A_->NumMyRows();
230 eu->n = A_->NumGlobalRows();
233 NumCompute_ = NumCompute_ + 1;
234 ComputeTime_ = ComputeTime_ + Time_.ElapsedTime();
239 int Ifpack_Euclid::ApplyInverse(
const Epetra_MultiVector& X, Epetra_MultiVector& Y)
const{
240 if(IsComputed() ==
false){
243 int NumVectors = X.NumVectors();
244 if(NumVectors != Y.NumVectors()){
247 Time_.ResetStartTime();
249 for(
int vecNum = 0; vecNum < NumVectors; vecNum++){
250 CallEuclid(X[vecNum], Y[vecNum]);
253 Euclid_dhPrintTestData(eu, stdout);
255 NumApplyInverse_ = NumApplyInverse_ + 1;
256 ApplyInverseTime_ = ApplyInverseTime_ + Time_.ElapsedTime();
261 int Ifpack_Euclid::CallEuclid(
double *x,
double *y)
const{
262 Euclid_dhApply(eu, x, y);
267 ostream& operator << (ostream& os,
const Ifpack_Euclid& A){
268 if (!A.Comm().MyPID()) {
270 os <<
"================================================================================" << endl;
271 os <<
"Ifpack_Euclid: " << A.Label () << endl << endl;
272 os <<
"Using " << A.Comm().NumProc() <<
" processors." << endl;
273 os <<
"Global number of rows = " << A.Matrix().NumGlobalRows() << endl;
274 os <<
"Global number of nonzeros = " << A.Matrix().NumGlobalNonzeros() << endl;
275 os <<
"Condition number estimate = " << A.Condest() << endl;
277 os <<
"Phase # calls Total Time (s) Total MFlops MFlops/s" << endl;
278 os <<
"----- ------- -------------- ------------ --------" << endl;
279 os <<
"Initialize() " << std::setw(5) << A.NumInitialize()
280 <<
" " << std::setw(15) << A.InitializeTime()
281 <<
" 0.0 0.0" << endl;
282 os <<
"Compute() " << std::setw(5) << A.NumCompute()
283 <<
" " << std::setw(15) << A.ComputeTime()
284 <<
" " << std::setw(15) << 1.0e-6 * A.ComputeFlops();
285 if (A.ComputeTime() != 0.0)
286 os <<
" " << std::setw(15) << 1.0e-6 * A.ComputeFlops() / A.ComputeTime() << endl;
288 os <<
" " << std::setw(15) << 0.0 << endl;
289 os <<
"ApplyInverse() " << std::setw(5) << A.NumApplyInverse()
290 <<
" " << std::setw(15) << A.ApplyInverseTime()
291 <<
" " << std::setw(15) << 1.0e-6 * A.ApplyInverseFlops();
292 if (A.ApplyInverseTime() != 0.0)
293 os <<
" " << std::setw(15) << 1.0e-6 * A.ApplyInverseFlops() / A.ApplyInverseTime() << endl;
295 os <<
" " << std::setw(15) << 0.0 << endl;
296 os <<
"================================================================================" << endl;
303 double Ifpack_Euclid::Condest(
const Ifpack_CondestType CT,
306 Epetra_RowMatrix* Matrix_in){
312 #endif // HAVE_EUCLID && HAVE_MPI