Subsection on parallelization
This commit is contained in:
+83
-2
@@ -1177,6 +1177,87 @@ schemes that allow for the injection of realistic laser pulses
|
||||
|
||||
% Eliasson_2002.pdf outflow condition for Fourier transformed Vlasov-poison system
|
||||
|
||||
\subsection{Parallelization}
|
||||
\label{subsec:num:parallel}
|
||||
|
||||
Hopefully you are convinced by now that Particle-in-Cell codes are actually a
|
||||
fairly approachable simulation method that can great insights into the
|
||||
microphysics of kinetic plasmas. But there is one downside compared to other
|
||||
methods explained in this book: A huge number of particles and a large number
|
||||
of time steps is required to simulate physically relevant systems. And even
|
||||
then we are not covering macroscopic scales. To increase the maximum size of
|
||||
the problem that can be studied and to reduce the time a scientist has to wait
|
||||
before obtaining results that can be studied parallelization is extremly common
|
||||
and has been used for a long time.
|
||||
|
||||
This parallelization can make use of vectorization in the form of
|
||||
single-instruction-multiple-data (SIMD) \cite{Bowers_2008}. Details of this
|
||||
depend on the platform that the code targets (CPUs, GPUs, accelerator cards and
|
||||
so on). The recent arrival of performance portability frameworks such as Kokkos
|
||||
\cite{Edwards_2014} or RAJA \cite{Beckingsale_2019} are changing the codes from
|
||||
carefully formulated C++ and Fortran codes that can be vectorized by the
|
||||
compiler and handwritten assembler primitives to higher level of abstraction.
|
||||
While good reference literature on the topic is rare, the field is changing too
|
||||
rapidly for us to give good advice that will still be relevant in one or two
|
||||
decades.
|
||||
|
||||
The next level of parallelization that is often employed is the use of parallel
|
||||
threads within a process. This might be OpenMP threads \cite{Dagum_1998,
|
||||
Larsgard_2007}, pthreads or other language level features for parallelism. This
|
||||
can be used to use the multiple cores that all current computers offer. Often
|
||||
the user has to manually ensure that no data races or other problems between
|
||||
different threads exist. Since this can be hard to ensure, some codes opt not
|
||||
to make use of these techniques.
|
||||
|
||||
Since the compute power of a single machine is only sufficient for very
|
||||
selected problems and the memory can only hold approximately one billion
|
||||
particles in RAM, it is commonly required to parallelize the code over many
|
||||
nodes. Each node runs one (or more) separate process that communicate with
|
||||
eachother and share the simulation workload. For the communication MPI
|
||||
\cite{Walker_1996} is the defacto standard but recently frameworks have started
|
||||
to appear that take care of threading and communication for the programmer.
|
||||
|
||||
The common way to distribute the workload is to split the simulation domain
|
||||
into smaller local domains (also known as patches or blocks). Each process is
|
||||
then responsible for the particles and fields in that local domain
|
||||
\cite{Pfund_1998, Plimpton_2000, Qiang_2000, Messmer_2001, Qiang_2010}. The
|
||||
state of the electromagnetic field in neighbouring domains is then copied into
|
||||
ghost zones that surround the local domain and act as boundary
|
||||
conditions\footnote{The reason why this works efficiantly is that the the
|
||||
particle shape function have only compact support and the field update only
|
||||
requiring neighboring cells. However with extra effort domain decomposition can
|
||||
also be applied to spectral solvers\cite{Vay_2013}.}. Particles that hit the
|
||||
boundary of the local domain are communicated to the neighbouring process,
|
||||
inject from the wall there and are removed from the local domain.
|
||||
Particle-in-Cell codes tend to parallelize very efficiently using this method
|
||||
since only communication with a handfull of neighbors is required and global
|
||||
all-to-all messaging can be nearly completely avoided. The only caveat is that
|
||||
efficiency only remains high as long as all processes have fairly balanced
|
||||
workloads. If the setup starts unbalanced (e.g. because of a bad decomposition
|
||||
or because of inhomogeneous plasma density) or develops load imbalances over
|
||||
the course of the simulation (typically in reconnection simulations when
|
||||
plasmoids are generated, or shock simulations where the downstream has higher
|
||||
density than the upstream) the parallelization efficancy drops. One can attempt
|
||||
to improve load balance the simulation by imoving the boundaries between local
|
||||
domains and making additional grid cells and particles the responsibility of
|
||||
less loaded processes, but this requires much more complicated code and incures
|
||||
additional costs.
|
||||
|
||||
An alternative to splitting the global domain into rectangular or brick-shaped
|
||||
local domains is to compute a space filling curve that forms a 1d path that
|
||||
goes through all grid cells exactly once
|
||||
\cite{Beck_2016,Germaschewski_2016,Barsamian_2018,Miller_2021}. Additionally
|
||||
the space filling curve has the properties that grid cells that are close to
|
||||
each other along the curve are also mostly close to each other in the full 2d
|
||||
or 3d space. When the curve is then cut into segments to be distributed across
|
||||
processes the cells of each process tend to be close to each other. For most of
|
||||
it's grid cells the process also owns the neighbouring field values and can use
|
||||
those without additional communication. Moving particles that enter another
|
||||
grid cell are likely to stay with the same process. If they do leave they are
|
||||
communicated to the correct neighboruing process same as in the case with patch
|
||||
based domain decomposition. The big upside is that the segments of the space
|
||||
filling curve do not have to be equally long and can be rebalanced more easily.
|
||||
|
||||
\subsection{Diagnostics}
|
||||
\label{subsec:num:diag}
|
||||
|
||||
@@ -1205,11 +1286,11 @@ the particles. The diagnostic is also very valuable to check conservation of tot
|
||||
Another obvious candidate for output are gridded quantities, such as electric
|
||||
and magnetic field as well as current density. These quantities do not
|
||||
require any extra calculation. The two most widely used choices are dumping
|
||||
the memory of every MPI domain to a separate binary file or writing a global
|
||||
the memory of every local domain (in a simulation that uses domain decomposition and MPI) to a separate binary file or writing a global
|
||||
view to a structured format such as HDF5\footnote{other formats are available,
|
||||
but HDF5 is widely supported by many post-processing tools}. The first choice
|
||||
has the advantage of low overhead as nearly no metadata is saved. The downside
|
||||
is that the separate views of the different domains need to be combined for
|
||||
is that the separate views of the different local domains need to be combined for
|
||||
further analysis. The overhead of creating many files at once and the tedious
|
||||
file handling make this alternative a poor choice for more than a few hundred
|
||||
cores. Parallel I/O to HDF5 requires slightly more complicated I/O code and
|
||||
|
||||
Reference in New Issue
Block a user