Esempio n. 1
0
void testBoundaryLRSolver(const std::string inputMatrixFileName,const std::string inputGraphFileName,const std::string outputFileName,const double iterInitTol,const int sizeThreshold,const int depth,user_IndexTree &usrTree){
  Eigen::MatrixXd inputMatrix = readBinaryIntoMatrixXd(inputMatrixFileName);
  Eigen::SparseMatrix<double> inputGraph = readMtxIntoSparseMatrix(inputGraphFileName);
  HODLR_Matrix testHODLR(inputMatrix,inputGraph,sizeThreshold,usrTree);
  int matrixSize = inputMatrix.rows();
  Eigen::VectorXd exactSoln = Eigen::VectorXd::LinSpaced(Eigen::Sequential,matrixSize,-2,2);
  Eigen::VectorXd inputF    = inputMatrix * exactSoln;
  testHODLR.set_BoundaryDepth(depth);
  testHODLR.printResultInfo = true;
  Eigen::VectorXd solverSoln = testHODLR.iterative_Solve(inputF,100,1e-10,iterInitTol,"PS_Boundary","recLU");
  Eigen::VectorXd difference = solverSoln - exactSoln;
  //double relError = difference.norm()/exactSoln.norm();
  //std::cout<<relError<<std::endl;
  testHODLR.saveSolverInfo(outputFileName);
  double startTime = clock();
  Eigen::PartialPivLU<Eigen::MatrixXd> LU (inputMatrix);
  solverSoln = LU.solve(inputF);
  double endTime = clock();
  double LU_SolveTime = (endTime - startTime)/CLOCKS_PER_SEC;
  std::cout<<"LU Solve Time = "<<LU_SolveTime<<" seconds"<<std::endl;
  std::cout<<"Matrix Size   = "<<inputMatrix.rows()<<std::endl;
}
Esempio n. 2
0
int main(){

  std::cout<<"+++++++++++++++++++++++++++++++++++++++++++++++++++"<<std::endl;
  std::cout<<"Testing fast iterative solver on a 100k matrix...."<<std::endl;
  //Eigen::SparseMatrix<double> inputSpMatrix = readMtxIntoSparseMatrix("../benchmarks/data/input_FETI/TardecAres/localmat1");
  // Eigen::SparseMatrix<double> inputSpMatrix = readMtxIntoSparseMatrix("../benchmarks/data/stiffness/GenericHull/localmat0");                                                                         

  Eigen_IML_Matrix inputSpMatrix;
  //inputSpMatrix = readMtxIntoSparseMatrix("../../../benchmarks/data/input_FETI/TardecAres/localmat1");
 
  //loadMarket(inputSpMatrix,"../../../benchmarks/data/input_FETI/TardecAres/localmat1");
  //inputSpMatrix = readMtxIntoSparseMatrix("../../benchmarks/data/UF/AMD/G3_circuit/G3_circuit.mtx");
  //inputSpMatrix = readMtxIntoSparseMatrix("../../benchmarks/data/UF/Botonakis/thermomech_dM/thermomech_dM.mtx");
  //inputSpMatrix   = readMtxIntoSparseMatrix("../../benchmarks/data/UF/CEMW/tmt_sym/tmt_sym.mtx");         
  //inputSpMatrix   = readMtxIntoSparseMatrix("../../benchmarks/data/UF/GHS_psdef/apache2/apache2.mtx");    
  //inputSpMatrix   = readMtxIntoSparseMatrix("../../benchmarks/data/UF/McRae/ecology2/ecology2.mtx");    
  //inputSpMatrix   = readMtxIntoSparseMatrix("../../benchmarks/data/UF/Wissgott/parabolic_fem/parabolic_fem.mtx");    
  //inputSpMatrix   = readMtxIntoSparseMatrix("../../benchmarks/data/stiffness/unStructured/cylinderHead/2.3m/localmat0");    
  //inputSpMatrix   = readMtxIntoSparseMatrix("../../benchmarks/data/SMatrices/linearElasticity/ElasticityS32_660k");    
  //inputSpMatrix   = readMtxIntoSparseMatrix("../../../benchmarks/data/SMatrices/Poisson/PoissonS64_1M");    
 
  //inputSpMatrix   = readMtxIntoSparseMatrix("../../benchmarks/data/input_FETI/structured/localmat1.800k");    
  //inputSpMatrix   = readMtxIntoSparseMatrix("../../benchmarks/data/UF/Janna/Cube_Coup_dt6/Cube_Coup_dt6.mtx");    
  //inputSpMatrix   = readMtxIntoSparseMatrix("../../../benchmarks/data/input_FETI/structured/localmat0.100k");    
  //inputSpMatrix   = readMtxIntoSparseMatrix("../../../benchmarks/data/input_FETI/unStructured/cube/localmat0.500k");
  //inputSpMatrix   = readMtxIntoSparseMatrix("../../../benchmarks/data/stiffness/unStructured/beam/stiffness.300k");
  //inputSpMatrix   = readMtxIntoSparseMatrix("../../../benchmarks/data/stiffness/unStructured/cylinderHead/330k/localmat0");    
  // inputSpMatrix   = readMtxIntoSparseMatrix("../../../benchmarks/data/input_FETI/structured/localmat0.400k");    
  inputSpMatrix   = readMtxIntoSparseMatrix("../../../benchmarks/data/input_FETI/unStructured/engine/localmat4");    
 
  
  //inputSpMatrix = rowScaling(inputSpMatrix);
 
  //testSolveSp(inputSpMatrix, "implicit");
  //testSolveSp(inputSpMatrix, "fast_Iterative");
  
  //Eigen_IML_Vector exactSoln_Sp = Eigen::VectorXd::LinSpaced(Eigen::Sequential,inputSpMatrix.rows(),-2,2);
  //Eigen_IML_Vector RHS = inputSpMatrix * exactSoln_Sp;
  Eigen_IML_Vector RHS = Eigen::MatrixXd::Random(inputSpMatrix.rows(),1);
  
  fastSparse_IML_Precond precond(inputSpMatrix);
  precond.printResultInfo = true;
  Eigen_IML_Vector x1      = precond.implicit_Solve(RHS);
  //Eigen_IML_Vector x0      = precond.solve(RHS);
  //Eigen_IML_Vector soln_Sp = precond.iterative_Solve(RHS,10,1e-10,1e-1);
  //Eigen_IML_Vector x0 = Eigen::MatrixXd::Zero(inputSpMatrix.rows(),1);
  precond.printResultInfo = false;
  std::cout<<"RHS norm = "<<RHS.norm()<<std::endl;
  double tol = 1e-4;
  int result, maxit = 5000,restart = 32;
  Eigen::MatrixXd H =Eigen::MatrixXd::Zero(restart+1,restart);
  //result = GMRES(inputSpMatrix,x0,RHS,precond,H,restart,maxit,tol);
  
  std::cout<<"GMRES flag = "<<result<<std::endl;
  std::cout<<"iterations performed "<<maxit<<std::endl;
  std::cout<<"tolerance achieved : "<<tol<<std::endl;

  
  diag_IML_Precond diagPrecond(inputSpMatrix);
  Eigen_IML_Vector x2 = diagPrecond.solve(RHS);
  H = Eigen::MatrixXd::Zero(restart+1,restart);
  maxit = 1000;
  tol = 1e-4;
  std::cout<<"here"<<std::endl;
  //result = GMRES(inputSpMatrix,x2,RHS,diagPrecond,H,restart,maxit,tol);

  std::cout<<"GMRES flag = "<<result<<std::endl;
  std::cout<<"iterations performed "<<maxit<<std::endl;
  std::cout<<"tolerance achieved : "<<tol<<std::endl;
  



  return 0;
}
Esempio n. 3
0
void analyzeRank(const std::string inputMatrixFileName,const std::string inputGraphFileName,const std::string outputFileName,const int input_Min_i,const int input_Min_j, const int input_NumRows,const int input_NumCols,std::string mode){
  Eigen::MatrixXd inputMatrix = readBinaryIntoMatrixXd(inputMatrixFileName);
  Eigen::SparseMatrix<double> inputGraph = readMtxIntoSparseMatrix(inputGraphFileName);
  int min_i,min_j,numRows,numCols;
  int matrixSize = inputMatrix.rows();
  if (mode == "topOffDiag"){  
    int split = matrixSize/2; 
    min_i = 0;
    min_j = split + 1;
    numRows = split + 1;
    numCols = matrixSize - split - 1;
  } else if (mode == "bottOffDiag"){  
    int split = matrixSize/2; 
    min_i = split + 1;
    min_j = 0;
    numRows = matrixSize - split - 1;
    numCols = split + 1; 
  }else{
    min_i   = input_Min_i;
    min_j   = input_Min_j;
    numRows = input_NumRows;
    numCols = input_NumCols;
  }
  int currRank  = 0;
  int currRankComp1 = 0;
  int currRankComp3 = 0;
  int currRankComp5 = 0;
  int nextRank  = -1;
  int depth     = 0;
  Eigen::MatrixXd currBlock = inputMatrix.block(min_i,min_j,numRows,numCols);
  Eigen::MatrixXd U,V;
  std::vector<double> numPoints,boundaryError,SVDError,singularValues;
  std::vector<double> boundaryErrorComp1,boundaryErrorComp3,boundaryErrorComp5;
  while (currRank != nextRank){
    nextRank = currRank;
    PS_Boundary_LowRankApprox(inputMatrix,inputGraph,U,V,min_i,min_j,numRows,numCols,1e-15,currRank,depth);
    numPoints.push_back(currRank);
    double relError = (U * V.transpose() - currBlock).norm()/currBlock.norm();

    boundaryError.push_back(relError);
    PS_Boundary_LowRankApprox(inputMatrix,inputGraph,U,V,min_i,min_j,numRows,numCols,1e-1,currRankComp1,depth);
    relError = (U * V.transpose() - currBlock).norm()/currBlock.norm();
    
    boundaryErrorComp1.push_back(relError);
    PS_Boundary_LowRankApprox(inputMatrix,inputGraph,U,V,min_i,min_j,numRows,numCols,1e-3,currRankComp3,depth);
    relError = (U * V.transpose() - currBlock).norm()/currBlock.norm();
    
    boundaryErrorComp3.push_back(relError);
    PS_Boundary_LowRankApprox(inputMatrix,inputGraph,U,V,min_i,min_j,numRows,numCols,1e-5,currRankComp5,depth);
    relError = (U * V.transpose() - currBlock).norm()/currBlock.norm();
  
    boundaryErrorComp5.push_back(relError);
    depth ++;
  }
  saveVectorAsText(outputFileName + "numPointsVsBoundaryDistance",numPoints);
  saveVectorAsText(outputFileName + "boundaryErrorVsBoundaryDistance",boundaryError);
  saveVectorAsText(outputFileName + "boundaryErrorCompVsBoundaryDistance1",boundaryErrorComp1);
  saveVectorAsText(outputFileName + "boundaryErrorCompVsBoundaryDistance3",boundaryErrorComp3);
  saveVectorAsText(outputFileName + "boundaryErrorCompVsBoundaryDistance5",boundaryErrorComp5);

  // Use svd to calculate the optimal low-rank approximation error
  Eigen::JacobiSVD<Eigen::MatrixXd> svd(currBlock,Eigen::ComputeThinU|Eigen::ComputeThinV);
  Eigen::VectorXd s = svd.singularValues();
  for (unsigned int i = 0; i < s.rows(); i++)
    singularValues.push_back(s(i));

  for (unsigned int i = 0; i < numPoints.size(); i++){
    int rank = numPoints[i];
    U = svd.matrixU().leftCols(rank);
    V = svd.matrixV().leftCols(rank);
    Eigen::MatrixXd K = Eigen::MatrixXd::Zero(rank,rank);
    for (int j = 0; j < rank; j++)
      K(j,j) = singularValues[j];
    double relError = (U * K * V.transpose() - currBlock).norm()/currBlock.norm();
    SVDError.push_back(relError);
  }
  saveVectorAsText(outputFileName + "SVDErrorVsBoundaryDistance",SVDError);
  saveVectorAsText(outputFileName + "SingularValueDecay",singularValues);

  // Calculate distance from boundary vs pivot size
  PS_Boundary_LowRankApprox(inputMatrix,inputGraph,U,V,min_i,min_j,numRows,numCols,1e-15,currRank,matrixSize,outputFileName + "distanceFromBoundaryVsPivotSize");

}