Hierarchical parallel with OpenFHE using OpenMP

Hi

I’m researching parallel processing using CKKS, and it seems the OpenFHE library internally implements parallel processing using OpenMP.

I’d like to perform hierarchical parallel processing using the code below. Is this possible?

    //Enables hierarchical parallel processing
    omp_set_nested(1);

    ・・・

    //Hierarchical parallel processing
    #pragma omp parallel for num_threads(2)
    for (int i=0; i<2; i++){
        cryptoContext->EvalMult(ciph, ciph);
    }

I’m using a MacBook Pro (8 cores) with M1, so I’m assuming that two threads will be assigned to the for loop and four threads to the OpenFHE function, for a total of 2 * 4 = 8 threads. Is that correct?

A couple of things. Use omp_set_max_active_levels() instead of omp_set_nested(). With omp_set_max_active_levels(1), the loop would run with 2 threads and the internal EvalMult() execution would be serialized. With omp_set_max_active_levels(2), the loop would run with 2 threads and the internal EvalMult() execution would be parallelized. Make sure to add a new omp_set_max_active_levels(1) at the end of your code to prevent other code in the library from running with 2 levels, which could cause a large decrease in performance.

I got it.

Thank you!