Search in sources :

Example 1 with WalkPath

use of com.tencent.angel.graph.client.node2vec.data.WalkPath in project angel by Tencent.

the class PathQueue method popBatchTail.

public static void popBatchTail(int psPartId, int batchSize, Long2ObjectOpenHashMap<long[]> result) {
    ReentrantLock queueLock = psPartId2Lock.get(psPartId);
    queueLock.lock();
    try {
        Queue<WalkPath> queue = psPartId2Queue.get(psPartId);
        int count = 0;
        while (!queue.isEmpty() && count < batchSize) {
            WalkPath wPath = queue.poll();
            result.put(wPath.getHead(), wPath.getTail2());
            count++;
        }
    } finally {
        queueLock.unlock();
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) WalkPath(com.tencent.angel.graph.client.node2vec.data.WalkPath)

Example 2 with WalkPath

use of com.tencent.angel.graph.client.node2vec.data.WalkPath in project angel by Tencent.

the class InitWalkPath method partitionUpdate.

@Override
public void partitionUpdate(PartitionUpdateParam partParam) {
    InitWalkPathPartitionParam pparam = (InitWalkPathPartitionParam) partParam;
    PartitionKey partKey = pparam.getPartKey();
    ServerLongAnyRow walkPath = (ServerLongAnyRow) psContext.getMatrixStorageManager().getRow(partKey, 0);
    ServerLongAnyRow rowNeighbor = (ServerLongAnyRow) psContext.getMatrixStorageManager().getRow(pparam.getNeighborMatrixId(), 0, partKey.getPartitionId());
    Random rand = new Random();
    ObjectIterator<Long2ObjectMap.Entry<IElement>> iter = rowNeighbor.iterator();
    walkPath.startWrite();
    walkPath.clear();
    PathQueue.init(partKey.getPartitionId());
    PathQueue.setThreshold(pparam.getThreshold());
    PathQueue.setKeepProba(pparam.getKeepProba());
    PathQueue.setNumParts(pparam.getNumParts());
    PathQueue.setIsTrunc(pparam.isTrunc());
    try {
        int count = 0;
        int batchSize = 1024;
        ArrayList<WalkPath> batchPath = new ArrayList<>();
        while (iter.hasNext()) {
            Long2ObjectMap.Entry<IElement> entry = iter.next();
            long key = entry.getLongKey() + partKey.getStartCol();
            LongArrayElement value = (LongArrayElement) entry.getValue();
            long[] neighbor = value.getData();
            long neigh = neighbor[rand.nextInt(neighbor.length)];
            WalkPath wPath = new WalkPath(pparam.getWalkLength(), key, neigh);
            walkPath.set(key, wPath);
            batchPath.add(wPath);
            count++;
            if (count % batchSize == 0) {
                PathQueue.initPushBatch(partKey.getPartitionId(), batchPath);
                batchPath.clear();
            }
        }
        if (!batchPath.isEmpty()) {
            PathQueue.initPushBatch(partKey.getPartitionId(), batchPath);
            batchPath.clear();
        }
    } finally {
        walkPath.endWrite();
    }
}
Also used : IElement(com.tencent.angel.ps.storage.vector.element.IElement) Long2ObjectMap(it.unimi.dsi.fastutil.longs.Long2ObjectMap) ArrayList(java.util.ArrayList) LongArrayElement(com.tencent.angel.ps.storage.vector.element.LongArrayElement) ServerLongAnyRow(com.tencent.angel.ps.storage.vector.ServerLongAnyRow) Random(java.util.Random) PartitionKey(com.tencent.angel.PartitionKey) WalkPath(com.tencent.angel.graph.client.node2vec.data.WalkPath)

Example 3 with WalkPath

use of com.tencent.angel.graph.client.node2vec.data.WalkPath in project angel by Tencent.

the class PathQueue method initPushBatch.

public static void initPushBatch(int psPartId, List<WalkPath> paths) {
    ReentrantLock queueLock = psPartId2Lock.get(psPartId);
    queueLock.lock();
    try {
        Queue<WalkPath> queue = psPartId2Queue.get(psPartId);
        queue.addAll(paths);
    } finally {
        queueLock.unlock();
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) WalkPath(com.tencent.angel.graph.client.node2vec.data.WalkPath)

Example 4 with WalkPath

use of com.tencent.angel.graph.client.node2vec.data.WalkPath in project angel by Tencent.

the class PathQueue method pushBatch.

public static void pushBatch(int psPartId, ServerLongAnyRow row, Long2LongOpenHashMap pathTail) {
    ReentrantLock queueLock = psPartId2Lock.get(psPartId);
    int completeCount = 0;
    queueLock.lock();
    try {
        Queue<WalkPath> queue = psPartId2Queue.get(psPartId);
        for (Map.Entry<Long, Long> entry : pathTail.entrySet()) {
            long key = entry.getKey();
            long tail = entry.getValue();
            WalkPath wPath = (WalkPath) row.get(key);
            wPath.add2Path(tail);
            if (wPath.isComplete()) {
                completeCount += 1;
            } else {
                queue.add(wPath);
            }
        }
        progress.put(psPartId, progress.get(psPartId) + completeCount);
    } finally {
        queueLock.unlock();
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) WalkPath(com.tencent.angel.graph.client.node2vec.data.WalkPath) Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) Long2LongOpenHashMap(it.unimi.dsi.fastutil.longs.Long2LongOpenHashMap) Long2ObjectOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap) Map(java.util.Map) Int2IntOpenHashMap(it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap)

Example 5 with WalkPath

use of com.tencent.angel.graph.client.node2vec.data.WalkPath in project angel by Tencent.

the class PathQueue method popBatchTail.

public static Long2ObjectOpenHashMap<long[]> popBatchTail(int psPartId, int batchSize) {
    ReentrantLock queueLock = psPartId2Lock.get(psPartId);
    queueLock.lock();
    Long2ObjectOpenHashMap<long[]> result;
    try {
        Queue<WalkPath> queue = psPartId2Queue.get(psPartId);
        int count = 0;
        result = new Long2ObjectOpenHashMap<>(batchSize);
        while (!queue.isEmpty() && count < batchSize) {
            WalkPath wPath = queue.poll();
            result.put(wPath.getHead(), wPath.getTail2());
            count++;
        }
    } finally {
        queueLock.unlock();
    }
    return result;
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) WalkPath(com.tencent.angel.graph.client.node2vec.data.WalkPath)

Aggregations

WalkPath (com.tencent.angel.graph.client.node2vec.data.WalkPath)7 ReentrantLock (java.util.concurrent.locks.ReentrantLock)6 PartitionKey (com.tencent.angel.PartitionKey)1 ServerLongAnyRow (com.tencent.angel.ps.storage.vector.ServerLongAnyRow)1 IElement (com.tencent.angel.ps.storage.vector.element.IElement)1 LongArrayElement (com.tencent.angel.ps.storage.vector.element.LongArrayElement)1 Int2IntOpenHashMap (it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap)1 Int2ObjectOpenHashMap (it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap)1 Long2LongOpenHashMap (it.unimi.dsi.fastutil.longs.Long2LongOpenHashMap)1 Long2ObjectMap (it.unimi.dsi.fastutil.longs.Long2ObjectMap)1 Long2ObjectOpenHashMap (it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Random (java.util.Random)1