I wrote an iterative code for Homomorphic Encryption.
Finding max/min requires 1 comparison and 1 multiplication. Multiplicative depth for comparison is O(sqrt(p-3)).

There are maxL1 outer iterations i and maxL2 inner iterations j. Comparison takes the largest depth in inner iterations and (maxL1 × maxL2) cells are compared. Hence, multiplicative depth of the algorithm is O(maxL1 × maxL2 ×(depth_cmp + 1)). For maxL1 = 4, maxL2 = 4, p = 41, this is equal to ∼ 114.

For this depth, I want my HElib code, so how can I set parameters for that?
I tried with p=41, m=1003280, nb=11000, but it gave runtime error “xdouble division by zero”, which comes when noise exceeds a threshold.

Your question is not clear to me. What iterative BGV OpenFHE code are you referring to?

Moreover, are you seeking assistance with parametrizing HElib? This might not be the ideal platform for HElib-related questions. For more targeted support, consider posting your question on the official HElib repository or forum.

I am computing a nXn Dynamic Programming matrix and filling the cells iteratively.
How do I set parameters so that I make sure that noise does not exceed before computation end?

I will surely look for HElib resources, but posted here under the general title of FHE questions for reference.

Each cell compares with the cell directly above it in the matrix, the cell to the left of it and the cell to the north-west of it. Thus, comparisons are involved for each cell computation, which increases depth of circuit.

To ensure the accuracy of your homomorphic circuit, compare it to an unencrypted ground truth implementation. As you develop your circuit, decrypt and validate the results against the ground truth at various points. Repeat this process iteratively until you have confirmed the correct functionality.

Test your circuit with diverse inputs to build confidence in its ability to compute the target functionality.

Additionally, analyze your circuit to determine its multiplicative depth (the maximum number of multiplications along any path) and set the multiplicative depth in the cryptographic parameters generation.