Multithreading in C++

Hi,
I am using MKL platform. To use multithreading that I have followed following steps in option.mk file,
1.set ITENSOR_USE_OMP=1
2.set export MKL_NUM_THREADS=1

by calling following commands for same program

  1. OMP_NUM_THREADS=1 ./program
  2. OMP_NUM_THREADS=2 ./program
  3. OMP_NUM_THREADS=3 ./program
  4. OMP_NUM_THREADS=4 ./program

Total calculation time noted for each thread and I get,

                     run1                       run2
no. of threads       time(in milliseconds)      time(in milliseconds) 
thread 1                  91523                   91894
thread 2                  78757                   92365
thread 4                  87575                   85565
thread 8                  85563                   91352

Also here (“ConserveQNs=”,false).

Why do I get different calculation time for different threads? Or this benefits only for itensor code that conserves QN.

You are correct that multithreading inside ITensor (as opposed to BLAS multithreading) only benefits calculations that conserve quantum numbers (QN). This is because the multithreading or parallelization is done over the different sparse blocks of the tensors, and for dense (non-QN) tensors there is no sparsity.

Okay. Thank you.

1 Like