Beispiel #1
0
from Numeric import sin

# builds the linear system matrix and sets up starting solution and
# right-hand side
Comm = Epetra.PyComm()

# I got similar results for _1 and _4
MapName = "/Users/marzio/matrices/PREMO/Falcon-step2/Falcon_ss_1_map"
MatrixName = "/Users/marzio/matrices/PREMO/Falcon-step2/Falcon_ss_4_matrix"
LHSName = "/Users/marzio/matrices/PREMO/Falcon-step2/Falcon_ss_1_guess"
RHSName = "/Users/marzio/matrices/PREMO/Falcon-step2/Falcon_ss_1_guess"

(ierr, Map) = EpetraExt.MatrixMarketFileToBlockMap(MapName, Comm)
(ierr, LHS) = EpetraExt.MatrixMarketFileToMultiVector(LHSName, Map)
(ierr, RHS) = EpetraExt.MatrixMarketFileToMultiVector(RHSName, Map)
(ierr, Matrix) = EpetraExt.MatrixMarketFileToCrsMatrix(MatrixName, Map)

LHSView = LHS.ExtractView()
n = LHS.MyLength()
for i in xrange(0, n):
  LHSView[0][i] = sin(i * 3.1415 / n) * sin(i * 3.1415 / n)

Matrix.Multiply(False, LHS, RHS)
LHS.PutScalar(0.0)

# sets up the parameters for ML using a python dictionary
MLList = {
  "max levels"        : 10, 
  "output"            : 10,
  "increasing or decreasing": "increasing",
  "aggregation: type" : "Uncoupled",
Beispiel #2
0
def generator(problemID, comm, List):
  GaleriList = {}
  if problemID[0:3] == "HB_":
    print "<p><p><div class=\"outputBox\"><pre>";
    FileName = HB_REPOSITORY + problemID[3:];
    Map, Matrix, LHS, RHS, ExactSolution = Galeri.ReadHB(FileName, comm);
    NullSpace = "not-set"
    print "</div>"

  elif problemID[0:3] == "MM_":
    # read matrix first, then use its map for the vectors
    # FIXME: to check for vectors here
    FileName = MM_REPOSITORY + problemID[3:] + "/A.mm";
    (ierr, Matrix) = EpetraExt.MatrixMarketFileToCrsMatrix(FileName, comm)
    Map = Matrix.RowMatrixRowMap()
    FileName = MM_REPOSITORY + problemID[3:] + "/ExactSolution.mm";

    if os.path.isfile(FileName):
      (ierr, ExactSolution) = EpetraExt.MatrixMarketFileToMultiVector(FileName, Map)
    else:
      ExactSolution = Epetra.Vector(Map)
      ExactSolution.PutScalar(0.0)

    FileName = MM_REPOSITORY + problemID[3:] + "/RHS.mm";
    if os.path.isfile(FileName):
      (ierr, RHS) = EpetraExt.MatrixMarketFileToMultiVector(FileName, Map)
    else:
      RHS = Epetra.MultiVector(Map, ExactSolution.NumVectors())
      RHS.PutScalar(0.0)

    FileName = MM_REPOSITORY + problemID[3:] + "/LHS.mm";
    if os.path.isfile(FileName):
      (ierr, LHS) = EpetraExt.MatrixMarketFileToMultiVector(FileName, Map)
    else:
      LHS = Epetra.MultiVector(Map, RHS.NumVectors())
      LHS.PutScalar(0.0)

    NullSpace = "not-set"
    print "</div>"

  elif problemID[0:4] == "XML_":
    FileName = XML_REPOSITORY + problemID[4:];
    XMLReader = EpetraExt.XMLReader(comm, FileName)
    Map = XMLReader.ReadMap("map")
    LHS = XMLReader.ReadMultiVector("LHS")
    RHS = XMLReader.ReadMultiVector("RHS")
    ExactSolution = XMLReader.ReadMultiVector("ExactSolution")
    Matrix = XMLReader.ReadCrsMatrix("A")
    NullSpace = "not-set"
    print "</div>"

  else:
    parts = string.split(problemID, '_');
    ProblemType = parts[0];
    for i in range(1, len(parts)):
      p2 = string.split(parts[i], '!')
      type = p2[0][0];
      name = p2[0][1:]
      value = p2[1];
      if (type == "i"):
        GaleriList[name] = int(value);
      elif type == "d":
        GaleriList[name] = float(value);
      elif type == "s":
        GaleriList[name] = value;
    
    if string.find(ProblemType, '2D') != -1:
      MapType = "Cartesian2D";
      mx = math.sqrt(NumProcs)
      if mx * mx == NumProcs:
        GaleriList['mx'] = int(mx)
        GaleriList['my'] = int(mx)
      else:
        GaleriList['mx'] = int(NumProcs)
        GaleriList['my'] = 1

    elif string.find(ProblemType, '3D') != -1:
      MapType = "Cartesian3D"
      mx = math.pow(NumProcs, 0.33334)
      if mx * mx * mx == NumProcs:
        GaleriList['mx'] = int(mx)
        GaleriList['my'] = int(mx)
        GaleriList['mz'] = int(mx)
      else:
        GaleriList['mx'] = int(NumProcs)
        GaleriList['my'] = 1
        GaleriList['mz'] = 1

    Map = Galeri.CreateMap(MapType, comm, GaleriList);

    Matrix = Galeri.CreateCrsMatrix(ProblemType, Map, GaleriList);

    LHS = Epetra.Vector(Map)
    RHS = Epetra.Vector(Map)
    ExactSolution = Epetra.Vector(Map)
    
    NullSpace = "not-set"

  # checks that the matrix is not too big

  if Map.NumGlobalElements() > MAX_MATRIX_ROWS:
    print "<b><font color=red>Sorry, the maximum matrix size is 20.000</font></b>"
    raise("PARAMETER_ERROR");

  if Matrix.NumGlobalNonzeros() > MAX_MATRIX_NONZEROS:
    print "<b><font color=red>Sorry, the maximum number of nonzeros is 250.000</font></b>"
    raise("PARAMETER_ERROR");

  # FIXME???
  if List.has_key('solution') == True:
    if List['solution'] == "zero":
      ExactSolution.PutScalar(0.0)
    elif List['solution'] == "random":
      ExactSolution.Random()
    elif List['solution'] == "constant":
      ExactSolution.PutScalar(1.0)
    elif List['solution'] == "from_file":
      # do nothing
      ciao = 2.0
    else:
      raise("PARAMETER_ERROR");

  if List.has_key('starting_solution') == True:
    if List['starting_solution'] == "zero":
      LHS.PutScalar(0.0)
    elif List['starting_solution'] == "random":
      LHS.Random()
    elif List['starting_solution'] == "constant":
      LHS.PutScalar(1.0)
    elif List['starting_solution'] == "from_file":
      # do nothing
      ciao = 2.0
    else:
      raise("PARAMETER_ERROR");
  
  if List.has_key('rhs') == True:
    if List['rhs'] == "zero":
      RHS.PutScalar(0.0)
    elif List['rhs'] == "random":
      RHS.Random()
    elif List['rhs'] == "constant":
      RHS.PutScalar(1.0)
    elif List['rhs'] == "matvec":
      Matrix.Apply(ExactSolution, RHS);
    elif List['rhs'] == "from_file":
      # do nothing
      ciao = 2.0
    else:
      raise("PARAMETER_ERROR");

  else:
    ExactSolution.Random()
    Matrix.Apply(ExactSolution, RHS)
    LHS.PutScalar(0.0)

  return(Map, Matrix, LHS, RHS, ExactSolution, NullSpace);
from PyTrilinos import Epetra, ML, EpetraExt, IFPACK, AztecOO
from math import sin
comm = Epetra.PyComm()
(ierr,
 Matrix) = EpetraExt.MatrixMarketFileToCrsMatrix("/tmp/MPSalsa_Diamond_med.mm",
                                                 comm)

Map = Matrix.RowMatrixRowMap()

# -------------------------------------- #
# building solutions and right-hand side #
# -------------------------------------- #

LHS = Epetra.Vector(Map)
RHS = Epetra.Vector(Map)
LHSView = LHS.ExtractView()
n = LHS.MyLength()
for i in xrange(0, n):
    LHSView[i] = sin(i * 3.1415 / n) * sin(i * 3.1415 / n)

Matrix.Multiply(False, LHS, RHS)

# ------------------------------------------------- #
# Parameters to run ML. Remember the RCM reordering #
# for Charon matrices!                              #
# ------------------------------------------------- #

MLList = {
    "max levels": 10,
    "output": 10,
    "smoother: type": "IFPACK",