# Hierarchical parallel with OpenFHE using OpenMP

**URL:** <https://openfhe.discourse.group/t/hierarchical-parallel-with-openfhe-using-openmp/2259>\
**Category:** Library Questions\
**Tags:** questions, openfhe-help\
**Created:** [January 16, 2026, 4:27pm UTC](https://openfhe.discourse.group/t/hierarchical-parallel-with-openfhe-using-openmp/2259 "2026-01-16T16:27:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cappuccino](https://avatars.discourse-cdn.com/v4/letter/c/aeb1de/32.png) [@cappuccino](https://openfhe.discourse.group/u/cappuccino)\
**Post date:** [January 16, 2026, 4:27pm UTC](https://openfhe.discourse.group/t/hierarchical-parallel-with-openfhe-using-openmp/2259/1 "2026-01-16T16:27:19Z")

</div>

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?

```auto
    //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?

---

<div class="post-metadata">

**Author:** ![pascoe](https://avatars.discourse-cdn.com/v4/letter/p/90ced4/32.png) [@pascoe](https://openfhe.discourse.group/u/pascoe)\
**Post date:** [January 21, 2026, 5:43pm UTC](https://openfhe.discourse.group/t/hierarchical-parallel-with-openfhe-using-openmp/2259/2 "2026-01-21T17:43:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![cappuccino](https://avatars.discourse-cdn.com/v4/letter/c/aeb1de/32.png) [@cappuccino](https://openfhe.discourse.group/u/cappuccino)\
**Post date:** [January 22, 2026, 3:33pm UTC](https://openfhe.discourse.group/t/hierarchical-parallel-with-openfhe-using-openmp/2259/3 "2026-01-22T15:33:51Z")

</div>

I got it.

Thank you!
