/*********************************************************************** * Method: DistanceDistributionAnalysis::deserialiseAdditional * Params: const picojson::value &v * Returns: bool * Effects: ***********************************************************************/ bool DistanceDistributionAnalysis::deserialiseAdditional(const picojson::value &v) { picojson::object vd; if (!jat(vd, v, "distances")) return false; float provisionalMaxDistance; if (!jat(provisionalMaxDistance, v, "max_distance")) return false; std::map<int, std::list<float>> provisionalDistances; for (const auto& indexDists : vd) { int provisionalIndex = std::stoi(indexDists.first); if (provisionalDistances.find(provisionalIndex) != provisionalDistances.end()) return false; picojson::array va; if (!jget(va, indexDists.second)) return false; for (const auto& vf : va) { float dist; if (!jget(dist, vf)) return false; provisionalDistances[provisionalIndex].push_back(dist); } } mMaxDistance = provisionalMaxDistance; distances = provisionalDistances; return true; }
/*********************************************************************** * Method: MonteCarloAnalysis::deserialise * Params: const picojson::value &v * Returns: bool * Effects: ***********************************************************************/ bool MonteCarloAnalysis::deserialise(const picojson::value &v) { WidthGroup provisionalOriginalWidth(0,0,0); if (!jat(provisionalOriginalWidth, v, "original_width")) { std::cout << "original width not found\n"; return false; } WidthGroup provisionalMean(0, 0, 0); if (!jat(provisionalMean, v, "mean")) { std::cout << "mean not found\n"; return false; } WidthGroup provisionalSD(0, 0, 0); if (!jat(provisionalSD, v, "standard_deviation")) { std::cout << "standard deviation not found\n"; return false; } WidthGroup provisionalDiscrepancy; if (!jat(provisionalDiscrepancy, v, "discrepancy")) { std::cout << "discrepancy not found\n"; return false; } int provisionalNodeCount; if (!jat(provisionalNodeCount, v, "node_count")) { std::cout << "node count not found\n"; return false; } picojson::array provisionalWidths; if (!jat(provisionalWidths, v, "generated_widths")) { std::cout << "generated widths not found\n"; return false; } if (provisionalWidths.size() != mTreeCount) { std::cout << "tree counts not equal\n"; return false; } for (const auto& widthFract : provisionalWidths) { WidthGroup readWidth; float readFract; if (!jat(readWidth, widthFract, "width")) { std::cout << "width not found\n"; return false; } if (!jat(readFract, widthFract, "fract")) { std::cout << "altered fraction not found\n"; return false; } } widths.clear(); alteredFractions.clear(); originalWidth = provisionalOriginalWidth; mean = provisionalMean; SD = provisionalSD; discrepancy = provisionalDiscrepancy; nodeCount = provisionalNodeCount; for (const auto& widthFract : provisionalWidths) { WidthGroup readWidth; float readFract; jat(readWidth, widthFract, "width"); jat(readFract, widthFract, "fract"); widths.push_back(readWidth); alteredFractions.push_back(readFract); } return true; }
CrsGraph_AMD::NewTypeRef CrsGraph_AMD:: operator()( OriginalTypeRef orig ) { origObj_ = &orig; int n = orig.NumMyRows(); int nnz = orig.NumMyNonzeros(); //create std CRS format std::vector<int> ia(n+1,0); std::vector<int> ja(nnz); int cnt; for( int i = 0; i < n; ++i ) { int * tmpP = &ja[ia[i]]; orig.ExtractMyRowCopy( i, nnz-ia[i], cnt, tmpP ); ia[i+1] = ia[i] + cnt; } //trim down to local only std::vector<int> iat(n+1); std::vector<int> jat(nnz); int loc = 0; for( int i = 0; i < n; ++i ) { iat[i] = loc; for( int j = ia[i]; j < ia[i+1]; ++j ) { if( ja[j] < n ) jat[loc++] = ja[j]; else break; } } iat[n] = loc; if( verbose_ ) { std::cout << "Orig Graph\n"; std::cout << orig << std::endl; std::cout << "-----------------------------------------\n"; std::cout << "CRS Format Graph\n"; std::cout << "-----------------------------------------\n"; for( int i = 0; i < n; ++i ) { std::cout << i << ": " << iat[i+1] << ": "; for( int j = iat[i]; j<iat[i+1]; ++j ) std::cout << " " << jat[j]; std::cout << std::endl; } std::cout << "-----------------------------------------\n"; } std::vector<int> perm(n); std::vector<double> info(AMD_INFO); amd_order( n, &iat[0], &jat[0], &perm[0], NULL, &info[0] ); if( info[AMD_STATUS] == AMD_INVALID ) std::cout << "AMD ORDERING: Invalid!!!!\n"; if( verbose_ ) { std::cout << "-----------------------------------------\n"; std::cout << "AMD Output\n"; std::cout << "-----------------------------------------\n"; std::cout << "STATUS: " << info[AMD_STATUS] << std::endl; std::cout << "SYMM: " << info[AMD_SYMMETRY] << std::endl; std::cout << "N: " << info[AMD_N] << std::endl; std::cout << "NZ: " << info[AMD_NZ] << std::endl; std::cout << "SYMM: " << info[AMD_SYMMETRY] << std::endl; std::cout << "NZDIAG: " << info[AMD_NZDIAG] << std::endl; std::cout << "NZ A+At: " << info[AMD_NZ_A_PLUS_AT] << std::endl; std::cout << "NDENSE: " << info[AMD_SYMMETRY] << std::endl; std::cout << "Perm\n"; for( int i = 0; i<n; ++i ) std::cout << perm[i] << std::endl; std::cout << "-----------------------------------------\n"; } //Generate New Domain and Range Maps //for now, assume they start out as identical const Epetra_BlockMap & OldMap = orig.RowMap(); int nG = orig.NumGlobalRows(); std::vector<int> newElements( n ); for( int i = 0; i < n; ++i ) newElements[i] = OldMap.GID( perm[i] ); NewMap_ = new Epetra_Map( nG, n, &newElements[0], OldMap.IndexBase(), OldMap.Comm() ); if( verbose_ ) { std::cout << "Old Map\n"; std::cout << OldMap << std::endl; std::cout << "New Map\n"; std::cout << *NewMap_ << std::endl; } //Generate New Graph NewGraph_ = new Epetra_CrsGraph( Copy, *NewMap_, 0 ); Epetra_Import Importer( *NewMap_, OldMap ); NewGraph_->Import( orig, Importer, Insert ); NewGraph_->FillComplete(); if( verbose_ ) { std::cout << "New CrsGraph\n"; std::cout << *NewGraph_ << std::endl; } newObj_ = NewGraph_; return *NewGraph_; }
//============================================================================== int Ifpack2_AMDReordering::Compute(const Ifpack2_Graph& Graph) { IsComputed_ = false; NumMyRows_ = Graph.NumMyRows(); int NumNz = Graph.NumMyNonzeros(); if (NumMyRows_ == 0) IFPACK2_CHK_ERR(-1); // strange graph this one // Extract CRS format vector<int> ia(NumMyRows_+1,0); vector<int> ja(NumNz); int cnt; for( int i = 0; i < NumMyRows_; ++i ) { int * tmpP = &ja[ia[i]]; Graph.ExtractMyRowCopy( i, NumNz-ia[i], cnt, tmpP ); ia[i+1] = ia[i] + cnt; } // Trim down to local only vector<int> iat(NumMyRows_+1); vector<int> jat(NumNz); int loc = 0; for( int i = 0; i < NumMyRows_; ++i ) { iat[i] = loc; for( int j = ia[i]; j < ia[i+1]; ++j ) { if( ja[j] < NumMyRows_ ) jat[loc++] = ja[j]; else break; } } iat[NumMyRows_] = loc; // Compute AMD permutation Reorder_.resize(NumMyRows_); vector<double> info(AMD_INFO); amesos_amd_order( NumMyRows_, &iat[0], &jat[0], &Reorder_[0], NULL, &info[0] ); if( info[AMD_STATUS] == AMD_INVALID ) cout << "AMD ORDERING: Invalid!!!!\n"; // Build inverse reorder (will be used by ExtractMyRowCopy() InvReorder_.resize(NumMyRows_); for (int i = 0 ; i < NumMyRows_ ; ++i) InvReorder_[i] = -1; for (int i = 0 ; i < NumMyRows_ ; ++i) InvReorder_[Reorder_[i]] = i; for (int i = 0 ; i < NumMyRows_ ; ++i) { if (InvReorder_[i] == -1) IFPACK2_CHK_ERR(-1); } IsComputed_ = true; return(0); }