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();
}
}
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();
}
}
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();
}
}
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();
}
}
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;
}
Aggregations