# Multithreading support in OpenFHE

**URL:** <https://openfhe.discourse.group/t/multithreading-support-in-openfhe/655>\
**Category:** Library Questions\
**Created:** [June 22, 2023, 10:11pm UTC](https://openfhe.discourse.group/t/multithreading-support-in-openfhe/655 "2023-06-22T22:11:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![meamit](https://avatars.discourse-cdn.com/v4/letter/m/eb8c5e/32.png) [@meamit](https://openfhe.discourse.group/u/meamit)\
**Post date:** [June 22, 2023, 10:11pm UTC](https://openfhe.discourse.group/t/multithreading-support-in-openfhe/655/1 "2023-06-22T22:11:01Z")

</div>

Is there any way of parallel processing so that a program takes less time while running like what we can do during the “make” of the library?

---

<div class="post-metadata">

**Author:** ![iquah](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/iquah/32/8_2.png) [@iquah](https://openfhe.discourse.group/u/iquah)\
**Post date:** [June 22, 2023, 11:01pm UTC](https://openfhe.discourse.group/t/multithreading-support-in-openfhe/655/2 "2023-06-22T23:01:02Z")

</div>

Under the hood OpenFHE already uses [OpenMP](https://www.openmp.org/) and it defaults to the max number of threads. To see open mp being used in the code check out [openfhe-development/src/core/lib/math/matrix.cpp](https://github.com/openfheorg/openfhe-development/blob/a7415334b8fc033501809d9547be92fb90228c0a/src/core/lib/math/matrix.cpp#L121) where you can see the `#pragma omp parallel for ` being used.

```c++
template <class Element>
Matrix<Element>& Matrix<Element>::operator-=(Matrix<Element> const& other) {
    if (rows != other.rows || cols != other.cols) {
        OPENFHE_THROW(math_error, "Subtraction operands have incompatible dimensions");
    }
#pragma omp parallel for // <- HERE
    for (size_t j = 0; j < cols; ++j) {
        for (size_t i = 0; i < rows; ++i) {
            data[i][j] -= other.data[i][j];
        }
    }

    return *this;
}

```

Another user was looking at using direct multithreading [Multi-threading ciphertext multiplication and bootstrapping](https://openfhe.discourse.group/t/multi-threading-ciphertext-multiplication-and-bootstrapping/634) but I’m not sure if it’s applicable to you. Also feel free to check out [CMakeLists.txt](https://github.com/openfheorg/openfhe-development/blob/main/CMakeLists.txt#L388) to see the CMake that relates to openmp
