コード例 #1
0
    def passiveProcess(self, stopper):
        self.mover.passive(self.skeleton, stopper)  # Non-trivial for Smooth
        moveData = cfiddler.Recv_MoveData(stopper, tag=self.move_channel)
        node = self.skeleton.getNodeWithIndex(moveData.index)
##        REPORT("HELPING", stopper, "FOR NODE #", node.remoteIndex(stopper))
        
        # recording energy-before (should this use periodic neighbor Elements?)
        neighbors = node.aperiodicNeighborElements(self.skeleton)
        reportData = [el.energyHomogeneity(self.skeleton) for el in neighbors]
        reportData += [el.energyShape() for el in neighbors]
        # move to the position -- self.skeleton is a DeputySkeleton
        self.skeleton.moveNodeTo(
            node, primitives.Point(moveData.x, moveData.y))
        # Check & send illegality
        mpitools.Send_Bool(bool(node.illegal()),
                           stopper,
                           tag=self.illegal_channel)

        # if illegal in any processes, it should be aborted
        if mpitools.Recv_Bool(
            stopper, tag=self.verdict_channel):  # True:continue, False:abort
            # recording energy-after
            reportData += [el.energyHomogeneity(self.skeleton)
                            for el in neighbors]
            reportData += [el.energyShape() for el in neighbors]
            # reporting
            mpitools.Send_DoubleVec(reportData,
                                    stopper,
                                    tag=self.report_channel)
            # receiving verdivt, True:stay, False:move back
            if not mpitools.Recv_Bool(stopper, self.verdict_channel):
                self.skeleton.moveNodeBack(node)
        else:  # Illegal!
            self.skeleton.moveNodeBack(node)
コード例 #2
0
    def passiveProcess(self, stopper):
        # the node to move
        myindex = mpitools.Recv_Int(stopper, tag=self.move_channel)
        node = self.skeleton.getNodeWithIndex(myindex)
        self.mover.passive(self.skeleton, node, stopper)

        # getting no. of move candidates
        nmoves = mpitools.Recv_Int(stopper, tag=self.move_channel)

        for i in range(nmoves):
            moveData = cfiddler.Recv_MoveData(stopper, tag=self.move_channel)
            ##            REPORT("HELPING", stopper, "FOR NODE #", node.remoteIndex(stopper))

            # recording energy-before
            neighbors = node.aperiodicNeighborElements(self.skeleton)
            reportData = [
                el.energyHomogeneity(self.skeleton) for el in neighbors
            ]
            reportData += [el.energyShape() for el in neighbors]
            # move to the position -- self.skeleton is a DeputySkeleton
            self.skeleton.moveNodeTo(node,
                                     primitives.Point(moveData.x, moveData.y))
            # Check & send illegality
            mpitools.Send_Bool(bool(node.illegal()),
                               stopper,
                               tag=self.illegal_channel)

            # if illegal in any processes, it should be aborted
            if mpitools.Recv_Bool(
                    stopper,
                    tag=self.verdict_channel):  # True:continue, False:abort
                # recording energy-after
                reportData += [
                    el.energyHomogeneity(self.skeleton) for el in neighbors
                ]
                reportData += [el.energyShape() for el in neighbors]
                # reporting
                mpitools.Send_DoubleVec(reportData,
                                        stopper,
                                        tag=self.report_channel)
            # reset for the next one
            self.skeleton.moveNodeBack(node)
##            REPORT("DONE HELPING", moveData.master, " ON NODE #",
##                   node.remoteIndex(moveData.master))

# receiving verdivt, True:stay, False:move back
        if mpitools.Recv_Bool(stopper, self.verdict_channel):
            x, y = mpitools.Recv_DoubleVec(stopper,
                                           tag=self.move_channel,
                                           size=2)
            self.skeleton.moveNodeTo(node, primitives.Point(x, y))
コード例 #3
0
 def passive(self, skeleton, stopper):  # Parallel mode -- share-holder
     from ooflib.SWIG.common import mpitools
     _rank = mpitools.Rank()
     # Getting the node index (local)
     index = mpitools.Recv_Int(stopper)
     node = skeleton.getNodeWithIndex(index)
     # Get the neighbor nodes (but not ones are shared with stoppers,
     # since they are already accounted for at "stopper".)
     nbrNodes = node.neighborNodes(skeleton)
     positions = []
     for nd in nbrNodes:
         if _rank == nd.master():  # my own node
             positions.append(skeleton.nodePosition(nd).x)
             positions.append(skeleton.nodePosition(nd).y)
     mpitools.Send_DoubleVec(positions, stopper)
コード例 #4
0
ファイル: fiddlenodesmethods.py プロジェクト: song2001/OOF2
 def passive(self, skeleton, node, stopper):
     from ooflib.SWIG.common import mpitools
     _rank = mpitools.Rank()
     # now, find all neighboring nodes
     neighbors = node.neighborNodes(skeleton)
     # among these, collect ones of which I'm the master.
     neighbors = [n for n in neighbors if _rank == n.master()]
     if neighbors:
         coords = [[skeleton.nodePosition(n).x,
                    skeleton.nodePosition(n).y] for n in neighbors]
         coords = reduce(lambda x,y: x+y, coords)
     else:
         coords = []
     # send the nodes
     mpitools.Send_DoubleVec(coords, stopper)