# Multithreading in iTensor

**URL:** <https://itensor.discourse.group/t/multithreading-in-itensor/285>\
**Category:** ITensor Julia Questions\
**Created:** [July 26, 2022, 8:52pm UTC](https://itensor.discourse.group/t/multithreading-in-itensor/285 "2022-07-26T20:52:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ray-l](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/ray-l/32/76_2.png) [@ray-l](https://itensor.discourse.group/u/ray-l)\
**Post date:** [July 26, 2022, 8:52pm UTC](https://itensor.discourse.group/t/multithreading-in-itensor/285/1 "2022-07-26T20:52:45Z")

</div>

Hi there,

I have a question about the performance of iTensor when it comes to multithreading.

Basically, I have a number of different configurations (in this case let’s assume they are based on the same physical system but each with different amount of site disorder). And I’m running a DMRG calculation, solving for the lowest ~20 excited states. Now, my naive approach in speeding up the calculation, was to run the script with

```auto
julia -t NUM mydmrg.jl

```

Where NUM is the number of threads that I have. And then with in the script, I simply have a line

```auto
Threads.@threads for case=1:numcases
 run_dmrg(args, case)
end 

```

Where each instance of run\_dmrg() is a standalone dmrg calculation for a particular configuration. What I noticed however, was that this is much slower than if I’m just running the cases sequentially. That is, the script with **numcases=1,** runs for about an hour, where a calculation of **numcases=40** takes about 15 hours.

I assume these are separate instances of the function and there are no internal communications between them whatsoever, so iTensor must have some multithreading built into the evaluation of dmrg? On the other hand, for the singular calculation (numcases=1), memory usage is only at 2.7% so there seems to be something else going on.

---

<div class="post-metadata">

**Author:** ![mtfishman](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/mtfishman/32/11_2.png) [@mtfishman](https://itensor.discourse.group/u/mtfishman)\
**Post date:** [July 27, 2022, 1:51am UTC](https://itensor.discourse.group/t/multithreading-in-itensor/285/2 "2022-07-27T01:51:33Z")

</div>

Julia threads and BLAS/LAPACK threads (used internally in ITensor for matrix multiplications and factorizations) can clash with each other.

Please try disabling BLAS/LAPACK threading with:

```julia
using LinearAlgebra
BLAS.set_num_threads(1)

```

at the beginning of your script and see if that helps.
