qcscine / qcmaquis

Release-only repository for SCINE QCMaquis, the DMRG software from the Reiher group.
BSD 3-Clause "New" or "Revised" License
32 stars 15 forks source link

Multithreading Issue with Random Guess #10

Closed v-adamgrofe closed 1 year ago

v-adamgrofe commented 2 years ago

Description of Issue:

Boost's random library is not thread safe, but the random guess loop is multithreaded (here at line 72). Given that the dmrg_random struct has static members for the random number generator means that only one is created, and simultaneously being used by multiple threads.

Symptoms:

The problem here was largely only observed when going to many threads (~44).

Proposed Solutions for Discussion:

  1. Remove the static keywords from the dmrg_random struct so that each thread can instantiate its own copy of the struct. Thus, the threads are no longer fighting over a single engine
  2. Add a mutex so that each thread can lock the engine while it is using it.

The latter solution would likely come with a performance cost since all of the threads are trying to lock the engine at once. The former solution may have a minimal cost in terms of memory because the dmrg_random struct is instantiated for each thread but would likely not experience a hit in terms of performance.

stknecht commented 2 years ago

Dear @v-adamgrofe thanks for filing the bug report and even providing a helpful solution. We will provide a bugfix ASAP. :)

AlbertoBaiardi commented 1 year ago

@v-adamgrofe Sorry for the late reply - I just opened a branch associated with this MR and will fix the problem ASAP. In the end, me and @stknecht decided to just make that part of the code serial, since the MPS initialization will never be an intensive part of the code.

We will keep you posted!

adam-grofe commented 1 year ago

@AlbertoBaiardi No problem. I have already implemented the same solution on my end.