0 votes
asked by (440 points)


I stumbled upon a problem in conjecture with openMP and ITensor2. It may very well have nothing to do with itensor, so I apologize in advance. Googling brought me nowhere, so I hope someone here may be able to figure out what the problem is.

Basically, adding a call to omp_get_wtime() and running the program with more than a single thread completely messes up some itensor calculations.

I copied a minimal example at the end of this message. I am using the latest itensor 2 (did git pull) and LAPACK, c++11, compiling using -fopenmp.
I was only able to reproduce the problem with more than a single thread (for example, export OMP_NUM_THREADS=2). When setting export OMP_NUM_THREADS=1 , things seem to work normally.
Similarly, If I remove the double start = omp_get_wtime(); line, things seem to work properly.

Here is a minimal example:

#include "itensor/all.h"
#include <omp.h>

using namespace itensor;

    int N = 10;

    auto sites = SpinOne(N);

    auto ampo = AutoMPO(sites);
    for(int j = 1; j < N; ++j)
        ampo += 0.5,"S+",j,"S-",j+1;
        ampo += 0.5,"S-",j,"S+",j+1;
        ampo +=     "Sz",j,"Sz",j+1;
    auto H = MPO(ampo);

    auto sweeps = Sweeps(5); //number of sweeps is 5
    sweeps.maxm() = 10,20,100,100,200;
    sweeps.cutoff() = 1E-10;

    auto psi = MPS(sites);
    double start = omp_get_wtime(); 

    auto energy = dmrg(psi,H,sweeps,{"Quiet=",true});

    printfln("Ground state energy from DMRG = %.12f",energy);

    return 0;


1 Answer

0 votes
answered by (14.1k points)

That code is running fine for me in ITensor v2 and v3 for both 1 and 2 threads. I am using ITensor v2 and v3 compiled with MKL. What errors are you seeing?

Welcome to ITensor Support Q&A, where you can ask questions and receive answers from other members of the community.

Formatting Tips:
  • To format code, indent by four spaces
  • To format inline LaTeX, surround it by @@ on both sides
  • To format LaTeX on its own line, surround it by $$ above and below
  • For LaTeX, it may be necessary to backslash-escape underscore characters to obtain proper formatting. So for example writing \sum\_i to represent a sum over i.
If you cannot register due to firewall issues (e.g. you cannot see the capcha box) please email Miles Stoudenmire to ask for an account.

To report ITensor bugs, please use the issue tracker.