Search in sources :

Example 6 with ServerMatrix

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);
}
Also used : ServerMatrix(com.tencent.angel.ps.storage.matrix.ServerMatrix) RowBasedPartition(com.tencent.angel.ps.storage.partition.RowBasedPartition) ServerLongAnyRow(com.tencent.angel.ps.storage.vector.ServerLongAnyRow) ServerPartition(com.tencent.angel.ps.storage.partition.ServerPartition)

Example 7 with ServerMatrix

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();
    }
}
Also used : ServerMatrix(com.tencent.angel.ps.storage.matrix.ServerMatrix) Long2ObjectMap(it.unimi.dsi.fastutil.longs.Long2ObjectMap) IOException(java.io.IOException) RowBasedPartition(com.tencent.angel.ps.storage.partition.RowBasedPartition) ServerLongAnyRow(com.tencent.angel.ps.storage.vector.ServerLongAnyRow)

Example 8 with ServerMatrix

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);
    }
}
Also used : ServerMatrix(com.tencent.angel.ps.storage.matrix.ServerMatrix) IntCSRStorage(com.tencent.angel.ps.storage.partition.storage.IntCSRStorage) CSRPartition(com.tencent.angel.ps.storage.partition.CSRPartition)

Example 9 with ServerMatrix

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();
    }
}
Also used : ServerMatrix(com.tencent.angel.ps.storage.matrix.ServerMatrix) Long2ObjectMap(it.unimi.dsi.fastutil.longs.Long2ObjectMap) LongArrayElement(com.tencent.angel.ps.storage.vector.element.LongArrayElement) RowBasedPartition(com.tencent.angel.ps.storage.partition.RowBasedPartition) ServerLongAnyRow(com.tencent.angel.ps.storage.vector.ServerLongAnyRow)

Example 10 with ServerMatrix

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);
}
Also used : ServerLongLongRow(com.tencent.angel.ps.storage.vector.ServerLongLongRow) ServerMatrix(com.tencent.angel.ps.storage.matrix.ServerMatrix) RowBasedPartition(com.tencent.angel.ps.storage.partition.RowBasedPartition) ServerPartition(com.tencent.angel.ps.storage.partition.ServerPartition)

Aggregations

ServerMatrix (com.tencent.angel.ps.storage.matrix.ServerMatrix)39 RowBasedPartition (com.tencent.angel.ps.storage.partition.RowBasedPartition)28 ServerPartition (com.tencent.angel.ps.storage.partition.ServerPartition)22 ServerLongAnyRow (com.tencent.angel.ps.storage.vector.ServerLongAnyRow)15 Long2ObjectMap (it.unimi.dsi.fastutil.longs.Long2ObjectMap)5 Random (java.util.Random)5 ServerIntAnyRow (com.tencent.angel.ps.storage.vector.ServerIntAnyRow)4 CSRPartition (com.tencent.angel.ps.storage.partition.CSRPartition)3 IntCSRStorage (com.tencent.angel.ps.storage.partition.storage.IntCSRStorage)3 ServerLongIntRow (com.tencent.angel.ps.storage.vector.ServerLongIntRow)3 AngelException (com.tencent.angel.exception.AngelException)2 MatrixFormat (com.tencent.angel.model.output.format.MatrixFormat)2 Pair (com.tencent.angel.protobuf.generated.MLProtos.Pair)2 ParameterServer (com.tencent.angel.ps.ParameterServer)2 ObjectNotFoundException (com.tencent.angel.ps.server.data.exception.ObjectNotFoundException)2 MatrixStorageManager (com.tencent.angel.ps.storage.MatrixStorageManager)2 ServerAnyAnyRow (com.tencent.angel.ps.storage.vector.ServerAnyAnyRow)2 ServerLongLongRow (com.tencent.angel.ps.storage.vector.ServerLongLongRow)2 ServerRow (com.tencent.angel.ps.storage.vector.ServerRow)2 LongArrayElement (com.tencent.angel.ps.storage.vector.element.LongArrayElement)2