def bfsTree(self, root): """ calculates a breadth-first search tree from the edges in the passed HyGraph, starting from the root vertex. "Breadth-first" in the sense that all vertices reachable in step i are added to the tree before any of the newly-reachable vertices' reachable vertices are explored. The returned tree (implied in the parent relationships) consists of simple edges, not the original hyperedges of the HyGraph instance. Input Arguments: root: an integer denoting the root vertex for the tree Input Arguments: parents: a ParVec instance of length equal to the number of vertices in the HyGraph, with each element denoting the vertex number of that vertex's parent in the tree. The root is its own parent. Unreachable vertices have a parent of -1. SEE ALSO: isBfsTree """ parents = pcb.pyDenseParVec(self.nvert(), -1) fringeV = pcb.pySpParVec(self.nvert()) parents[root] = root fringeV[root] = root while fringeV.getnee() > 0: fringeV.setNumToInd() fringeE = self._spm.SpMV_SelMax(fringeV) fringeV = self._spmT.SpMV_SelMax(fringeE) pcb.EWiseMult_inplacefirst(fringeV, parents, True, -1) parents[fringeV] = 0 parents += fringeV return ParVec.toParVec(parents)
def loadDenseVect(name, length): import sys import csv import pyCombBLAS as pcb # needs to happen on all processors inputFile = open(name, "rb") parser = csv.reader(inputFile, dialect="excel-tab") firstRec = True for fields in parser: if firstRec: firstRec = False n = int(fields[0]) if n != length: return pcb.pyDenseParVec(length, 0) ret = pcb.pyDenseParVec(n, 0) else: if len(fields) == 2: ret[int(fields[0])] = float(fields[1]) return ret
def k2validate(G, root, parents): ret = 1; # assume valid nrowG = G.getnrow(); # calculate level in the tree for each vertex; root is at level 0 # about the same calculation as bfsTree, but tracks levels too parents2 = pcb.pyDenseParVec(nrowG, -1); fringe = pcb.pySpParVec(nrowG); parents2[root] = root; fringe[root] = root; levels = pcb.pyDenseParVec(nrowG, -1); levels[root] = 0; level = 1; while fringe.getnee() > 0: fringe.setNumToInd(); G.SpMV_SelMax_inplace(fringe); pcb.EWiseMult_inplacefirst(fringe, parents2, True, -1); #fringe.printall(); parents2.ApplyMasked(pcb.set(0), fringe); parents2.add(fringe); levels.ApplyMasked(pcb.set(level), fringe); level += 1; # spec test #1 # Not implemented # spec test #2 # tree edges should be between verts whose levels differ by 1 #print "starting spec test#2" # root = element of parents that points to itself ##tmp1 = parents.copy() ##tmp1 -= pcb.pyDenseParVec.range(nrowG,0) ##root = tmp1.FindInds_NotEqual(0); #treeEdges = ((parents <> -1) & (parents <> root); tmp1 = parents.copy(); tmp1[root] = -1; treeEdges = tmp1.FindInds(pcb.bind2nd(pcb.not_equal_to(), -1)); #treeI = parents[treeEdges] treeI = parents.SubsRef(treeEdges); #treeJ = 1..nrowG[treeEdges] treeJ = pcb.pyDenseParVec.range(nrowG,0).SubsRef(treeEdges); #if any(levels[treeI]-levels[treeJ] <> -1): tmp1 = levels.SubsRef(treeI); tmp1 -= levels.SubsRef(treeJ); tmp2 = tmp1.FindInds(pcb.bind2nd(pcb.not_equal_to(), -1)); if tmp2.getnee(): print "spec test #2 failed." ret = -1; # spec test #3 # Not implemented # spec test #4 # Not implemented # spec test #5 # Not implemented del G, parents, parents2, fringe, levels, tmp1, tmp2, treeEdges, treeI, treeJ return ret
if (scale < 0): if len(sys.argv) >= 3: path = sys.argv[2] else: print "Expecting a path to a matrix file as argument." sys.exit(); print "loading matrix from %s"%(path) A.load(path) A.Apply(pcb.set(1)) #print "converting to boolean" # already boolean #A = pcb.pySpParMatBool(A) n = A.getnrow() colreducer = pcb.pyDenseParVec(n, 1).sparse(); degrees = A.SpMV_PlusTimes(colreducer).dense(); else: if (pcb.root()): print "Generating RMAT with 2**%d nodes" %(scale) k1time = A.GenGraph500Edges(scale) A.Apply(pcb.set(1)) degrees = A.Reduce(pcb.pySpParMat.Column(), pcb.plus()); if (pcb.root()): print "Generation took %lf s"%(k1time) #A.save("/home/alugowski-ucsb/matrices/rmat%d.mtx"%(scale)) n = A.getnrow() m = A.getncol() nee = A.getnee()