use of com.tencent.angel.ps.storage.partition.RowBasedPartition in project angel by Tencent.
the class InitNeighborAliasTable method partitionUpdate.
@Override
public void partitionUpdate(PartitionUpdateParam partParam) {
PartInitNeighborAliasTableParam param = (PartInitNeighborAliasTableParam) partParam;
ServerMatrix matrix = psContext.getMatrixStorageManager().getMatrix(partParam.getMatrixId());
RowBasedPartition part = (RowBasedPartition) matrix.getPartition(partParam.getPartKey().getPartitionId());
ServerLongAnyRow row = (ServerLongAnyRow) part.getRow(0);
ObjectIterator<Long2ObjectMap.Entry<NeighborsAliasTableElement>> iter = param.getNodeId2Neighbors().long2ObjectEntrySet().iterator();
row.startWrite();
try {
while (iter.hasNext()) {
Long2ObjectMap.Entry<NeighborsAliasTableElement> entry = iter.next();
NeighborsAliasTableElement element = entry.getValue();
if (element == null) {
row.set(entry.getLongKey(), null);
} else {
row.set(entry.getLongKey(), new NeighborsAliasTableElement(element.getNeighborIds(), element.getAccept(), element.getAlias()));
}
}
} finally {
row.endWrite();
}
}
use of com.tencent.angel.ps.storage.partition.RowBasedPartition in project angel by Tencent.
the class GetNeighborAliasTable method partitionGet.
@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
PartGetNeighborAliasTableParam param = (PartGetNeighborAliasTableParam) partParam;
ServerMatrix matrix = psContext.getMatrixStorageManager().getMatrix(partParam.getMatrixId());
ServerPartition part = matrix.getPartition(partParam.getPartKey().getPartitionId());
ServerLongAnyRow row = (ServerLongAnyRow) (((RowBasedPartition) part).getRow(0));
long[] nodeIds = param.getNodeIds();
long[][] neighbors = new long[nodeIds.length][];
int[] count = param.getCount();
Random r = new Random();
for (int i = 0; i < nodeIds.length; i++) {
long nodeId = nodeIds[i];
// Get node neighbor number
NeighborsAliasTableElement element = (NeighborsAliasTableElement) (row.get(nodeId));
if (element == null) {
neighbors[i] = null;
} else {
long[] nodeNeighbors = element.getNeighborIds();
if (nodeNeighbors == null || nodeNeighbors.length == 0 || count[i] <= 0) {
neighbors[i] = null;
} else {
neighbors[i] = new long[count[i]];
// start sampling by alias table for count times
float[] accept = element.getAccept();
int[] alias = element.getAlias();
for (int j = 0; j < count[i]; j++) {
int index = r.nextInt(nodeNeighbors.length);
float ac = r.nextFloat();
if (ac < accept[index]) {
neighbors[i][j] = nodeNeighbors[index];
} else {
neighbors[i][j] = nodeNeighbors[alias[index]];
}
}
}
}
}
return new PartGetNeighborAliasTableResult(part.getPartitionKey().getPartitionId(), neighbors);
}
use of com.tencent.angel.ps.storage.partition.RowBasedPartition in project angel by Tencent.
the class InitOutDegreeFunc method partitionUpdate.
@Override
public void partitionUpdate(PartitionUpdateParam partParam) {
PartInitOutDegreeParam param = (PartInitOutDegreeParam) partParam;
ServerMatrix matrix = psContext.getMatrixStorageManager().getMatrix(partParam.getMatrixId());
RowBasedPartition part = (RowBasedPartition) matrix.getPartition(partParam.getPartKey().getPartitionId());
ServerLongIntRow row = (ServerLongIntRow) part.getRow(0);
ObjectIterator<Long2IntMap.Entry> iter = param.getNodeIdToOutDegree().long2IntEntrySet().iterator();
row.startWrite();
try {
while (iter.hasNext()) {
Long2IntMap.Entry entry = iter.next();
row.set(entry.getLongKey(), entry.getIntValue());
}
} finally {
row.endWrite();
}
}
Aggregations