def GenStubs(sw): """ determine degrees for all the nodes, generate the stubs and distribute them """ taskname = sw.GetName() msglist = sw.GetMsgList() sw.flog.write("msglist " + str(msglist) + "\n") sw.flog.flush() ntasks = int(sw.GetVar("gen_tasks")) sw.flog.write("__tasks__ %s\t%s\n" % (taskname, str(ntasks))) sw.flog.flush() for item in msglist: dmsg = sw.GetMsg(item) d = dmsg["body"] sw.flog.write("task %s, args %s\n" % (taskname, str(d))) sw.flog.flush() ns = d["s"] nrange = d["r"] sw.flog.write("task %s, start %d, range %d\n" % (taskname, ns, nrange)) sw.flog.flush() # determine node degrees DegV = Snap.TIntV(nrange) Snap.GetDegrees(DegV, distmean, distvar) sw.flog.write("1 got degrees\n") sw.flog.flush() # randomly assign stubs to tasks Tasks = Snap.TIntIntVV(ntasks) Snap.AssignRndTask(DegV, Tasks) sw.flog.write("2 assigned stubs\n") sw.flog.flush() # add ns to all values in Tasks for i in range(0, Tasks.Len()): Snap.IncVal(Tasks.GetVal(i), ns) sw.flog.write("3 incremented base\n") sw.flog.flush() # send messages for i in range(0, Tasks.Len()): #sw.flog.write("sending task %d" % (i) + "\n") sw.flog.write("sending task %d, len %d" % (i, Tasks.GetVal(i).Len()) + "\n") sw.flog.flush() sw.Send(i, Tasks.GetVal(i), swsnap=True)
def GenStubs(sw): """ determine degrees for all the nodes, generate the stubs and distribute them """ taskname = sw.GetName() msglist = sw.GetMsgList() sw.log.debug("msglist: %s" % str(msglist)) ntasks = int(sw.GetVar("gen_tasks")) sw.log.debug("__tasks__ %s\t%d" % (taskname, ntasks)) for item in msglist: dmsg = sw.GetMsg(item) d = dmsg["body"] ns = d["s"] nrange = d["r"] sw.log.debug("task: %s, args: %s, start: %d, range: %d" % \ (taskname, str(d), ns, nrange)) # 1) Get degrees # determine node degrees DegV = Snap.TIntV(nrange) # vector of vertices' degree Snap.GetDegrees(DegV, distmean, distvar) # populate # 2) Assign stubs # randomly assign stubs to tasks Tasks = Snap.TIntIntVV( ntasks) # vector of tasks, with each cell a vector Snap.AssignRndTask(DegV, Tasks) # each task is assigned a vec of vertex ids # 3) Incremented base (above) # add ns to all values in Tasks for i in xrange(0, Tasks.Len()): # inc the values in each list by ns (num_start) # so that they are true vectex ids Snap.IncVal(Tasks.GetVal(i), ns) # send messages for i in xrange(0, Tasks.Len()): sw.log.debug("sending task %d, len %d" % (i, Tasks.GetVal(i).Len())) sw.Send(i, Tasks.GetVal(i), swsnap=True)
#print "dir(Vec1)", dir(Vec1) print "Len Vec1", Vec1.Len() #print "dir(snap.TIntIntVV)", dir(snap.TIntIntVV) Vec2 = snap.TIntIntVV(numtask) #print "dir(Vec2)", dir(Vec2) print "Len Vec2", Vec2.Len() print "Vec1", type(Vec1) snap.GetDegrees(Vec1, 10.0, 1.5) for i in range(0, Vec1.Len()): print "Vec1", i, Vec1.GetVal(i).Val snap.AssignRndTask(Vec1, Vec2) for i in range(0, Vec2.Len()): Vec3 = Vec2.GetVal(i) print "Vec3", i, Vec3.Len() for j in range(0, Vec3.Len()): print "Vec4", i, j, Vec3.GetVal(j).Val sys.exit(0) for i in range(0, Vec2.Len()): Vec3 = Vec2.GetVal(i) print "Vec3", i, Vec3.Len() h = httplib.HTTPConnection("rokl1.stanford.edu", 8100)