Skip to content

Why is chunkSize set in this way? #160

@luluzhou1

Description

@luluzhou1

Issue
In src/engine_multiexp.js line 127-137,

const opPromises = [];
        for (let i=0; i<nPoints; i += chunkSize) {
            if (logger) logger.debug(`Multiexp start: ${logText}: ${i}/${nPoints}`);
            const n= Math.min(nPoints - i, chunkSize);
            const buffBasesChunk = buffBases.slice(i*sGIn, (i+n)*sGIn);
            const buffScalarsChunk = buffScalars.slice(i*sScalar, (i+n)*sScalar);
            opPromises.push(_multiExpChunk(buffBasesChunk, buffScalarsChunk, inType, logger, logText).then( (r) => {
                if (logger) logger.debug(`Multiexp end: ${logText}: ${i}/${nPoints}`);
                return r;
            }));
        }

If I understand correctly, the purpose here is to execute the _multiExpChunk function in parallel. However, I cannot understand why chunkSize is set like this: chunkSize = Math.floor(nPoints / (tm.concurrency /nChunks)); (line 122).
For instance, in one proof generation where tm.concurrency = 10, nChunks = 18, and nPoints = 1020160, the resulting chunkSize is 1836288, which is greater than nPoints, leading to opPromises containing only one element.

Possible solution:
change line 122 to
chunkSize = Math.floor(nPoints / (tm.concurrency * nChunks));
After the change, the time spent on Multiexp has been reduced to approximately 80% of the original runtime.
I'm not entirely sure if this is the best solution, as I do not fully understand the meaning of nChunks. Any explanation of the meanings of pTSizes, bitChunkSize, and nChunks would be greatly appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions