Multithreading
Before detailing the multithreading capabilities of PEPSKit, there are some general remarks to be made about parallelism in Julia. In particular, it is important to know the interaction of Julia threads and BLAS threads, and that the BLAS thread behavior is inconsistent among different vendors. Since these details have been explained many times elsewhere, we here want to point towards the MPSKit docs, which provide a good rundown of the threading behavior and what to be aware of.
PEPSKit's multithreading features are provided through OhMyThreads.jl. In addition, we also supply a differentiable parallel map, which parallelizes not only the forward pass but also the reverse pass of the map application, see PEPSKit.dtmap
. The threading behaviour can be specified through a global scheduler
that is interfaced through the set_scheduler!
function:
PEPSKit.Defaults.set_scheduler!
— Functionset_scheduler!([scheduler]; kwargs...)
Set OhMyThreads
multithreading scheduler parameters.
The function either accepts a scheduler
as an OhMyThreads.Scheduler
or as a symbol where the corresponding parameters are specificed as keyword arguments. For instance, a static scheduler that uses four tasks with chunking enabled can be set via
set_scheduler!(StaticScheduler(; ntasks=4, chunking=true))
or equivalently with
set_scheduler!(:static; ntasks=4, chunking=true)
For a detailed description of all schedulers and their keyword arguments consult the OhMyThreads documentation.
If no scheduler
is passed and only kwargs are provided, the DynamicScheduler
constructor is used with the provided kwargs.
To reset the scheduler to its default value, one calls set_scheduler!
without passing arguments which then uses the default DynamicScheduler()
. If the number of used threads is just one it falls back to SerialScheduler()
.
By default, the OhMyThreads machinery will be used to parallelize certain parts of the code, if Julia started with multiple threads. Cases where PEPSKit can leverage parallel threads are:
- CTMRG steps using the
:simultaneous
scheme, where we parallelize over all unit cell coordinates and spatial directions - The reverse pass of these parallelized CTMRG steps
- Evaluating expectation values of observables, where we parallelize over the terms contained in the
LocalOperator