Search in sources :

Example 1 with PSErrorRequest

use of com.tencent.angel.protobuf.generated.PSMasterServiceProtos.PSErrorRequest in project angel by Tencent.

the class InitNeighborTest method testCSR.

@Test
public void testCSR() throws Exception {
    Worker worker = LocalClusterContext.get().getWorker(workerAttempt0Id).getWorker();
    MatrixClient client = worker.getPSAgent().getMatrixClient(SPARSE_INT_MAT, 0);
    int matrixId = client.getMatrixId();
    ParameterServer ps = LocalClusterContext.get().getPS(psAttempt0Id).getPS();
    Location masterLoc = LocalClusterContext.get().getMaster().getAppMaster().getAppContext().getMasterService().getLocation();
    TConnection connection = TConnectionManager.getConnection(ps.getConf());
    MasterProtocol master = connection.getMasterService(masterLoc.getIp(), masterLoc.getPort());
    // Init node neighbors
    Int2ObjectOpenHashMap<int[]> nodeIdToNeighbors = new Int2ObjectOpenHashMap<>();
    nodeIdToNeighbors.put(1, new int[] { 2, 3 });
    nodeIdToNeighbors.put(2, new int[] { 4 });
    InitNeighbor func = new InitNeighbor(new InitNeighborParam(matrixId, nodeIdToNeighbors));
    client.asyncUpdate(func).get();
    nodeIdToNeighbors.clear();
    nodeIdToNeighbors.put(1, new int[] { 4, 5, 6 });
    nodeIdToNeighbors.put(2, new int[] { 5 });
    nodeIdToNeighbors.put(4, new int[] { 5, 6 });
    func = new InitNeighbor(new InitNeighborParam(matrixId, nodeIdToNeighbors));
    client.asyncUpdate(func).get();
    nodeIdToNeighbors.clear();
    nodeIdToNeighbors.put(3, new int[] { 4, 5, 6 });
    nodeIdToNeighbors.put(5, new int[] { 6 });
    nodeIdToNeighbors.put(8, new int[] { 3, 4 });
    func = new InitNeighbor(new InitNeighborParam(matrixId, nodeIdToNeighbors));
    client.asyncUpdate(func).get();
    nodeIdToNeighbors.clear();
    client.asyncUpdate(new InitNeighborOver(new InitNeighborOverParam(matrixId))).get();
    // Sample the neighbors
    int[] nodeIds = new int[] { 1, 2, 3, 4, 5, 6, 7, 8 };
    SampleNeighborParam param = new SampleNeighborParam(matrixId, nodeIds, -1);
    Int2ObjectOpenHashMap<int[]> result = ((SampleNeighborResult) (client.get(new SampleNeighbor(param)))).getNodeIdToNeighbors();
    ObjectIterator<Entry<int[]>> iter = result.int2ObjectEntrySet().fastIterator();
    LOG.info("==============================sample neighbors result============================");
    Entry<int[]> entry;
    while (iter.hasNext()) {
        entry = iter.next();
        LOG.info("node id = " + entry.getIntKey() + ", neighbors = " + Arrays.toString(entry.getValue()));
    }
    client.checkpoint(0);
    ps.stop(-1);
    PSErrorRequest request = PSErrorRequest.newBuilder().setPsAttemptId(ProtobufUtil.convertToIdProto(psAttempt0Id)).setMsg("out of memory").build();
    master.psError(null, request);
    Thread.sleep(10000);
    result = ((SampleNeighborResult) (client.get(new SampleNeighbor(param)))).getNodeIdToNeighbors();
    iter = result.int2ObjectEntrySet().fastIterator();
    LOG.info("==============================sample neighbors result============================");
    while (iter.hasNext()) {
        entry = iter.next();
        LOG.info("node id = " + entry.getIntKey() + ", neighbors = " + Arrays.toString(entry.getValue()));
    }
}
Also used : Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) InitNeighborParam(com.tencent.angel.graph.client.initneighbor.InitNeighborParam) SampleNeighborResult(com.tencent.angel.graph.client.sampleneighbor.SampleNeighborResult) SampleNeighbor(com.tencent.angel.graph.client.sampleneighbor.SampleNeighbor) InitNeighbor(com.tencent.angel.graph.client.initneighbor.InitNeighbor) ParameterServer(com.tencent.angel.ps.ParameterServer) Entry(it.unimi.dsi.fastutil.ints.Int2ObjectMap.Entry) TConnection(com.tencent.angel.ipc.TConnection) InitNeighborOverParam(com.tencent.angel.graph.client.initneighbor.InitNeighborOverParam) SampleNeighborParam(com.tencent.angel.graph.client.sampleneighbor.SampleNeighborParam) Worker(com.tencent.angel.worker.Worker) MatrixClient(com.tencent.angel.psagent.matrix.MatrixClient) InitNeighborOver(com.tencent.angel.graph.client.initneighbor.InitNeighborOver) MasterProtocol(com.tencent.angel.master.MasterProtocol) PSErrorRequest(com.tencent.angel.protobuf.generated.PSMasterServiceProtos.PSErrorRequest) Location(com.tencent.angel.common.location.Location) Test(org.junit.Test)

Example 2 with PSErrorRequest

use of com.tencent.angel.protobuf.generated.PSMasterServiceProtos.PSErrorRequest in project angel by Tencent.

the class InitNeighborTest2 method testCSR.

@Test
public void testCSR() throws Exception {
    Worker worker = LocalClusterContext.get().getWorker(workerAttempt0Id).getWorker();
    MatrixClient client = worker.getPSAgent().getMatrixClient(SPARSE_INT_MAT, 0);
    int matrixId = client.getMatrixId();
    ParameterServer ps = LocalClusterContext.get().getPS(psAttempt0Id).getPS();
    Location masterLoc = LocalClusterContext.get().getMaster().getAppMaster().getAppContext().getMasterService().getLocation();
    TConnection connection = TConnectionManager.getConnection(ps.getConf());
    MasterProtocol master = connection.getMasterService(masterLoc.getIp(), masterLoc.getPort());
    // Init node neighbors
    Long2ObjectOpenHashMap<long[]> nodeIdToNeighbors = new Long2ObjectOpenHashMap<>();
    nodeIdToNeighbors.put(1, new long[] { 2, 3, 4, 5, 6 });
    nodeIdToNeighbors.put(2, new long[] { 4, 5 });
    nodeIdToNeighbors.put(3, new long[] { 4, 5, 6 });
    nodeIdToNeighbors.put(4, new long[] { 5, 6 });
    nodeIdToNeighbors.put(5, new long[] { 6 });
    nodeIdToNeighbors.put(8, new long[] { 3, 4 });
    InitNeighbor func = new InitNeighbor(new InitNeighborParam(matrixId, nodeIdToNeighbors));
    client.asyncUpdate(func).get();
    nodeIdToNeighbors.clear();
    /*nodeIdToNeighbors.put(1, new long[]{4, 5, 6});
    nodeIdToNeighbors.put(2, new long[]{5});
    nodeIdToNeighbors.put(4, new long[]{5, 6});
    func = new InitNeighbor(new InitNeighborParam(matrixId, nodeIdToNeighbors));
    client.asyncUpdate(func).get();
    nodeIdToNeighbors.clear();

    nodeIdToNeighbors.put(3, new long[]{4, 5, 6});
    nodeIdToNeighbors.put(5, new long[]{6});
    nodeIdToNeighbors.put(8, new long[]{3, 4});
    func = new InitNeighbor(new InitNeighborParam(matrixId, nodeIdToNeighbors));
    client.asyncUpdate(func).get();
    nodeIdToNeighbors.clear();
    */
    // client.asyncUpdate(new InitNeighborOver(new InitNeighborOverParam(matrixId))).get();
    // Sample the neighbors
    long[] nodeIds = new long[] { 1, 2, 3, 4, 5, 6, 7, 8 };
    SampleNeighborParam param = new SampleNeighborParam(matrixId, nodeIds, 2);
    Long2ObjectOpenHashMap<long[]> result = ((SampleNeighborResult) (client.get(new SampleNeighbor(param)))).getNodeIdToNeighbors();
    ObjectIterator<Long2ObjectMap.Entry<long[]>> iter = result.long2ObjectEntrySet().fastIterator();
    LOG.info("==============================sample neighbors result============================");
    Long2ObjectMap.Entry<long[]> entry;
    while (iter.hasNext()) {
        entry = iter.next();
        LOG.info("node id = " + entry.getLongKey() + ", neighbors = " + Arrays.toString(entry.getValue()));
    }
    client.checkpoint(0).get();
    ps.stop(-1);
    PSErrorRequest request = PSErrorRequest.newBuilder().setPsAttemptId(ProtobufUtil.convertToIdProto(psAttempt0Id)).setMsg("out of memory").build();
    master.psError(null, request);
    Thread.sleep(10000);
    param = new SampleNeighborParam(matrixId, nodeIds, -1);
    result = ((SampleNeighborResult) (client.get(new SampleNeighbor(param)))).getNodeIdToNeighbors();
    iter = result.long2ObjectEntrySet().fastIterator();
    LOG.info("==============================sample neighbors result============================");
    while (iter.hasNext()) {
        entry = iter.next();
        LOG.info("node id = " + entry.getLongKey() + ", neighbors = " + Arrays.toString(entry.getValue()));
    }
}
Also used : InitNeighborParam(com.tencent.angel.graph.client.initneighbor2.InitNeighborParam) SampleNeighborResult(com.tencent.angel.graph.client.sampleneighbor2.SampleNeighborResult) Long2ObjectMap(it.unimi.dsi.fastutil.longs.Long2ObjectMap) SampleNeighbor(com.tencent.angel.graph.client.sampleneighbor2.SampleNeighbor) InitNeighbor(com.tencent.angel.graph.client.initneighbor2.InitNeighbor) Long2ObjectOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap) ParameterServer(com.tencent.angel.ps.ParameterServer) TConnection(com.tencent.angel.ipc.TConnection) SampleNeighborParam(com.tencent.angel.graph.client.sampleneighbor2.SampleNeighborParam) Worker(com.tencent.angel.worker.Worker) MatrixClient(com.tencent.angel.psagent.matrix.MatrixClient) MasterProtocol(com.tencent.angel.master.MasterProtocol) PSErrorRequest(com.tencent.angel.protobuf.generated.PSMasterServiceProtos.PSErrorRequest) Location(com.tencent.angel.common.location.Location) Test(org.junit.Test)

Aggregations

Location (com.tencent.angel.common.location.Location)2 TConnection (com.tencent.angel.ipc.TConnection)2 MasterProtocol (com.tencent.angel.master.MasterProtocol)2 PSErrorRequest (com.tencent.angel.protobuf.generated.PSMasterServiceProtos.PSErrorRequest)2 ParameterServer (com.tencent.angel.ps.ParameterServer)2 MatrixClient (com.tencent.angel.psagent.matrix.MatrixClient)2 Worker (com.tencent.angel.worker.Worker)2 Test (org.junit.Test)2 InitNeighbor (com.tencent.angel.graph.client.initneighbor.InitNeighbor)1 InitNeighborOver (com.tencent.angel.graph.client.initneighbor.InitNeighborOver)1 InitNeighborOverParam (com.tencent.angel.graph.client.initneighbor.InitNeighborOverParam)1 InitNeighborParam (com.tencent.angel.graph.client.initneighbor.InitNeighborParam)1 InitNeighbor (com.tencent.angel.graph.client.initneighbor2.InitNeighbor)1 InitNeighborParam (com.tencent.angel.graph.client.initneighbor2.InitNeighborParam)1 SampleNeighbor (com.tencent.angel.graph.client.sampleneighbor.SampleNeighbor)1 SampleNeighborParam (com.tencent.angel.graph.client.sampleneighbor.SampleNeighborParam)1 SampleNeighborResult (com.tencent.angel.graph.client.sampleneighbor.SampleNeighborResult)1 SampleNeighbor (com.tencent.angel.graph.client.sampleneighbor2.SampleNeighbor)1 SampleNeighborParam (com.tencent.angel.graph.client.sampleneighbor2.SampleNeighborParam)1 SampleNeighborResult (com.tencent.angel.graph.client.sampleneighbor2.SampleNeighborResult)1