diff --git a/nummeth-ws22/fig_chapter10/Cray-1-deutsches-museum.jpg b/nummeth-ws22/fig_chapter10/Cray-1-deutsches-museum.jpg new file mode 100644 index 0000000..eeadeef Binary files /dev/null and b/nummeth-ws22/fig_chapter10/Cray-1-deutsches-museum.jpg differ diff --git a/nummeth-ws22/fig_chapter10/alltoall.pdf b/nummeth-ws22/fig_chapter10/alltoall.pdf new file mode 100644 index 0000000..3626022 Binary files /dev/null and b/nummeth-ws22/fig_chapter10/alltoall.pdf differ diff --git a/nummeth-ws22/fig_chapter10/altix.jpg b/nummeth-ws22/fig_chapter10/altix.jpg new file mode 100644 index 0000000..0dfe28b Binary files /dev/null and b/nummeth-ws22/fig_chapter10/altix.jpg differ diff --git a/nummeth-ws22/fig_chapter10/boinc.png b/nummeth-ws22/fig_chapter10/boinc.png new file mode 100644 index 0000000..f87d91a Binary files /dev/null and b/nummeth-ws22/fig_chapter10/boinc.png differ diff --git a/nummeth-ws22/fig_chapter10/burgers1.pdf b/nummeth-ws22/fig_chapter10/burgers1.pdf new file mode 100644 index 0000000..679e004 Binary files /dev/null and b/nummeth-ws22/fig_chapter10/burgers1.pdf differ diff --git a/nummeth-ws22/fig_chapter10/burgers2.pdf b/nummeth-ws22/fig_chapter10/burgers2.pdf new file mode 100644 index 0000000..dd2d58d Binary files /dev/null and b/nummeth-ws22/fig_chapter10/burgers2.pdf differ diff --git a/nummeth-ws22/fig_chapter10/caracal.png b/nummeth-ws22/fig_chapter10/caracal.png new file mode 100644 index 0000000..0ae3fcf Binary files /dev/null and b/nummeth-ws22/fig_chapter10/caracal.png differ diff --git a/nummeth-ws22/fig_chapter10/chess.pdf b/nummeth-ws22/fig_chapter10/chess.pdf new file mode 100644 index 0000000..bc2d55a Binary files /dev/null and b/nummeth-ws22/fig_chapter10/chess.pdf differ diff --git a/nummeth-ws22/fig_chapter10/cluster.png b/nummeth-ws22/fig_chapter10/cluster.png new file mode 100644 index 0000000..eae85e7 Binary files /dev/null and b/nummeth-ws22/fig_chapter10/cluster.png differ diff --git a/nummeth-ws22/fig_chapter10/diffmem.pdf b/nummeth-ws22/fig_chapter10/diffmem.pdf new file mode 100644 index 0000000..d36e61b Binary files /dev/null and b/nummeth-ws22/fig_chapter10/diffmem.pdf differ diff --git a/nummeth-ws22/fig_chapter10/diffmem2.pdf b/nummeth-ws22/fig_chapter10/diffmem2.pdf new file mode 100644 index 0000000..7967229 Binary files /dev/null and b/nummeth-ws22/fig_chapter10/diffmem2.pdf differ diff --git a/nummeth-ws22/fig_chapter10/eniac.jpg b/nummeth-ws22/fig_chapter10/eniac.jpg new file mode 100644 index 0000000..bec7b04 Binary files /dev/null and b/nummeth-ws22/fig_chapter10/eniac.jpg differ diff --git a/nummeth-ws22/fig_chapter10/ganglia.pdf b/nummeth-ws22/fig_chapter10/ganglia.pdf new file mode 100644 index 0000000..6a25307 Binary files /dev/null and b/nummeth-ws22/fig_chapter10/ganglia.pdf differ diff --git a/nummeth-ws22/fig_chapter10/ganglia1.pdf b/nummeth-ws22/fig_chapter10/ganglia1.pdf new file mode 100644 index 0000000..ba89316 Binary files /dev/null and b/nummeth-ws22/fig_chapter10/ganglia1.pdf differ diff --git a/nummeth-ws22/fig_chapter10/ganglia2.pdf b/nummeth-ws22/fig_chapter10/ganglia2.pdf new file mode 100644 index 0000000..efa2569 Binary files /dev/null and b/nummeth-ws22/fig_chapter10/ganglia2.pdf differ diff --git a/nummeth-ws22/fig_chapter10/ganglia3.pdf b/nummeth-ws22/fig_chapter10/ganglia3.pdf new file mode 100644 index 0000000..8a985ac Binary files /dev/null and b/nummeth-ws22/fig_chapter10/ganglia3.pdf differ diff --git a/nummeth-ws22/fig_chapter10/hdf_basic.png b/nummeth-ws22/fig_chapter10/hdf_basic.png new file mode 100644 index 0000000..8c9c01d Binary files /dev/null and b/nummeth-ws22/fig_chapter10/hdf_basic.png differ diff --git a/nummeth-ws22/fig_chapter10/hdf_dataset.png b/nummeth-ws22/fig_chapter10/hdf_dataset.png new file mode 100644 index 0000000..e0832c0 Binary files /dev/null and b/nummeth-ws22/fig_chapter10/hdf_dataset.png differ diff --git a/nummeth-ws22/fig_chapter10/hdf_group.png b/nummeth-ws22/fig_chapter10/hdf_group.png new file mode 100644 index 0000000..a099fdd Binary files /dev/null and b/nummeth-ws22/fig_chapter10/hdf_group.png differ diff --git a/nummeth-ws22/fig_chapter10/hdf_organi.png b/nummeth-ws22/fig_chapter10/hdf_organi.png new file mode 100644 index 0000000..f50a184 Binary files /dev/null and b/nummeth-ws22/fig_chapter10/hdf_organi.png differ diff --git a/nummeth-ws22/fig_chapter10/headnode.png b/nummeth-ws22/fig_chapter10/headnode.png new file mode 100644 index 0000000..783cd03 Binary files /dev/null and b/nummeth-ws22/fig_chapter10/headnode.png differ diff --git a/nummeth-ws22/fig_chapter10/independent.pdf b/nummeth-ws22/fig_chapter10/independent.pdf new file mode 100644 index 0000000..d954fd7 Binary files /dev/null and b/nummeth-ws22/fig_chapter10/independent.pdf differ diff --git a/nummeth-ws22/fig_chapter10/matrices.png b/nummeth-ws22/fig_chapter10/matrices.png new file mode 100644 index 0000000..7267662 Binary files /dev/null and b/nummeth-ws22/fig_chapter10/matrices.png differ diff --git a/nummeth-ws22/fig_chapter10/matrix2.png b/nummeth-ws22/fig_chapter10/matrix2.png new file mode 100644 index 0000000..c75ef88 Binary files /dev/null and b/nummeth-ws22/fig_chapter10/matrix2.png differ diff --git a/nummeth-ws22/fig_chapter10/node.png b/nummeth-ws22/fig_chapter10/node.png new file mode 100644 index 0000000..a2f7bf5 Binary files /dev/null and b/nummeth-ws22/fig_chapter10/node.png differ diff --git a/nummeth-ws22/fig_chapter10/node_cpu.png b/nummeth-ws22/fig_chapter10/node_cpu.png new file mode 100644 index 0000000..83a4717 Binary files /dev/null and b/nummeth-ws22/fig_chapter10/node_cpu.png differ diff --git a/nummeth-ws22/fig_chapter10/node_ohne.png b/nummeth-ws22/fig_chapter10/node_ohne.png new file mode 100644 index 0000000..691c25e Binary files /dev/null and b/nummeth-ws22/fig_chapter10/node_ohne.png differ diff --git a/nummeth-ws22/fig_chapter10/nomp_1.png b/nummeth-ws22/fig_chapter10/nomp_1.png new file mode 100644 index 0000000..04b1bc4 Binary files /dev/null and b/nummeth-ws22/fig_chapter10/nomp_1.png differ diff --git a/nummeth-ws22/fig_chapter10/nomp_2.png b/nummeth-ws22/fig_chapter10/nomp_2.png new file mode 100644 index 0000000..1e0a3a9 Binary files /dev/null and b/nummeth-ws22/fig_chapter10/nomp_2.png differ diff --git a/nummeth-ws22/fig_chapter10/omp1.png b/nummeth-ws22/fig_chapter10/omp1.png new file mode 100644 index 0000000..794ef3b Binary files /dev/null and b/nummeth-ws22/fig_chapter10/omp1.png differ diff --git a/nummeth-ws22/fig_chapter10/omp2.png b/nummeth-ws22/fig_chapter10/omp2.png new file mode 100644 index 0000000..e64122d Binary files /dev/null and b/nummeth-ws22/fig_chapter10/omp2.png differ diff --git a/nummeth-ws22/fig_chapter10/omp3.png b/nummeth-ws22/fig_chapter10/omp3.png new file mode 100644 index 0000000..fc74e22 Binary files /dev/null and b/nummeth-ws22/fig_chapter10/omp3.png differ diff --git a/nummeth-ws22/fig_chapter10/omp4.png b/nummeth-ws22/fig_chapter10/omp4.png new file mode 100644 index 0000000..348ffc3 Binary files /dev/null and b/nummeth-ws22/fig_chapter10/omp4.png differ diff --git a/nummeth-ws22/fig_chapter10/p3dfft.png b/nummeth-ws22/fig_chapter10/p3dfft.png new file mode 100644 index 0000000..fdbd3ff Binary files /dev/null and b/nummeth-ws22/fig_chapter10/p3dfft.png differ diff --git a/nummeth-ws22/fig_chapter10/quad.png b/nummeth-ws22/fig_chapter10/quad.png new file mode 100644 index 0000000..a34420e Binary files /dev/null and b/nummeth-ws22/fig_chapter10/quad.png differ diff --git a/nummeth-ws22/fig_chapter10/scaling.pdf b/nummeth-ws22/fig_chapter10/scaling.pdf new file mode 100644 index 0000000..310752d Binary files /dev/null and b/nummeth-ws22/fig_chapter10/scaling.pdf differ diff --git a/nummeth-ws22/fig_chapter10/serval.png b/nummeth-ws22/fig_chapter10/serval.png new file mode 100644 index 0000000..b027cfc Binary files /dev/null and b/nummeth-ws22/fig_chapter10/serval.png differ diff --git a/nummeth-ws22/fig_chapter10/seti.pdf b/nummeth-ws22/fig_chapter10/seti.pdf new file mode 100644 index 0000000..c62934f Binary files /dev/null and b/nummeth-ws22/fig_chapter10/seti.pdf differ diff --git a/nummeth-ws22/fig_chapter10/shmem.pdf b/nummeth-ws22/fig_chapter10/shmem.pdf new file mode 100644 index 0000000..7a3a549 Binary files /dev/null and b/nummeth-ws22/fig_chapter10/shmem.pdf differ diff --git a/nummeth-ws22/fig_chapter10/strong.pdf b/nummeth-ws22/fig_chapter10/strong.pdf new file mode 100644 index 0000000..da54ef5 Binary files /dev/null and b/nummeth-ws22/fig_chapter10/strong.pdf differ diff --git a/nummeth-ws22/fig_chapter10/top500.png b/nummeth-ws22/fig_chapter10/top500.png new file mode 100644 index 0000000..7fd70a3 Binary files /dev/null and b/nummeth-ws22/fig_chapter10/top500.png differ diff --git a/nummeth-ws22/fig_chapter10/twin.png b/nummeth-ws22/fig_chapter10/twin.png new file mode 100644 index 0000000..3fb0389 Binary files /dev/null and b/nummeth-ws22/fig_chapter10/twin.png differ diff --git a/nummeth-ws22/fig_chapter10/weak.pdf b/nummeth-ws22/fig_chapter10/weak.pdf new file mode 100644 index 0000000..808b230 Binary files /dev/null and b/nummeth-ws22/fig_chapter10/weak.pdf differ diff --git a/nummeth-ws22/skript.tex b/nummeth-ws22/skript.tex index 5bce826..5c97687 100644 --- a/nummeth-ws22/skript.tex +++ b/nummeth-ws22/skript.tex @@ -6539,6 +6539,1990 @@ special treatment of boundary or interior domains. We calculated the velocity field in the steady state. Fig. \ref{fig:lbm3}b shows the streamlines of the flow field ater 1 million time steps for a lattice of $300\times 300$ lattice points with $\omega=1.7$ and the velocity of the lid chosen as $u_\text{lid} = 0.1$. The sliding lid induces a large vortex rotating clock wise. The two lower corners show smalls vortices rotating in the opposite direction. + + +\chapter{Parallel programming} + + + + + + + + + + + + + + + + + + + + + +This chapter is mostly based on a tutorial for the usage of work group cluster. While the very specific details are related to a cluster no longer in existence, the general idea of parallelisation, using different HPC architectures and writing to file systems is essentially similar for other systems. + +\section{HPC Architectures} + +The meaning of High-performance computing (HPC) has changed over the last decades including meaning like large mainframe systems over vector computers to cluster systems. The term HPC is anyway poorly defined (most recently HPC has been mixed with data science\dots). + +The classic usage of HPC systems is the simulation of fluid dynamics. This is a relevant topic in several physics fields, engineering, meteorology. The topology of interconnets is modeled to suit this usage (with some deviations in Jülich with its 5-dimensional torus interconnect). + +The technology of supercomputers has changed pretty much over the years - as we will see later - until recently large homogenous clusters were the trend, but this changes more and more to heterogeneous systems using GPU cards. + + + +\subsection{The old days: ENIAC} + +ENIAC (Electronic Numerical Integrator and Computer) was the first programmable, electronic, general-purpose digital computer, completed in 1945. There were other computers that had these features, but the ENIAC had all of them in one package. It was Turing-complete and able to solve ``a large class of numerical problems'' through reprogramming. + +Although ENIAC was designed and primarily used to calculate artillery firing tables for the United States Army's Ballistic Research Laboratory (which later became a part of the Army Research Laboratory), its first program was a study of the feasibility of the thermonuclear weapon. + +ENIAC was completed in 1945 and first put to work for practical purposes on December 10, 1945 + +\begin{itemize} + \item 40 parallel components (60 cm $\times$ 270 cm $\times$ 70 cm) + \item 170 m$^2$, 27 tons + \item 17,486 electron tubes, 7,200 diodes, 1,500 relais , 70,000 resistors + \item Price (with today's prices) 7 Mio. US Dollar +\end{itemize} +\begin{center} + \pgfimage[width=0.95\textwidth]{fig_chapter10/eniac} +\end{center} + +An addition takes 0.2 ms, a multiplication 2.8 ms, a division 24ms\\ +Programs were ``hard wired'', programs could not be stored + +ENIAC was \emph{HPC} because it was simply large + +\subsection{CRAY computers} +Since 1976 Cray computers have been the synonym for supercomputers + +\begin{itemize} + \item First Cray machines were vector machines (see below) + \item Moved later to multi-processor systems + \item Nowadays they sell clusters +\end{itemize} + +\begin{center} + \pgfimage[width=0.95\textwidth]{fig_chapter10/Cray-1-deutsches-museum} +\end{center} + + + +\subsection{Vector computers} +In the 70s vector computers were the state-of-the-art HPC +\begin{itemize} + \item Parallelization through ``Single instruction - multiple data'' + \item Typical example $$\vec{Y} = a \cdot \vec{X} + \vec{Y}$$ can be solved for vector processors in one step + \item Very fast for any simulation that can be written in the SIMD form + \item Due to complex coding pure vector machines are rarely used + \item Mostly Japanese machines (NEC SX-9 and other) +\end{itemize} +BUT: +\begin{itemize} + \item Modern computer architectures feature vector units + \item SSE features in Intel CPUs + \item GPUs are also highly vectorized +\end{itemize} + +\subsection{Symmetric Multiprocessing} +Symmetric multiprocessing comprises of +\begin{itemize} + \item Multiple CPUs + \item One memory block + \item Common access of all CPUs to the same memory +\end{itemize} +SMP systems are actually scaled up systems of normal servers\\ +Unfortunately the prices does not scale linearly with CPU numbers\\ +Typical systems: Sun Sparc M32, HP Superdome + + +\subsection{NUMA} +An extension to SMP systems are the non-uniform memory access (NUMA) systems + +\begin{itemize} + \item CPUs have a local memory (like in the SMP case) + \item All CPUs in a system share a common memory +\end{itemize} +This approach makes the large common memories of SMP unnecessary.\\ +The complexity of NUMA systems is very high and so is the price\\ +Typical examples include the SGI Altix systems + +\begin{center} + \pgfimage[width=0.95\textwidth]{fig_chapter10/altix} +\end{center} + + +\subsection{Clusters} +Almost every new supercomputer is a cluster of some kind. Its typical elements are +\begin{itemize} + \item Nodes have a set of CPUs and memory on their own + \item Nodes cannot access the memory of other CPUs + \item Communication is done via a high-speed network +\end{itemize} +This approach scales much better in terms of money\\ +Problems have to be compatible with the heterogeneous memory\\ +The interesting component is the high-speed network: Mostly Infiniband, but also special interconnects from, e.g. Cray + +Almost all systems on the Top 500 list are clusters\dots +\begin{center} + \pgfimage[height=0.88\textheight]{fig_chapter10/top500} +\end{center} + + +\subsection{Massively parallel computers} +The last interesting approach used, is the massively parallel computing +\begin{itemize} + \item Independent computers get independent pieces of the workload + \item Communication is only done to present the final results +\end{itemize} +This approach has been used by SETI\@ Home (now: Boinc) and is limited to a very small set of problems.\\ +Alternatively the GRID computing of Cern can be seen as MPP + + +\subsection{GPUs} +The newest trend in HPC: GPGPU!\\ +\emph{General Purpose Graphic Processing Unit} +\begin{itemize} + \item GPGPUs are in some way similar to vector computes + \item Many modern implementations deliver good results only for single-precision + \item GPGPUs boost the nominal speed of clusters + \item Can only be programmed using special languages +\end{itemize} +Typical example: NVidia Kepler, Intel Knight's Corner + + +\subsection{The Tau cluster} + + +\begin{center} + \pgfimage[width=0.9\textwidth]{fig_chapter10/node_ohne} +\end{center} + + +\begin{center} + \pgfimage[width=0.9\textwidth]{fig_chapter10/node_cpu} +\end{center} + + + +\begin{center} + \pgfimage[width=0.9\textwidth]{fig_chapter10/node} +\end{center} + + + +The nodes consist of +\begin{itemize} + \item 2 Intel E5-2650v2 CPUs (total of 16 physical cores)\\ (2.6 GHz, 20MB cache, AVX extension) + \item 64 GB RAM + \item 2 64 GB SSDs + \item Ethernet-, Infiniband- and management port +\end{itemize} +Each system is, therefore an SMP system of its own. + +Systems are grouped in Twin or Quad chassis ($\rightarrow$ 64 cores in 2 height units) + + +\begin{center} + \pgfimage[width=0.9\textwidth]{fig_chapter10/quad} +\end{center} + +\begin{center} + \pgfimage[width=0.9\textwidth]{fig_chapter10/twin} +\end{center} + +The nodes are connected to headnode +\begin{itemize} + \item Single CPU system + \item Bundles the node SSDs to a cluster file system (BeeGFS) + \item Connects via a SAS-link the HP 3Par disk system (which our ITC friends bought) +\end{itemize} + +\begin{center} + \pgfimage[height=0.95\textheight]{fig_chapter10/headnode} +\end{center} + + + +Two further machines +\begin{itemize} + \item Dual CPU Intel E5-2630v2 (12 physical, 24 logical cores) + \item 32 GB RAM + \item Large (and slow) disk array attached to caracal + \item serval serves login purpose +\end{itemize} + + +\begin{center} + \pgfimage[width=0.9\textwidth]{fig_chapter10/serval} +\end{center} + +\begin{center} + \pgfimage[height=0.95\textheight]{fig_chapter10/caracal} +\end{center} + +And then\dots +\begin{itemize} + \item All machines are connected via Ethernet (the cluster nodes are not directly connected to the university network) + \item All cluster nodes are connected via high-speed Infiniband network + \item All machines are attached to a management network (so you don't have to go there to press the power switch) +\end{itemize} + +\begin{center} + \pgfimage[height=0.95\textheight]{fig_chapter10/cluster} +\end{center} + +Why this configuration?\\ +Value for money! +\begin{columns} + + \textbf{16 cores per node}\\ + \begin{itemize} + \item 2 CPUs = 2400\$ + \item Mainboard = 700\$ + \item 64 GB RAM = 700\$ + \end{itemize} + = 250 \$ per core + + \textbf{60 cores per node}\\ + \begin{itemize} + \item 4 CPUs = 23200\$ + \item Mainboard = 8000\$ + \item 256 GB RAM = 2800\$ + \end{itemize} + = 570 \$ per core + +\textbf{Infiniband} is also the most popular way to connect clusters. +%Intel® Xeon® Processor E5-2650 v2 +%(20M Cache, 2.60 GHz) Launched Q3'13 8 95 W BOX : $1171.00 +%-> Board 900$ +% +%Intel® Xeon® Processor E7-8880 v2 +%(37.5M Cache, 2.50 GHz) Launched Q1'14 15 130 W TRAY: $5729.00 +%-> Quadboard rund $6000 +% +% +%Intel® Xeon® Processor E7-4860 v2 +%(30M Cache, 2.60 GHz) Launched Q1'14 12 130 W TRAY: $3838.00 +% + + + + +\section{Basic concepts of parallelization} + +\subsection{Independent jobs} +\begin{center} + \pgfimage[height=0.85\textheight]{fig_chapter10/independent} +\end{center} + +Simplest parallelization: +\begin{itemize} + \item Applicable when problem is separable in non-communicating subproblems + \item No specific needs for the system + \item Only very few problems can be parallelized like this +\end{itemize} + + +\subsection{Shared memory} + +\begin{center} + \pgfimage[width=\textwidth]{fig_chapter10/shmem} +\end{center} +For systems with shared memory (i.e., CPUs share the same memory controller) +\begin{itemize} + \item Whenever problems can be separated in space + \item Requires SMP systems + \item No CPU-CPU communication required + \item Data transfer through common memory + \item Fast and dangerous +\end{itemize} + +\subsection{Global communication} +\begin{center} + \pgfimage[height=0.85\textheight]{fig_chapter10/alltoall} +\end{center} +All-to-All communication +\begin{itemize} + \item may be required for data aggregation + \item is usually extremely expensive +\end{itemize} + +\subsection{Local communication} +\begin{center} + \pgfimage[width=\textwidth]{fig_chapter10/diffmem} +\end{center} + +\begin{center} + \pgfimage[height=0.85\textheight]{fig_chapter10/diffmem2} +\end{center} + +The inter-CPU communication is +\begin{itemize} + \item the workhorse for all problems, which can be spatially decomposed + \item very cost-effective in terms of communication (only point-wise communication) +\end{itemize} + +\subsection{SETI\@ HOME} +SETI\@ HOME was one of the first projects to distribute small work packages\\ +Nowadays it is part of BOINC +\begin{center} + \pgfimage[width=0.5\textwidth]{fig_chapter10/boinc} +\end{center} +The idea is to have a problem, that can be separated into independent problems.\\ +For SETI\@ HOME these were radio observations of some minutes length + +This kind of distributed computing is simple to realize and limited in application +\begin{center} + \pgfimage[width=0.7\textwidth]{fig_chapter10/seti} +\end{center} + + +\subsection{Chess} +\begin{center} + \pgfimage[height=0.85\textheight]{fig_chapter10/chess} +\end{center} + +Chess is an atypical problem +\begin{itemize} + \item Different moves are evaluated + \item Each move offers different new moves + \item This yields a longer tree + \item Basically a new \alert{thread} can be started for each branch +\end{itemize} +Parallelization is of unknown quality - we do not know how many branches there are or if some branch ends earlier (check mate\dots)\\ +Essentially easy to parallelize +\begin{itemize} + \item On shared memory systems all CPUs know the state of the game anyway + \item On separated systems the complete state of the game can easily be transmitted. +\end{itemize} + +\subsection{Algebra} +A major part of supercomputing is devoted to linear algebra\\ +(The actual benchmark LINPACK for clusters is in fact a linear algebra test) + +Most of the linear algebra applications have been solved in various packages - which are mostly available as parallel program + +Possible distribution of matrices on CPUs +\begin{center} +\pgfimage[height=.85\textheight]{fig_chapter10/matrices} +\end{center} + +\begin{center} +\pgfimage[height=.85\textheight]{fig_chapter10/matrix2} +\end{center} + +\begin{itemize} + \item Different matrix geometries for different operations + \item Aim: Minimize communication + \item Mostly block wise schemes are used + \item If you really need to do \textbf{LARGE} matrix operations: Go for ScaLapack +\end{itemize} + +(Short note: The analysis of the CMB is a science case for this) + + + +\subsection{Fourier Transform} +The discrete Fourier transform +\begin{align*} +\hat f (k_x) = \sum_{j=1}^n f(x) \exp(-i k_x x) +\end{align*} +with $x$ discretized as $x_j= j \Delta x$ is a typical numerical problem\\ +The actual implementation is usually the FFTW + +For 1D data parallelization does not help. But how about multi-D data? +\begin{align*} +\hat f (k_x,k_y) = \sum_{i_x,i_y=1}^n f(x) \exp(-i_x k_x x) \exp(-i_y k_y y) +\end{align*} +Here the transform can be done dimension by dimension + +\begin{center} + \pgfimage[height=0.9\textheight]{fig_chapter10/p3dfft} +\end{center} + +\begin{itemize} + \item Data is transformed in one dimension on processor only + \item Through transposition data is arranged to be on one CPU for the next dimension + \item Finally data is transposed in the correct dimension + \item One dimension cannot be cut! +\end{itemize} + +\textbf{Don't try this at home!} Other people have implemented this for you +\begin{itemize} + \item P3DFFT - Fortran based + \item SandiaFFT - C++ based +\end{itemize} + +\subsection{Fluid simulations} +Typical problem: The Burgers' equation +\begin{align*} + \frac{\partial u}{\partial t} + \frac{\partial}{\partial x} u^2 = 0 +\end{align*} +This can be discretized to +\begin{align*} + u_i^{n+1} = u_i^n \Delta t \left( \frac{(u_{i+1}^n)^2 - (u_{i-1}^n)^2}{2\Delta x}\right) +\end{align*} +(This is a not too good numerical scheme, but anyway\dots)\\ +We will assume periodic boundaries + +Implementation on one CPU +\pgfimage[width=\textwidth]{fig_chapter10/burgers1} +We introduce two ghost cells on both sides\\ +\begin{enumerate} + \item Update from left with $u_i^{n+1}=\dots$ + \item Stop at $i-1$ + \item Copy $u_0$ to right ghost cell + \item Copy $u_{i-1}$ to left ghost cell + \item Start over +\end{enumerate} + +\pgfimage[width=\textwidth]{fig_chapter10/burgers2} +For two CPUs, the simulation area is divided into two equal halves.\\ +We introduce two ghost cells \alert{for every CPU}\\ +\begin{enumerate} + \item Update from left with $u_i^{n+1}=\dots$ + \item Stop at right end of CPU + \item Copy rightmost cell to left ghost cell \alert{of the next CPU} + \item Copy leftmost cell to right ghost cell \alert{of the next CPU} + \item Start over +\end{enumerate} + + +This is essentially the most important case! +\begin{itemize} + \item It can easily be extended to more CPUs and more dimensions + \item For higher dimensions the cells to be transmitted are hyperplanes of one dimension less + \item A good choice of the +\end{itemize} + +\section{Scaling of codes} + + +\subsection{What is scaling?} +\begin{description} + \item[Weak scaling] Every code has a fixed work load and for the scaling test the number of cores is increased increasing also the total work load + \item[Strong scaling] The total work load is a fixed quantity, that is distributed to the cores. When the number of cores is increased for the scaling test, the work load per core is decreased. +\end{description} + + \begin{center} + \pgfimage[width=0.8\textwidth]{fig_chapter10/scaling} + \end{center} + +\begin{figure} + \begin{center} + \pgfimage[width=0.8\textwidth]{fig_chapter10/weak} + \end{center} + \caption{Typical examples for weak scaling runs} + \label{fig:weak} +\end{figure} + +\begin{figure} + \begin{center} + \pgfimage[width=0.8\textwidth]{fig_chapter10/strong} + \end{center} + \caption{Typical examples for strong scaling runs} + \label{fig:strong} +\end{figure} + +\begin{itemize} +\item Strong scaling can be used to find the optimal work load per CPU +\item Weak scaling can be used to find the maximum problem size +\end{itemize} + +What is limiting the scaling? +\begin{itemize} + \item Communication overhead (too much surface area per simulation volume) + \item Uneven workload + \item Output! + \item Cache size (code runs faster, when it fits into the CPU's cache) +\end{itemize} + + + + +\section{Basics of OpenMP} + +\subsection{What is OpenMP?} +{\Large \textbf{Open} Specifications for \textbf{M}ulti \textbf{P}rocessing} + +\begin{itemize} + \item Standardized API for parallel programming + \item Supported by many vendors + \item Implemented in C/C++ and Fortran + \item Only available for shared memory systems +\end{itemize} + +What OpenMP does not do +\begin{itemize} + \item No run-time check for deadlocks + \item No run-time check for data dependency +\end{itemize} + + + +\begin{columns} + \column{0.65\textwidth} + OpenMP is based on the \emph{fork/join} model + \begin{itemize} + \item An OpenMP program starts as single thread (master thread) + \item Further threads (team) are generated by parallel regions + \item At the end of parallel regions threads are barrier synchronized + \item Beyond the parallel region code is executed sequentially + \end{itemize} + \column{0.35\textwidth} + \pgfimage[width=\textwidth]{fig_chapter10/omp1} +\end{columns} + + +\subsection{Hello World! - OpenMP} + + +Code +\begin{lstlisting}[language=C] +int main(void) +{ + #pragma omp parallel + printf("Hello World\n"); +} +\end{lstlisting} + +Compile +\begin{lstlisting}[language=bash] +icc -openmp -o hello hello.c +gcc -fopenmp -o hello hello.c + +export OMP_NUM_THREADS=4 +./hello +Hello world +Hello world +Hello world +Hello world +\end{lstlisting} + + + + + + \subsection{Variables} + + Data is stored either shared or private + \begin{itemize} + \item The binding of variables is chosen in the code + \item Variables are by default shared + \item This is not true for loop variables! + \end{itemize} + There is also the special case of reduction variables, which are reduced by an arithmetic reduction at the end of a parallel block + +\pgfimage[width=\textwidth]{fig_chapter10/omp3} + + +\only<3>{ +\pgfimage[width=\textwidth]{fig_chapter10/omp4} + +} +\end{frame} +\begin{frame}[fragile] + \frametitle{General pragmas} + +C-style pragma +\begin{lstlisting}[language=C] +#pragma omp directive [clause[[,] clause] ...] +structured block +\end{lstlisting} +\vspace*{-10mm} +Fortran-style pragme +\begin{lstlisting}[language=Fortran] +!$OMP directive [clause[[,] clause] ...] +structured block +!$OMP END +\end{lstlisting} +\vspace*{-10mm} +You can check for OpenMP support during compile time +\begin{lstlisting}[language=C] +#ifdef _OPENMP +iam = omp_get_thread_num(); +#endif +\end{lstlisting} +\vspace*{-10mm} +\begin{lstlisting}[language=Fortran] +!$ iam = OMP_GET_THREAD_NUM() +\end{lstlisting} +\end{frame} + + +\begin{frame}[fragile] +\frametitle{Useful OpenMP Runtime Commands} + +sets or returns the number of threads in the team +\begin{lstlisting}[language=C] +void omp_set_num_threads(int num_threads); +int omp_get_num_threads(void); +\end{lstlisting} + +returns the maximal number of threads in a team +\begin{lstlisting}[language=C] +int omp_get_max_threads(void); +\end{lstlisting} + +returns the the thread id (from 0 to $n-1$) +\begin{lstlisting}[language=C] +int omp_get_thread_num(void); +\end{lstlisting} + +returns the number of processors on which the program can be run +\begin{lstlisting}[language=C] +int omp_get_num_procs(void); +\end{lstlisting} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Useful OpenMP Runtime Commands} +toggles the dynamic thread team size +\begin{lstlisting}[language=C] +int omp_in_parallel(void); +void omp_set_dynamic(int dynamics_threads); +\end{lstlisting} + +returns the state of the dynamics thread time size +\begin{lstlisting}[language=C] +int omp_get_dynamic(void); +\end{lstlisting} + +toggles the nested parallelization +\begin{lstlisting}[language=C] +void omp_set_nested(int nested); +\end{lstlisting} + +returns the state of the nested parallelization +\begin{lstlisting}[language=C] +int omp_get_nested(void); +\end{lstlisting} + + + +\end{frame} + +\begin{frame}[fragile] +\frametitle{Parallel regions: Syntax} + +Clauses +\begin{itemize} +\item \verb+private (list)+ +\item \verb+shared (list)+ +\item \verb+default (shared | none)+ +\item \verb+firstprivate (list)+ +\item \verb+reduction (operator: list)+ +\item \verb+if (scalar-expression)+ +\item \verb+copyin (list)+ +\item \verb+num_threads (integer-expression)+ +\item \verb+proc_bind (master | close | spread)+ +\end{itemize} +\begin{lstlisting}[language=C] +#pragma omp parallel [clause[[,] clause] ...] +structured block +\end{lstlisting} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Execution model} +\begin{itemize} + \item At the start of every parallel region a team of threads is generated + \item Thread 0 is the master thread +\end{itemize} +\begin{columns} + \column{0.5\textwidth} + \begin{lstlisting}[language=C] + #pragma omp parallel + { + printf("Hello World!\n"); + } + \end{lstlisting} + \column{0.5\textwidth} + \pgfimage[width=\textwidth]{fig_chapter10/nomp_1} +\end{columns} +\end{frame} + + + +\begin{frame}[fragile] +\frametitle{Parallel loops} + +\begin{itemize} + \item Main usage of OpenMP + \item Many programs can be parallelized efficiently through loop parallelization + \item Simple to do: Just add directive to loops + \item Not every loop can be parallelized + \item The \verb+for+ directive is doing the job +\end{itemize} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Parallel loops} +Syntax: Clauses +\begin{itemize} + \item \texttt{private (list)} + \item \texttt{firstprivate (list)} + \item \texttt{lastprivate (list)} + \item \texttt{reduction (operator: list)} + \item \texttt{schedule (kind [, chunksize])} + \item \texttt{collapse (n)} + \item \texttt{ordered} + \item \texttt{nowait} +\end{itemize} + +\end{frame} + +\begin{frame} +\frametitle{Parallel loops} +Loops have to be in canonical form +\begin{itemize} + \item the number of loop runs has to be known before the start of the loop + \item the loop counter may not be altered inside the loop + \item the program has to end the loop + \item no early exit by \texttt{break} + \item no exceptions inside the loop that are catched outside + \item \texttt{exit} is allowed inside the loop +\end{itemize} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Parallel loops - examples} +Exampe: Row sum +\begin{lstlisting}[language=C] +#pragma omp parallel for +for ( i = 0; i < n; i++ ) { +a[i][0] = 0; +for ( j = 0; j < m; j++ ) +a[i][0] = a[i][0] + a[i][j]; +} +\end{lstlisting} + +Example: Smoothing +\begin{lstlisting}[language=C] +for ( i = 1; i < n; i++ ) { +#pragma omp parallel for +for ( j = 1; j < m - 1; j++ ) +a[i][j] = ( a[i-1][j-1] + a[i-1][j] + a[i-1][j+1] ) / 3.0; +} +\end{lstlisting} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Parallel loops - collapse} +\begin{itemize} + \item perfectly nested loops can be collapsed + \item all loop variables have to be independent + \item only the innermost loop may contain arbitrary code + \item useful for the iteration over multidimensional fields +\end{itemize} +\verb+#pragma omp parallel for collapse(n)+\\ +$n$ is the number of collapsed for loops +\end{frame} + +\begin{frame}[fragile] +\frametitle{Parallel loops - collapse} +\begin{lstlisting}[language=C] +#pragma omp parallel for collapse(3) +for(int l=0; l<10; ++l) +for(int j=0; j<3; ++j) +for(int k=0; k<7; ++k){ +/* Only here is arbitrary code */ +foo[l][j][k] = 0; +} +\end{lstlisting} + +\end{frame} + + +\begin{frame}[fragile] +\frametitle{Ordered execution} +Ordered execution with \texttt{ordered} +\begin{itemize} +\item The \texttt{ordered} directive will execute the following block in the original sequential order +\item This allows sequential writing of data into a filee +\item Code in the ordered region is sequentialized +\end{itemize} +\texttt{\#pragma omp ordered} +\begin{itemize} + \item When parts of a loop have to be executed ordered the keyword has to be put in as directive and as clause +\end{itemize}strukturierter Block +\end{frame} + +\begin{frame}[fragile] +\frametitle{Ordered execution} +\begin{lstlisting}[language=C] +/* ordered as clause */ +#pragma omp parallel for ordered +for ( i=0; i; +int main(int argc, char** argv) { + // Initialize the MPI environment + MPI_Init(NULL, NULL); + // Get the number of processes + int world_size; + MPI_Comm_size(MPI_COMM_WORLD, &world_size); + // Get the rank of the process + int world_rank; + MPI_Comm_rank(MPI_COMM_WORLD, &world_rank); + // Get the name of the processor + char processor_name[MPI_MAX_PROCESSOR_NAME]; + int name_len; + MPI_Get_processor_name(processor_name, &name_len); + // Print off a hello world message + printf("Hello world from processor %s, rank %d" + " out of %d processors\n", + processor_name, world_rank, world_size); + // Finalize the MPI environment. + MPI_Finalize(); +} +\end{lstlisting} +\end{frame} + + +\begin{frame}[fragile] + \frametitle{MPI - Basic commands} + +\begin{lstlisting}[language=C] +MPI_Init(int* argc, char*** argv) +\end{lstlisting} +\vspace{-10mm} +During \verb+MPI_Init+, all of MPI's global and internal variables are constructed. For example, a communicator is formed around all of the processes that were spawned, and unique ranks are assigned to each process. Currently, \verb+MPI_Init+ takes two arguments that are not necessary, and the extra parameters are simply left as extra space in case future implementations might need them. + + +\begin{lstlisting}[language=C] +MPI_Get_processor_name(char* name, int* name_length) +\end{lstlisting} +\vspace{-10mm} +\verb+MPI_Get_processor_name+ obtains the actual name of the processor on which the process is executing. + +The final call in this program is: +\begin{lstlisting}[language=C] +MPI_Finalize() +\end{lstlisting} +\vspace{-10mm} +\verb+MPI_Finalize+ is used to clean up the MPI environment. No more MPI calls can be made after this one. + + +\end{frame} + +\begin{frame}[fragile] + \frametitle{MPI - Communicators} +MPI utilizes so called communicators. At the start \verb+MPI_COMM_WORLD+ is constructed, which consists of all processors +\begin{lstlisting}[language=C] +MPI_Comm_size(MPI_Comm communicator,int* size) +\end{lstlisting} +\vspace{-10mm} +\verb+MPI_Comm_size+ returns the size of a communicator. For \verb+MPI_COMM_WORLD+ this returns the total number of processes +\begin{lstlisting}[language=C] +MPI_Comm_rank(MPI_Comm communicator,int* rank) +\end{lstlisting} +\vspace{-10mm} +\verb+MPI_Comm_rank+ returns the rank of a process in a communicator. Each process inside of a communicator is assigned an incremental rank starting from zero. The ranks of the processes are primarily used for identification purposes when sending and receiving messages. + + +\end{frame} + +\begin{frame}[fragile] + \frametitle{MPI - Communicators} +For almost all purposes two communicators are relevant +\begin{itemize} + \item \verb+MPI_COMM_WORLD+ with all processes and no topological information + \item \verb+MPI_CART_COMM+ a communicator with cartesian topology +\end{itemize} +For any multi-dimensional application, the Cartcomm simplifies life. +\end{frame} + +\begin{frame}[fragile] + \frametitle{MPI - CartCommunicators} +\begin{lstlisting}[language=C] +MPI_Dims_create( nnodes, ndims, dims ) +\end{lstlisting} +\vspace{-10mm} +yields a balanced processor number for a cartesian communicator\\ +Input Parameter: +\begin{itemize} + \item \texttt{nnodes} number of processes to be distributed (integer) + \item \texttt{ndims} number of dimensions (integer) +\end{itemize} +Inout Parameter +\begin{itemize} + \item \texttt{dims} array of the size \texttt{ndims} which defines the number of processes in each dimension (array of integer)\\ Values $>0$ are used as given input, 0 will be calculated newly +\end{itemize} +\end{frame} + +\begin{frame}[fragile] + \frametitle{MPI - CartCommunicators} +\begin{lstlisting}[language=C] +int MPI_Cart_create(MPI_Comm comm_old, int ndims, const int dims[], + const int periods[], int reorder, MPI_Comm *comm_cart) +\end{lstlisting} +\vspace{-10mm} +creates a new communicator with topological communicator\\ +Input Parameters +\begin{itemize} +\item \verb+comm_old+ input communicator (handle, typically \verb+MPI_COMM_WORLD+) +\item \verb+ndims+ number of dimensions of cartesian grid (integer) +\item \verb+dims+ integer array of size \verb+ndims+ specifying the number of processes in each dimension (output of \verb+MPI_Dims_create+ can and should be used) +\item \verb+periods+ logical array of size \verb+ndims+ specifying whether the grid is periodic (true) or not (false) in each dimension +\item \verb+reorder+ ranking may be reordered (true) or not (false) (logical) +\end{itemize} +Output Parameters +\begin{itemize} +\item \verb+comm_cart+ communicator with new cartesian topology (handle) +\end{itemize} +\end{frame} + +\begin{frame}[fragile] + \frametitle{MPI - CartCommunicators} +\begin{lstlisting}[language=C] +int MPI_Cart_coords(MPI_Comm comm, int rank, int maxdims, int coords[]) +\end{lstlisting} +\vspace{-10mm} +Determines process coords in cartesian topology given rank in group\\ +Input Parameters +\begin{itemize} +\item \verb+comm+ + communicator with cartesian structure (handle) +\item \verb+rank+ + rank of a process within group of comm (integer, from \verb+MPI_Cart_Rank+) +\item \verb+maxdims+ + length of vector coords in the calling program (integer) +\end{itemize} +Output Parameters +\begin{itemize} +\item \verb+coords+ + integer array (of size \verb+ndims+) containing the Cartesian coordinates of specified process (integer) +\end{itemize} +\end{frame} + + + +\begin{frame}[fragile] + \frametitle{MPI - CartCommunicators} +\begin{lstlisting}[language=C] +int MPI_Cart_shift(MPI_Comm comm, int direction, int disp, int *rank_source, + int *rank_dest) +\end{lstlisting} +\vspace{-10mm} +Returns the shifted source and destination ranks, given a shift direction and amount +Synopsis\\ +Input Parameters +\begin{itemize} +\item \verb+comm+ + communicator with cartesian structure (handle) +\item \verb+direction+ + coordinate dimension of shift (integer) +\item \verb+disp+ + displacement (> 0: upwards shift, < 0: downwards shift) (integer) +\end{itemize} +Output Parameters +\begin{itemize} +\item \verb+rank_source+ + rank of source process (integer) +\item \verb+rank_dest+ + rank of destination process (integer) +\end{itemize} + + +\end{frame} + + + + +\begin{frame}[fragile] + \frametitle{MPI - Send \& Receive} +\begin{lstlisting}[language=C] +MPI_Send(void* data, int count, MPI_Datatype datatype, + int destination, int tag, MPI_Comm communicator) +MPI_Recv(void* data, int count, MPI_Datatype datatype, int source, + int tag, MPI_Comm communicator, MPI_Status* status) +\end{lstlisting} +\vspace{-10mm} +Processes can send data to \verb+destination+ with a given \verb+datatype+ (cf. next slide)\\ +Data has certain tags to identify them.\\ +The receiver has to be actively expecting the data with that tag\\ +Since the rank of process depends on the communicator, this \verb+communicator+ has to be given explicitly. + +\end{frame} + + +\begin{frame}[fragile] + \frametitle{MPI - Send \& Receive} +Datatypes\\ +\begin{tabular}{ll} +\verb+MPI datatype+ & C equivalent\\ +\verb+MPI_SHORT+ & short int\\ +\verb+MPI_INT+ & int\\ +\verb+MPI_LONG+ & long int\\ +\verb+MPI_LONG_LONG+ & long long int\\ +\verb+MPI_UNSIGNED_CHAR+ & unsigned char\\ +\verb+MPI_UNSIGNED_SHORT+& unsigned short int\\ +\verb+MPI_UNSIGNED+ & unsigned int\\ +\verb+MPI_UNSIGNED_LONG+ & unsigned long int\\ +\verb+MPI_UNSIGNED_LONG_LONG+ & unsigned long long int\\ +\verb+MPI_FLOAT+ & float\\ +\verb+MPI_DOUBLE+ & double\\ +\verb+MPI_LONG_DOUBLE+ & long double\\ +\verb+MPI_BYTE+ & char +\end{tabular} +\end{frame} + +\begin{frame}[fragile] + \frametitle{MPI Barriers} +\begin{lstlisting}[language=C] +int MPI_Barrier( MPI_Comm comm ) +\end{lstlisting} +Input Parameters +\begin{itemize} +\item \verb+comm+ communicator (handle) +\end{itemize} +Blocks the caller until all processes in the communicator have called it; that is, the call returns at any process only after all members of the communicator have entered the call. + +\end{frame} + + +\begin{frame}[fragile] + \frametitle{MPI - Send \& Receive} +Minimal example +\begin{lstlisting}[language=C] +// Find out rank, size +int world_rank; +MPI_Comm_rank(MPI_COMM_WORLD, &world_rank); +int world_size; +MPI_Comm_size(MPI_COMM_WORLD, &world_size); + +int number; +if (world_rank == 0) { + number = -1; + MPI_Send(&number, 1, MPI_INT, 1, 0, MPI_COMM_WORLD); +} else if (world_rank == 1) { + MPI_Recv(&number, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, + MPI_STATUS_IGNORE); + printf("Process 1 received number %d from process 0\n", + number); +} +\end{lstlisting} +\end{frame} + + +\begin{frame}[fragile] + \frametitle{MPI - Reduction} +\begin{lstlisting}[language=C] +int MPI_Reduce(const void *sendbuf, void *recvbuf, int count, + MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm) +\end{lstlisting} +\vspace{-10mm} +Reduces values on all processes to a single value +\begin{columns} + \column{0.5\textwidth} +Input Parameters +\begin{itemize} +\item \verb+sendbuf+ + address of send buffer (choice) +\item \verb+count+ + number of elements in send buffer (integer) +\item \verb+datatype+ + data type of elements of send buffer (handle) +\item \verb+op+ + reduce operation (handle) +\item \verb+root+ + rank of root process (integer) +\item \verb+comm+ + communicator (handle) +\end{itemize} +Output Parameters +\begin{itemize} +\item \verb+recvbuf+ + address of receive buffer (choice, significant only at root) +\end{itemize} +\column{0.5\textwidth} +\begin{tabular}{ll} +\verb+MPI_LAND+ & logical \verb+AND+\\ +\verb+MPI_LOR+ & logical \verb+OR+\\ +\verb+MPI_LXOR+ & logical \verb+XOR+\\ +\verb+MPI_BAND+ & binary \verb+AND+\\ +\verb+MPI_BOR+ & binary \verb+OR+\\ +\verb+MPI_BXOR+ & binary \verb+XOR+\\ +\verb+MPI_MIN+ & minimum\\ +\verb+MPI_MAX+ & maximum\\ +\verb+MPI_SUM+ & sum\\ +\verb+MPI_PROD+ & product\\ +\verb+MPI_MINLOC+ & maximum and index \\ +\verb+MPI_MAXLOC+ & minimum and index \\ +\end{tabular} + +\end{columns} +\end{frame} + + +\begin{frame}[fragile] +\frametitle{MPI Example: Burgers} +\begin{lstlisting}[language=C] +#include +#include +#include +#include +#include +#include +#define DIM 1 +//Define constants for directions +#define LEFT 0 +#define RIGHT 1 +#define B 2 +//Namespaces +using namespace blitz; +using namespace std; +//Some constants +const int N=1000; +const int tend=1000; +const int outputstep=50; +const double dx=1.; +const double dt=0.1; +\end{lstlisting} +\end{frame} + +\begin{frame}[fragile] +\frametitle{MPI Example: Burgers} +\begin{lstlisting}[language=C] +int main(int argc, char *argv[]) { + +blitz::Array un, unp; + +//Buffers for data transfer +double in[B], out[B]; + +int localsize, localindex, localmin, localmax; +//MPI variables +int size, rank, dims[DIM]; +int periods[DIM], coords[DIM]; +int neighbours[2]; +MPI_Comm cartcomm; +MPI_Status status; +\end{lstlisting} +\end{frame} + +\begin{frame}[fragile] +\frametitle{MPI Example: Burgers} +\begin{lstlisting}[language=C] +//Initialize MPI +MPI_Init(&argc,&argv); +//Find out how many processes are available +MPI_Comm_size(MPI_COMM_WORLD,&size); +MPI_Comm_rank(MPI_COMM_WORLD,&rank); +cerr <<"CPU " <{ + \begin{center} + \pgfimage[width=0.9\textwidth]{hdf_organi} + \end{center} + } + \only<2>{ + \begin{center} + \pgfimage[width=0.9\textwidth]{hdf_dataset} + \end{center} + } +\end{frame} + +\begin{frame} + \frametitle{Basic Functions} + \only<1>{ + \begin{center} + \pgfimage[width=0.9\textwidth]{hdf_basic} + \end{center} + } +\end{frame} + +\begin{frame}[fragile] + \frametitle{Open a file} +\begin{lstlisting}[language=C] +comm = MPI_COMM_WORLD; +info = MPI_INFO_NULL; +// Initialize MPI +MPI_Init(&argc, &argv); +// Set up file access property list for MPI-IO access +plist_id = H5Pcreate(H5P_FILE_ACCESS); +H5Pset_fapl_mpio(plist_id, comm, info); +file_id = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, plist_id); +// Close the file. +H5Fclose(file_id); +MPI_Finalize(); +\end{lstlisting} +\end{frame} + +\begin{frame}[fragile] + \frametitle{Create a dataset} +\begin{lstlisting}[language=C] + +file_id = H5Fcreate(...); +// Create the dataspace for the dataset. +dimsf[0] = NX; +dimsf[1] = NY; +filespace = H5Screate_simple(RANK, dimsf, NULL); +// Create the dataset with default properties collective. +dset_id = H5Dcreate(file_id, "dataset1", H5T_NATIVE_INT, +filespace, H5P_DEFAULT); +H5Dclose(dset_id); +// Close the file. +H5Fclose(file_id); +\end{lstlisting} +\end{frame} + +\begin{frame} + \frametitle{Create a group} + \only<1>{ + \begin{center} + \pgfimage[width=0.9\textwidth]{hdf_group} + \end{center} + } + +\end{frame} + +\begin{frame}[fragile] + \frametitle{Create a group} +\begin{lstlisting}[language=C] +hid_t file_id, group_id; +... +// Open "file.h5" +file_id = H5Fopen ("file.h5", H5F_ACC_RDWR, +H5P_DEFAULT); +// Create group "/B" in file. +group_id = H5Gcreate (file_id,"B", H5P_DEFAULT, +H5P_DEFAULT, H5P_DEFAULT); +/* Close group and file. */ +status = H5Gclose (group_id); +status = H5Fclose (file_id); +\end{lstlisting} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Compiling HDF5} +Programs using HDF5 have to be linked with the HDF5 library\\ +The library has to be compiled with parallel support + \begin{lstlisting}[language=bash] +fspanier@fsk-serval:~/tmp$ mpicxx -c hdf_example.cpp -I /opt/phdf5/include/ -o hdf_example.o +fspanier@fsk-serval:~/tmp$ mpicxx hdf_example.o -L /opt/phdf5/lib/ -lhdf5 -o hdfexample +fspanier@fsk-serval:~/tmp$ mpirun.openmpi -np 2 ./hdfexample +CPU 0 of 2 +CPU 1 of 2 +\end{lstlisting} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Inside HDF5} + \begin{lstlisting}[language=bash] +fspanier@fsk-serval:~/tmp$ h5ls test.hdf5 +Timestep_0 Group +Timestep_1 Group +globalsize Dataset {1} +fspanier@fsk-serval:~/tmp$ h5dump test.hdf5 +HDF5 "test.hdf5" { +GROUP "/" { + GROUP "Timestep_0" { + DATASET "u" { + DATATYPE H5T_IEEE_F64LE + DATASPACE SIMPLE { ( 10 ) / ( 10 ) } + DATA { + (0): 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 + } + } + } + GROUP "Timestep_1" { + DATASET "u" { + DATATYPE H5T_IEEE_F64LE + DATASPACE SIMPLE { ( 10 ) / ( 10 ) } + DATA { + (0): 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 + } + } + } + DATASET "globalsize" { + DATATYPE H5T_STD_I32LE + DATASPACE SIMPLE { ( 1 ) / ( 1 ) } + DATA { + (0): 10 + } + } +} +} +\end{lstlisting} +\end{frame} + +\chapter{Using the local cluster} + +\begin{frame} + \frametitle{Storage spaces} + \only<1>{ +\begin{description} + \item[Home] +The home directory is living on the helio machines and is mainly meant as small storage with fallback solution. Home is exported through nfs4. +\item[Scratch] +The scratch filesystem is attached to fsk-caracal and exported from there via nfs4. It is split into /scratch/small and /scratch/large. +\item[BeeGFS] +BeeGFS is a new development in the field of cluster file systems. In this case the SSDs in the nodes are connected in one filesystem. This filesystem can be used from cluster nodes and serval/caracal. +\item[3Par] +The 3Par has been purchased by the ITC department and got into our hands somehow. It is in fact optimized for database access, but can also be utilized for very fast writing. The same limitation as for the BeeGFS apply: +\end{description} +} +\only<2>{ +When to use what? +\begin{itemize} + \item Store sources and papers $\Rightarrow$ home + \item Single-core and shared memory simulations $\Rightarrow$ scratch + \item Massively-parallel simulation $\Rightarrow$ BeeGFS/3Par + \item Storing large simulation results $\Rightarrow$ scratch +\end{itemize} +} +\end{frame} + + +\begin{frame} + \frametitle{Network and Services} + \only<1>{ + \begin{description} + \item[PUKnet connection] +Only fsk-serval, fsk-caracal, and the helio machines are connected directly to the PUKnet and can, therefore, be accessed from the office PCs. Since these machines offer all tools to start and stop jobs and also export the relevant filesystems, this is sufficient. As mentioned above, fsk-serval is also open to the outside: It is reachable via ssh. + \item[Internal Ethernet] +All cluster machines are part of an internal Ethernet network. The two main reasons for connecting them like this were the administrative overhead to get all machines registered on PUKnet and the risk minimization. + \item[Service network] +All machines are equipped with service network ports (IPMI, IlO and similar). This allows for performing most service tasks without entering the machine room. + \item[Infiniband] +The compute nodes, the head node and fsk-caracal can talk to each other via the low-latency, high-bandwidth Infiniband connection. This is done automatically for NFS and for MPI jobs. + \end{description} + } + \only<2>{ + \begin{description} + \item[Kerberos] the cluster is secured via Kerberos providing safe authentication and encrypted data transmission + \item[LDAP] user account information is stored in an LDAP database + \item[NFS] cluster file systems are available via NFS4. This requires a Kerberos authenticated connection + \end{description} + + } +\end{frame} + +\begin{frame}[fragile] + \frametitle{Software} + Two compilers are installed: +\begin{itemize} + \item GCC system 4.9 (gcc, gfortran, g++) + \item Intel Composer XE 13 (icc, ifort, icpc) +\end{itemize} +For MPI programs the OpenMPI compilers are installed. They use the GCC compilers as standard. By setting \verb+OMPI_CC+ ,\verb+OMPI_FC+, \verb+OMPI_CXX+ they can be forced to use other compilers. + +The cluster features a queueing system \emph{Torque} (a PBS like system) with a Maui scheduler. + +\end{frame} + + +\begin{frame}[fragile] + \frametitle{Preparatory issues} +You should start by copying your source code to the cluster's home directory with something like +\begin{lstlisting}[language=bash] + scp -r /path/to/source username@fsk-serval.puk.ac.za: +\end{lstlisting} +\vspace{-10mm} +Then log into fsk-serval +\begin{lstlisting}[language=bash] + ssh username@fsk-serval.puk.ac.za +\end{lstlisting} +\vspace{-10mm} +It is recommended to use the gcc/gfortran compilers, if you want to use the Intel compilers instead, you have to source the shell variables +\begin{lstlisting}[language=bash] +source /opt/intel/composerxe/bin/compilervars.sh +\end{lstlisting} +\vspace{-10mm} +(for reasons of simplicity you should put that also into your .bashrc) +\end{frame} +\begin{frame}[fragile] + \frametitle{Preparatory issues} +You will have scratch space allocated already (either under \texttt{/scratch/small} or \texttt{/scratch/large}). Should it be reasonable to use the 3Par or beegfs, you can create a directory under \texttt{/scratch/beegfs} or \texttt{/scratch/3par-beegfs} yourself.\\ + +Since the queueing system has to submit jobs via ssh without asking for a password every time, you need to provide a ssh key. +\begin{lstlisting} + ssh fsk-caracal.puk.ac.za + ssh-keygen + ssh-copy-id node-1 + for i in `seq 1 34`; do ssh node-$i 'echo $HOSTNAME'; done +\end{lstlisting} +\vspace{-10mm} +Don't set any passphrase for the ssh key and answer all questions with 'yes'\footnote{It should not be necessary to log in to every node as we do it here, but the ssh implementation is indeed very picky}. After doing so you have logged into every node of the cluster and the queueing system can submit jobs to the nodes directly. + +\end{frame} +\begin{frame}[fragile] + \frametitle{Preparatory issues} +Next step +\begin{itemize} + \item find the optimal compiler settings + \item find the optimal number of cores to be used +\end{itemize} +Most compilers have more or less optimal automatic settings. for gcc this +\begin{lstlisting}[language=bash] + gcc -march=native -O3 +\end{lstlisting} +\vspace{-10mm} +and for the Intel compiler +\begin{lstlisting}[language=bash] + icc -xHost -O3 +\end{lstlisting} +\vspace{-10mm} +For the brave among you one may also use +\begin{lstlisting}[language=bash] + gcc -Ofast + icc -fast +\end{lstlisting} +\vspace{-10mm} +These compiler settings work also for the compilers from the same set (gcc: g++, gfortran; icc: icpc, ifort). Should for some reason your code not work with these settings, you should check your code for not so obvious coding problems. + + + +\end{frame} + + +\begin{frame}[fragile] +\frametitle{Job files in general} + +Jobs on the cluster are controlled by job files. These are in general shell script with extensions to control queueing system parameters. For complete examples see below. The following PBS parameters are important +\begin{itemize} + \item \verb+#PBS -N+ assigns a name to the job (for later identification) + \item \verb+#PBS -q+ selects a queue to run on + \item \verb+#PBS -l+ defines the needed resources ('ppn' processes per node, 'nodes' number of nodes, 'walltime' total run time) + \item \verb+#PBS -u+ assigns a username + \item \verb+#PBS -m+ defines when to write emails ('b' at the beginning and 'e' at the end as well as combinations thereof) + \item \verb+#PBS -M+ defines the email address to write to + \item \verb+#PBS -d+ defines the directory, where the executable resides + \item \verb+#PBS -w+ defines the working directory +\end{itemize} +\end{frame} + +\begin{frame} +\frametitle{Single CPU jobs} +\only<1>{ +\begin{itemize} + \item the cluster is designed for large scale jobs, i.e., there is a large number of price-efficient CPUs with a very good interconnect. + \item The single-core performance of most modern (Core i5/i7 Haswell etc.) desktop CPUs is better! + \item Using the cluster for single CPU jobs makes only sense, when a large number of jobs is thrown into the queue. + \item Another good reason to run single CPU jobs is the direct connection to the storage servers. This mainly affects \emph{HESS analysis runs}. The typical job file for a single CPU job looks like this +\end{itemize} +%Before attempting to run single CPU jobs, keep in mind that the cluster is designed for large scale jobs, i.e., there is a large number of price-efficient CPUs with a very good interconnect. The single-core performance of most modern (Core i5/i7 Haswell etc.) desktop CPUs is better! Using the cluster for single CPU jobs makes only sense, when a large number of jobs is thrown into the queue. \\ +%Another good reason to run single CPU jobs is the direct connection to the storage servers. This mainly affects \emph{HESS analysis runs}. The typical job file for a single CPU job looks like this +Typical approach: +\begin{itemize} + \item Write a shell script producing job files for different parameters + \item Submit the resulting job files +\end{itemize} +} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Single CPU jobs} +\begin{lstlisting}[language=bash] +#!/bin/bash +for i in 1 2 4 8 16; do +for j in 10000 100000 1000000 10000000 100000000; do +let 'k=16*i' +jobname="strong_$k" +jobname+="_" +jobname="$jobname$j" +filename="$jobname.job" +echo "#!/bin/bash" > $filename +echo "#PBS -N $jobname -q infiniband" >> $filename +echo "#PBS -l nodes=$i:ppn=16 -l walltime=10:30,mem=200Mb" >> $filename +echo "#PBS -w /scratch/large/fspanier -d /scratch/large/fspanier" >> $filename +echo "#PBS -u fspanier" >> $filename +echo "#PBS -m be" >> $filename +echo "#PBS -M felix@fspanier.de" >> $filename +echo "echo 'Strong scaling, $j grid cells on $k CPUs'" >> $filename +echo "time mpirun -np $k -hostfile " '$PBS_NODEFILE' " -mca btl self,sm,openib,tcp --bind-to-socket --bysocket ./burgers_mpi_bench $j" >> $filename +echo "echo 'Run complete!'" >> $filename +done +done +\end{lstlisting} +\end{frame} + +\begin{frame}[fragile] +\frametitle{OpenMP jobs} + +OpenMP jobs are typically run on one node (really!), so 'nodes' has to be 1. 'ppn' can be any value from 1 to 16. Select the 'shmem' queue. The program can be run immediately, but '\verb+OMP_NUM_TASKS+' has to be set, otherwise all cores of the node will be used. +\begin{lstlisting}[language=bash] +#!/bin/bash +#PBS -N jobname -q shmem +#PBS -l nodes=1:ppn=16 -l walltime=30:00:00 +#PBS -u user +#PBS -m be +#PBS -M email@nwu.ac.za +#PBS -d /scratch/large/user/dir -w /scratch/large/user/dir +tasks=`cat $PBS_NODEFILE | wc -l` +hostname=`hostname` +echo "Running on $hostname with $tasks tasks." +export OMP_NUM_TASKS=$tasks +./program +\end{lstlisting} +\vspace{-10mm} +The wall time is set to 30 hours in this case. It is advisable to set a time which is more realistically to avoid zombie jobs blocking the cluster more than necessary (so set something like one hour more than your expected runtime). +\end{frame} + +\begin{frame}[fragile] +\frametitle{Infiniband jobs} + +Infiniband jobs are in some aspects different: +\begin{itemize} + \item Of course the number of 'nodes' can be higher + \item 'ppn' should always be 16. + \item The 'infiniband' queue should be used + \item The program has to be run with mpirun. PBS defines a shell variable for the host file, that has to be passed to mpirun. If shell variable are to be exported this is done with the \verb+-x+ option of mpirun. +\end{itemize} + +\begin{lstlisting}[language=bash] +#!/bin/bash +#PBS -N jobname -q infiniband +#PBS -l nodes=32:ppn=16 -l walltime=30:00:00 +#PBS -u username +#PBS -m be +#PBS -M email@nwu.ac.za +#PBS -d /scratch/large/user/dir -w /scratch/large/user/dir +tasks=`cat $PBS_NODEFILE | wc -l` +hostname=`hostname` +echo "Running on $hostname with $tasks tasks." +export var1=value1 +export var2=value2 +mpirun -x var1 -x var2 -hostfile $PBS_NODEFILE -np $tasks + -mca btl self,sm,openib,tcp --bind-to-socket --bysocket ./program +\end{lstlisting} + + +\end{frame} + +\begin{frame}[fragile] + \frametitle{Running a job} +\begin{itemize} + \item \texttt{qsub} submits the job + \item \texttt{qstat} shows the jobs run by the user + \item \texttt{qdel} remove a job from the queue +\end{itemize} + \begin{lstlisting}[language=bash] +fspanier@fsk-serval:/scratch/large/fspanier/burgers$ qsub strong_64_1000000.job +1478.fsk-caracal.puk.ac.za +fspanier@fsk-serval:/scratch/large/fspanier/burgers$ qstat +Job id Name User Time Use S Queue +------------------ ---------------- ---------- -------- - ----- +1478.fsk-caracal ...ng_64_1000000 fspanier 0 Q infiniband +fspanier@fsk-serval:/scratch/large/fspanier/burgers$ qdel 1478 + + \end{lstlisting} +\end{frame} + +\subsection{More cluster info} +\begin{itemize} + \item \texttt{showq} on fsk-caracal prints a more detailed list of jobs +\end{itemize} + \begin{lstlisting}[language=bash] +fspanier@fsk-caracal:~$ showq +ACTIVE JOBS-------------------- +JOBNAME USERNAME STATE PROC REMAINING STARTTIME + +1477 aivascenko Running 512 18:45:41 Wed Apr 8 16:55:21 + + 1 Active Job 512 of 560 Processors Active (91.43%) + 32 of 36 Nodes Active (88.89%) + +IDLE JOBS---------------------- +JOBNAME USERNAME STATE PROC WCLIMIT QUEUETIME +0 Idle Jobs + +BLOCKED JOBS---------------- +JOBNAME USERNAME STATE PROC WCLIMIT QUEUETIME + +Total Jobs: 1 Active Jobs: 1 Idle Jobs: 0 Blocked Jobs: 0 + \end{lstlisting} + + +\subsection{http://fsk-caracal/ganglia} + + \begin{center} + \pgfimage[width=0.9\textwidth]{fig_chapter10/ganglia1} + \end{center} + + \begin{center} + \pgfimage[width=0.9\textwidth]{fig_chapter10/ganglia2} + \end{center} + + \begin{center} + \pgfimage[width=0.9\textwidth]{fig_chapter10/ganglia3} + \end{center} + + + + + + + + + + + + + + \bibliographystyle{natdin} \bibliography{./literatur.bib}