+1 vote
asked by (180 points)
reshown ago by
In my project I have to run a long DMRG calculation for different values of particle interactions, and I would like to run the different calculations in parallel. For this I implement a naive OpenMP parallel computing the following way:

Add the "-fopenmp" flag in compilation

Run my entire program within a for-loop initialized with "#pragma omp parallel for".

The processes run for about 40-60 sweeps (of 128), after which I get "Segmentation fault (core dumped)". Is the DMRG code in ITensor not thread-safe?
commented ago by (20.8k points)
Hi, before I try to answer the question, may I ask some more details about the code? A key question is: are you putting the same wavefunction into the dmrg function? (I.e. the same variable "psi" of type MPS or IQMPS?) The reason I ask that is that psi is passed by reference, so the dmrg function overwrites it. If you passed the same one to each call to dmrg then it could cause issues with different threads "racing" for the same memory. If you could post some or all of your code that would be very helpful.
commented ago by (180 points)
You can find the code at https://www.dropbox.com/s/tyov039vo7et3ky/UaaPar.cc?dl=0 though it's a bit messy. The major confusion for me is that I basically do nothing before starting the for-loop, meaning each parallel iteration has its completely own setup (as I understand it).

Another mystery is that I can run the non-parallel code on e.g. two CPU-cores by starting it through two different terminals without problems.
commented ago by (20.8k points)
Hi so this code and your comment answers my question I think. I was saying that you may need to create separate copies of the wavefunction (psi0) before calling dmrg with multiple threads. Not doing this could be the reason you got an error. On the other hand it may not fix the problem but having separate copies of the wavefunction is the first thing I'd try.

Please log in or register to answer this question.

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.