use of com.tencent.angel.ps.storage.matrix.ServerMatrix in project angel by Tencent.
the class GetNeighborWithByteAttr method partitionGet.
@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
PartSampleNeighborWithAttrParam param = (PartSampleNeighborWithAttrParam) 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();
NeighborsAttrsCompressedElement[] elementsCompressed = new NeighborsAttrsCompressedElement[nodeIds.length];
for (int i = 0; i < nodeIds.length; i++) {
long nodeId = nodeIds[i];
// Get node neighbors
NeighborsAttrsCompressedElement elem = (NeighborsAttrsCompressedElement) (row.get(nodeId));
if (elem == null) {
elementsCompressed[i] = null;
} else {
elementsCompressed[i] = elem;
}
}
return new PartGetNeighborWithAttrResult(part.getPartitionKey().getPartitionId(), elementsCompressed);
}
use of com.tencent.angel.ps.storage.matrix.ServerMatrix in project angel by Tencent.
the class InitLongNeighborByteAttr method partitionUpdate.
@Override
public void partitionUpdate(PartitionUpdateParam partParam) {
PartInitNeighborAttrParam param = (PartInitNeighborAttrParam) 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<NeighborsAttrsElement>> iter = param.getNodeId2Neighbors().long2ObjectEntrySet().iterator();
row.startWrite();
try {
while (iter.hasNext()) {
Long2ObjectMap.Entry<NeighborsAttrsElement> entry = iter.next();
NeighborsAttrsElement elem = entry.getValue();
if (elem == null) {
row.set(entry.getLongKey(), null);
} else {
// compress the neighbor IDs
try {
byte[] compressed = Snappy.compress(elem.getNeighborIds());
NeighborsAttrsCompressedElement compressedElement = new NeighborsAttrsCompressedElement(compressed, elem.getAttrs());
row.set(entry.getLongKey(), compressedElement);
} catch (IOException e) {
LOG.error("save neighbor table error!", e);
row.set(entry.getLongKey(), null);
}
}
}
} finally {
row.endWrite();
}
}
use of com.tencent.angel.ps.storage.matrix.ServerMatrix in project angel by Tencent.
the class InitNeighbor method partitionUpdate.
@Override
public void partitionUpdate(PartitionUpdateParam partParam) {
PartInitNeighborParam param = (PartInitNeighborParam) partParam;
int[] nodeIds = param.getNodeIds();
int[] neighborNums = param.getNeighborNums();
int[] neighbors = param.getNeighbors();
ServerMatrix matrix = psContext.getMatrixStorageManager().getMatrix(param.getMatrixId());
CSRPartition part = (CSRPartition) matrix.getPartition(param.getPartKey().getPartitionId());
IntCSRStorage storage = (IntCSRStorage) part.getStorage();
synchronized (storage) {
int startOffset = (int) param.getPartKey().getStartCol();
// Store the total neighbor number of all nodes in rowOffsets
int[] rowOffsets = storage.getRowOffsets();
for (int i = 0; i < nodeIds.length; i++) {
rowOffsets[nodeIds[i] - startOffset] += neighborNums[i];
}
// Put the node ids, node neighbor number, node neighbors to the cache
List<int[]> tempRowIds = storage.getTempRowIds();
List<int[]> tempRowLens = storage.getTempRowLens();
List<int[]> tempColumnOffsets = storage.getTempColumnIndices();
if (tempRowIds == null) {
tempRowIds = new ArrayList<>();
tempRowLens = new ArrayList<>();
tempColumnOffsets = new ArrayList<>();
storage.setTempRowIds(tempRowIds);
storage.setTempRowLens(tempRowLens);
storage.setTempColumnIndices(tempColumnOffsets);
}
tempRowIds.add(param.getNodeIds());
tempRowLens.add(neighborNums);
tempColumnOffsets.add(neighbors);
}
}
use of com.tencent.angel.ps.storage.matrix.ServerMatrix in project angel by Tencent.
the class InitNeighbor method partitionUpdate.
@Override
public void partitionUpdate(PartitionUpdateParam partParam) {
PartInitNeighborParam param = (PartInitNeighborParam) 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<long[]>> iter = param.getNodeIdToNeighborIndices().long2ObjectEntrySet().iterator();
row.startWrite();
try {
while (iter.hasNext()) {
Long2ObjectMap.Entry<long[]> entry = iter.next();
row.set(entry.getLongKey(), new LongArrayElement(entry.getValue()));
}
} finally {
row.endWrite();
}
}
use of com.tencent.angel.ps.storage.matrix.ServerMatrix in project angel by Tencent.
the class GetNumNeighborEdgesFunc method partitionGet.
@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
PartGetNumNeighborEdgesParam param = (PartGetNumNeighborEdgesParam) partParam;
ServerMatrix matrix = psContext.getMatrixStorageManager().getMatrix(partParam.getMatrixId());
ServerPartition part = matrix.getPartition(partParam.getPartKey().getPartitionId());
ServerLongLongRow row = (ServerLongLongRow) (((RowBasedPartition) part).getRow(0));
long[] nodeIds = param.getNodeIds();
long[] numEdges = new long[nodeIds.length];
for (int i = 0; i < nodeIds.length; i++) {
numEdges[i] = row.get(nodeIds[i]);
}
return new PartGetNumNeighborEdgesResult(part.getPartitionKey().getPartitionId(), numEdges);
}
Aggregations