# SA and Sb reside on rank zero, so solving the equation is # done there. if (MPI.COMM_WORLD.Get_rank() == 0): # Solve using NumPy [x, res, rank, s] = np.linalg.lstsq(SA.Matrix, Sb.Matrix) else: x = None telp = time.time() - t0 # Distribute the solution so to compute residual in a distributed fashion x = MPI.COMM_WORLD.bcast(x, root=0) # Convert x to a distributed matrix. # Here we give the type explictly, but the value used is the default. x = elemhelper.local2distributed(x, type=elem.DistMatrix_d) # Compute residual r = elem.DistMatrix_d() elem.Copy(b, r) elem.Gemv(elem.NORMAL, -1.0, A1, x, 1.0, r) res = elem.Norm(r) if (MPI.COMM_WORLD.Get_rank() == 0): print "%(name)s:\tSketched solution residual %(val).3f\ttook %(elp).2e sec" %\ {"name" : sname, "val" : res, "elp" : telp} # As with all Python object they will be automatically garbage # collected, and the associated memory will be freed. # You can also explicitly free them. del S # S = 0 will also free memory.
# SA and Sb reside on rank zero, so solving the equation is # done there. if (MPI.COMM_WORLD.Get_rank() == 0): # Solve using NumPy [x, res, rank, s] = np.linalg.lstsq(SA.Matrix().ToNumPy(), Sb.Matrix().ToNumPy()) else: x = None telp = time.time() - t0 # Distribute the solution so to compute residual in a distributed fashion x = MPI.COMM_WORLD.bcast(x, root=0) # Convert x to a distributed matrix. # Here we give the type explictly, but the value used is the default. x = elemhelper.local2distributed(x, type=El.DistMatrix) # Compute residual r = El.DistMatrix() El.Copy(b, r) El.Gemv(El.NORMAL, -1.0, A1, x, 1.0, r) res = El.Norm(r) if (MPI.COMM_WORLD.Get_rank() == 0): print "%(name)s:\tSketched solution residual %(val).3f\ttook %(elp).2e sec" %\ {"name" : sname, "val" : res, "elp" : telp} # As with all Python object they will be automatically garbage # collected, and the associated memory will be freed. # You can also explicitly free them. del S # S = 0 will also free memory.
# done there. if (MPI.COMM_WORLD.Get_rank() == 0): # Solve using NumPy [x, res, rank, s] = np.linalg.lstsq(SA.Matrix().ToNumPy(), Sb.Matrix().ToNumPy()) else: x = None telp = time.time() - t0 # Distribute the solution so to compute residual in a distributed fashion x = MPI.COMM_WORLD.bcast(x, root=0) # Convert x to a distributed matrix. # Here we give the type explictly, but the value used is the default. x = elemhelper.local2distributed(x, type=El.DistMatrix) # Compute residual r = El.DistMatrix() El.Copy(b, r) El.Gemv(El.NORMAL, -1.0, A1, x, 1.0, r) res = El.Norm(r) if (MPI.COMM_WORLD.Get_rank() == 0): print "%(name)s:\tSketched solution residual %(val).3f\ttook %(elp).2e sec" %\ {"name" : sname, "val" : res, "elp" : telp} # As with all Python object they will be automatically garbage # collected, and the associated memory will be freed. # You can also explicitly free them. del S # S = 0 will also free memory.