Beispiel #1
0
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)
Beispiel #2
0
def GenStubs(sw):
    """
    determine degrees for all the nodes, generate the stubs and distribute them
    """
    seg_bits = int(sw.GetVar('seg_bits'))

    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(LazyStr(lambda: "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.TIntVVV(
            ntasks
        )  # vector of tasks, with each cell a segmented vector for nodes

        sw.log.debug("[%s] about to assign some random tasks" % taskname)

        # incrementing by ns is handled in this function
        Snap.AssignRndTask64(
            DegV, Tasks, ns,
            seg_bits)  # each task is assigned a vec of vertex ids
        sw.log.debug("[%s] done assigning some random tasks" % taskname)
        # we have to add ns in the step above since otherwise
        # we would have to copy vectors

        # 3) Incremented base (above)
        # add ns to all values in Tasks
        # (handled in AssignRndTask64)

        # send messages
        for i in xrange(0, Tasks.Len()):
            sw.log.debug(LazyStr(lambda: "[%s] sending task %d, memsize %d" % \
                (taskname, i, Snap.GetMemSize64(Tasks.GetVal(i)))))
            sw.Send(i, Tasks.GetVal(i), swsnap=True)
Beispiel #3
0
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)
sys.exit(0)

#print "dir(snap.TIntV)", dir(snap.TIntV)
Vec1 = snap.TIntV(numnodes)
#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)