0 votes
asked by (120 points)

Hi,

I have some difficulties using multithreading for my calculations which include tensor networks (in Julia). Just to clarify, I don't want to use multiple threads to speed-up contraction of large tensors, I want to evaluate a function for multiple configurations of parameters in parallel, and have each function call use ITensor for tensor contraction.

So far I tried to use the usual Threads.@threads at a beginning of a loop, but in each try I get a different error- sometimes one of the tensors end up with too many indices, which happen randomly at multiple places in the code, and sometimes one of the threads drink up all the memory of the cluster (in which case I couldn't pinpoint the exact place in the code which causes it).

If I don't use multithreading and just evaluate the function once at a time using a regular for loop I never had these problems. It seems as if the different threads interfere with each other and modify memory which the other threads use. I also tried to explicitly disable multithreading at levels of contractions with BLAS.set_num_threads(1), but it didn't changed the results.

Am I doing something wrong? Do anyone know if there is might be some potential problems with multithreading function with ITensor calculations?

Thanks,
Matan.

commented by (64.7k points)
Hi Matan,
Good question. My first guess is that you are running in a subtle aspect of Julia and therefore of ITensor which is that, because of the reference semantics of variables in Julia and how Julia arrays work, etc, a lot of ITensor code does not make distinct copies of things like ITensor data but only views. So your multithreaded code may need to make more explicit copies of things before it begins and inside the body of your loop to avoid different threads accessing the same memory (so called “race conditions”).

To be any more specific, it would be helpful if you could provide a small example of some code that errors or doesn’t work as expected.

Thanks,
Miles

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.

Categories

...