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"
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(std::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;
180 cout <<
"\nThe string " << name <<
" is not an available option." << endl;
187 int Ifpack_Euclid::SetParameter(std::string name,
double value){
190 for(
size_t i; i < name.length(); i++){
191 name[i] = (char) tolower(name[i], loc);
193 if(name.compare(
"setsparse") == 0){
195 }
else if(name.compare(
"setilut") == 0){
201 cout <<
"\nThe string " << name <<
" is not an available option." << endl;
208 int Ifpack_Euclid::Compute(){
209 if(IsInitialized() ==
false){
210 IFPACK_CHK_ERR(Initialize());
212 Time_.ResetStartTime();
213 sprintf(Label_,
"IFPACK_Euclid (level=%d, bj=%d, stats=%d, mem=%d, sparse=%f, rowscale=%d, ilut=%f)",
214 SetLevel_, SetBJ_, SetStats_, SetMem_, SetSparse_, SetRowScale_, SetILUT_);
216 eu->level = SetLevel_;
218 strcpy(
"bj", eu->algo_par);
220 if(SetSparse_ != 0.0){
221 eu->sparseTolA = SetSparse_;
223 if(SetRowScale_ != 0){
227 eu->droptol = SetILUT_;
229 if(SetStats_ != 0 || SetMem_ != 0){
231 Parser_dhInsert(parser_dh,
"-eu_stats",
"1");
234 eu->A = (
void*) A_.get();
235 eu->m = A_->NumMyRows();
236 eu->n = A_->NumGlobalRows();
239 NumCompute_ = NumCompute_ + 1;
240 ComputeTime_ = ComputeTime_ + Time_.ElapsedTime();
246 if(IsComputed() ==
false){
249 int NumVectors = X.NumVectors();
250 if(NumVectors != Y.NumVectors()){
253 Time_.ResetStartTime();
255 for(
int vecNum = 0; vecNum < NumVectors; vecNum++){
256 CallEuclid(X[vecNum], Y[vecNum]);
259 Euclid_dhPrintTestData(eu, stdout);
261 NumApplyInverse_ = NumApplyInverse_ + 1;
262 ApplyInverseTime_ = ApplyInverseTime_ + Time_.ElapsedTime();
267 int Ifpack_Euclid::CallEuclid(
double *x,
double *y)
const{
268 Euclid_dhApply(eu, x, y);
273 std::ostream& operator << (std::ostream& os,
const Ifpack_Euclid& A){
274 if (!A.Comm().MyPID()) {
276 os <<
"================================================================================" << endl;
277 os <<
"Ifpack_Euclid: " << A.Label () << endl << endl;
278 os <<
"Using " << A.Comm().NumProc() <<
" processors." << endl;
279 os <<
"Global number of rows = " << A.Matrix().NumGlobalRows() << endl;
280 os <<
"Global number of nonzeros = " << A.Matrix().NumGlobalNonzeros() << endl;
281 os <<
"Condition number estimate = " << A.Condest() << endl;
283 os <<
"Phase # calls Total Time (s) Total MFlops MFlops/s" << endl;
284 os <<
"----- ------- -------------- ------------ --------" << endl;
285 os <<
"Initialize() " << std::setw(5) << A.NumInitialize()
286 <<
" " << std::setw(15) << A.InitializeTime()
287 <<
" 0.0 0.0" << endl;
288 os <<
"Compute() " << std::setw(5) << A.NumCompute()
289 <<
" " << std::setw(15) << A.ComputeTime()
290 <<
" " << std::setw(15) << 1.0e-6 * A.ComputeFlops();
291 if (A.ComputeTime() != 0.0)
292 os <<
" " << std::setw(15) << 1.0e-6 * A.ComputeFlops() / A.ComputeTime() << endl;
294 os <<
" " << std::setw(15) << 0.0 << endl;
295 os <<
"ApplyInverse() " << std::setw(5) << A.NumApplyInverse()
296 <<
" " << std::setw(15) << A.ApplyInverseTime()
297 <<
" " << std::setw(15) << 1.0e-6 * A.ApplyInverseFlops();
298 if (A.ApplyInverseTime() != 0.0)
299 os <<
" " << std::setw(15) << 1.0e-6 * A.ApplyInverseFlops() / A.ApplyInverseTime() << endl;
301 os <<
" " << std::setw(15) << 0.0 << endl;
302 os <<
"================================================================================" << endl;
309 double Ifpack_Euclid::Condest(
const Ifpack_CondestType CT,
318 #endif // HAVE_EUCLID && HAVE_MPI