Search in sources :

Example 1 with CompSparseLongKeyDoubleVector

use of com.tencent.angel.ml.math.vector.CompSparseLongKeyDoubleVector in project angel by Tencent.

the class LongKeyTestTask method run.

@Override
public void run(TaskContext taskContext) throws AngelException {
    try {
        MatrixClient client = taskContext.getMatrix("longkey_test");
        while (taskContext.getEpoch() < 100) {
            long startTs = System.currentTimeMillis();
            TVector row = client.getRow(0);
            LOG.info("Task " + taskContext.getTaskId() + " in iteration " + taskContext.getEpoch() + " pull use time=" + (System.currentTimeMillis() - startTs) + ", sum=" + ((CompSparseLongKeyDoubleVector) row).sum());
            startTs = System.currentTimeMillis();
            CompSparseLongKeyDoubleVector deltaV = new CompSparseLongKeyDoubleVector(client.getMatrixId(), 0, 2100000000, 110000000);
            SparseLongKeyDoubleVector deltaV1 = new SparseLongKeyDoubleVector(2100000000, 150000000);
            DenseDoubleVector deltaV2 = new DenseDoubleVector(110000000);
            for (int i = 0; i < 2100000000; i += 20) {
                deltaV.set(i, 1.0);
                deltaV1.set(i, 1.0);
            }
            for (int i = 0; i < 110000000; i++) {
                deltaV2.set(i, 1.0);
            }
            startTs = System.currentTimeMillis();
            int tryNum = 100;
            while (tryNum-- > 0) {
                deltaV.timesBy(2.0);
            }
            LOG.info("combine times use time " + (System.currentTimeMillis() - startTs));
            startTs = System.currentTimeMillis();
            tryNum = 100;
            while (tryNum-- > 0) {
                deltaV1.timesBy(2.0);
            }
            LOG.info("single times use time " + (System.currentTimeMillis() - startTs));
            startTs = System.currentTimeMillis();
            tryNum = 100;
            while (tryNum-- > 0) {
                deltaV2.timesBy(2.0);
            }
            LOG.info("dense times use time " + (System.currentTimeMillis() - startTs));
            deltaV.setMatrixId(client.getMatrixId());
            deltaV.setRowId(0);
            LOG.info("Task " + taskContext.getTaskId() + " in iteration " + taskContext.getEpoch() + " train use time=" + (System.currentTimeMillis() - startTs));
            startTs = System.currentTimeMillis();
            client.increment(deltaV);
            client.clock().get();
            LOG.info("Task " + taskContext.getTaskId() + " in iteration " + taskContext.getEpoch() + " flush use time=" + (System.currentTimeMillis() - startTs));
            taskContext.incEpoch();
        }
    } catch (Throwable x) {
        throw new AngelException("run task failed ", x);
    }
}
Also used : AngelException(com.tencent.angel.exception.AngelException) CompSparseLongKeyDoubleVector(com.tencent.angel.ml.math.vector.CompSparseLongKeyDoubleVector) DenseDoubleVector(com.tencent.angel.ml.math.vector.DenseDoubleVector) MatrixClient(com.tencent.angel.psagent.matrix.MatrixClient) TVector(com.tencent.angel.ml.math.TVector) CompSparseLongKeyDoubleVector(com.tencent.angel.ml.math.vector.CompSparseLongKeyDoubleVector) SparseLongKeyDoubleVector(com.tencent.angel.ml.math.vector.SparseLongKeyDoubleVector)

Aggregations

AngelException (com.tencent.angel.exception.AngelException)1 TVector (com.tencent.angel.ml.math.TVector)1 CompSparseLongKeyDoubleVector (com.tencent.angel.ml.math.vector.CompSparseLongKeyDoubleVector)1 DenseDoubleVector (com.tencent.angel.ml.math.vector.DenseDoubleVector)1 SparseLongKeyDoubleVector (com.tencent.angel.ml.math.vector.SparseLongKeyDoubleVector)1 MatrixClient (com.tencent.angel.psagent.matrix.MatrixClient)1