make Neighbor objects peer with other Neighbor objects
Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
parent
bc289555d3
commit
c909f0b75d
33
DAS/node.py
33
DAS/node.py
|
@ -21,15 +21,18 @@ class Neighbor:
|
||||||
"""It returns the amount of sent and received data."""
|
"""It returns the amount of sent and received data."""
|
||||||
return "%d:%d/%d, q:%d" % (self.node.ID, self.sent.count(1), self.received.count(1), len(self.sendQueue))
|
return "%d:%d/%d, q:%d" % (self.node.ID, self.sent.count(1), self.received.count(1), len(self.sendQueue))
|
||||||
|
|
||||||
def __init__(self, v, dim, blockSize):
|
def __init__(self, node, dim, blockSize):
|
||||||
"""It initializes the neighbor with the node and sets counters to zero."""
|
"""It initializes the neighbor with the node and sets counters to zero."""
|
||||||
self.node = v
|
self.node = node
|
||||||
self.dim = dim # 0:row 1:col
|
self.dim = dim # 0:row 1:col
|
||||||
self.receiving = zeros(blockSize)
|
self.receiving = zeros(blockSize)
|
||||||
self.received = zeros(blockSize)
|
self.received = zeros(blockSize)
|
||||||
self.sent = zeros(blockSize)
|
self.sent = zeros(blockSize)
|
||||||
self.sendQueue = deque()
|
self.sendQueue = deque()
|
||||||
|
|
||||||
|
def setPeer(self, peer):
|
||||||
|
self.peer = peer
|
||||||
|
|
||||||
|
|
||||||
class Validator:
|
class Validator:
|
||||||
def __init__(self, rowIDs, columnIDs):
|
def __init__(self, rowIDs, columnIDs):
|
||||||
|
@ -116,11 +119,25 @@ class Node:
|
||||||
self.segmentShuffleScheduler = True # send each segment that's worth sending once in shuffled order, then repeat
|
self.segmentShuffleScheduler = True # send each segment that's worth sending once in shuffled order, then repeat
|
||||||
self.segmentShuffleSchedulerPersist = True # Persist scheduler state between timesteps
|
self.segmentShuffleSchedulerPersist = True # Persist scheduler state between timesteps
|
||||||
|
|
||||||
def addRowNeighbor(self, lineID, node):
|
def addRowNeighbor(self, lineID, peer, symmetric = True):
|
||||||
self.rowNeighbors[lineID].update({node.ID : Neighbor(node, 0, self.shape.blockSizeR)})
|
n = Neighbor(self, 0, self.shape.blockSizeR)
|
||||||
|
p = Neighbor(peer, 0, self.shape.blockSizeR)
|
||||||
|
n.setPeer(p)
|
||||||
|
p.setPeer(n)
|
||||||
|
|
||||||
def addColumnNeighbor(self, lineID, node):
|
self.rowNeighbors[lineID].update({peer.ID : n})
|
||||||
self.columnNeighbors[lineID].update({node.ID : Neighbor(node, 1, self.shape.blockSizeC)})
|
if symmetric:
|
||||||
|
peer.rowNeighbors[lineID].update({self.ID : p})
|
||||||
|
|
||||||
|
def addColumnNeighbor(self, lineID, peer, symmetric = True):
|
||||||
|
n = Neighbor(self, 1, self.shape.blockSizeR)
|
||||||
|
p = Neighbor(peer, 1, self.shape.blockSizeR)
|
||||||
|
n.setPeer(p)
|
||||||
|
p.setPeer(n)
|
||||||
|
|
||||||
|
self.columnNeighbors[lineID].update({peer.ID : n})
|
||||||
|
if symmetric:
|
||||||
|
peer.columnNeighbors[lineID].update({self.ID : p})
|
||||||
|
|
||||||
|
|
||||||
def logIDs(self):
|
def logIDs(self):
|
||||||
|
@ -271,10 +288,10 @@ class Node:
|
||||||
|
|
||||||
def sendSegmentToNeigh(self, rID, cID, neigh):
|
def sendSegmentToNeigh(self, rID, cID, neigh):
|
||||||
"""Send segment to a neighbor (without checks)."""
|
"""Send segment to a neighbor (without checks)."""
|
||||||
self.logger.trace("sending %d/%d to %d", rID, cID, neigh.node.ID, extra=self.format)
|
self.logger.trace("sending %d/%d to %d", rID, cID, neigh.peer.node.ID, extra=self.format)
|
||||||
i = rID if neigh.dim else cID
|
i = rID if neigh.dim else cID
|
||||||
neigh.sent[i] = 1
|
neigh.sent[i] = 1
|
||||||
neigh.node.receiveSegment(rID, cID, self.ID)
|
neigh.peer.node.receiveSegment(rID, cID, self.ID)
|
||||||
self.statsTxInSlot += 1
|
self.statsTxInSlot += 1
|
||||||
|
|
||||||
def checkSendSegmentToNeigh(self, rID, cID, neigh):
|
def checkSendSegmentToNeigh(self, rID, cID, neigh):
|
||||||
|
|
|
@ -157,8 +157,7 @@ class Simulator:
|
||||||
for u, v in G.edges:
|
for u, v in G.edges:
|
||||||
val1=rowChannels[id][u]
|
val1=rowChannels[id][u]
|
||||||
val2=rowChannels[id][v]
|
val2=rowChannels[id][v]
|
||||||
val1.addRowNeighbor(id, val2)
|
val1.addRowNeighbor(id, val2) # symmetric
|
||||||
val2.addRowNeighbor(id, val1)
|
|
||||||
|
|
||||||
for id in range(self.shape.blockSizeR):
|
for id in range(self.shape.blockSizeR):
|
||||||
|
|
||||||
|
@ -176,7 +175,6 @@ class Simulator:
|
||||||
val1=columnChannels[id][u]
|
val1=columnChannels[id][u]
|
||||||
val2=columnChannels[id][v]
|
val2=columnChannels[id][v]
|
||||||
val1.addColumnNeighbor(id, val2)
|
val1.addColumnNeighbor(id, val2)
|
||||||
val2.addColumnNeighbor(id, val1)
|
|
||||||
|
|
||||||
for v in self.validators:
|
for v in self.validators:
|
||||||
if (self.proposerPublishOnly and v.amIproposer):
|
if (self.proposerPublishOnly and v.amIproposer):
|
||||||
|
@ -184,12 +182,12 @@ class Simulator:
|
||||||
count = min(self.proposerPublishTo, len(rowChannels[id]))
|
count = min(self.proposerPublishTo, len(rowChannels[id]))
|
||||||
publishTo = random.sample(rowChannels[id], count)
|
publishTo = random.sample(rowChannels[id], count)
|
||||||
for vi in publishTo:
|
for vi in publishTo:
|
||||||
v.addRowNeighbor(id, vi)
|
v.addRowNeighbor(id, vi, False)
|
||||||
for id in v.columnIDs:
|
for id in v.columnIDs:
|
||||||
count = min(self.proposerPublishTo, len(columnChannels[id]))
|
count = min(self.proposerPublishTo, len(columnChannels[id]))
|
||||||
publishTo = random.sample(columnChannels[id], count)
|
publishTo = random.sample(columnChannels[id], count)
|
||||||
for vi in publishTo:
|
for vi in publishTo:
|
||||||
v.addColumnNeighbor(id, vi)
|
v.addColumnNeighbor(id, vi, False)
|
||||||
|
|
||||||
if self.logger.isEnabledFor(logging.DEBUG):
|
if self.logger.isEnabledFor(logging.DEBUG):
|
||||||
for i in range(0, self.shape.numberNodes):
|
for i in range(0, self.shape.numberNodes):
|
||||||
|
|
Loading…
Reference in New Issue