diff --git a/documents/Programmierparadigmen/Compilerbau.tex b/documents/Programmierparadigmen/Compilerbau.tex index 6aa3dbe..2946226 100644 --- a/documents/Programmierparadigmen/Compilerbau.tex +++ b/documents/Programmierparadigmen/Compilerbau.tex @@ -184,6 +184,79 @@ Maschinencode oder Assembler zu erstellen. Dabei muss folgendes beachtet werden: \item \textbf{Nachoptimierung}\todo{?} \end{itemize} +\section{Weiteres} +\subsection{First- und Follow} +\begin{definition}[$k$-Präfix]\xindex{Präfix}\xindex{\# (Compilerbau)}% + Sei $G = (\Sigma, V, P, S)$ eine Grammatik, $k \in \mdn_{> 0}$ und + $x \in (V \cup \Sigma)^*$ mit + \[x = x_1 \dots x_m \text{ mit } x_i \in (V \cup \Sigma) \text{ wobei } i \in 1, \dots, m\] + + Dann heißt $\tilde{x} \in (V \cup \Sigma \cup \Set{\#})^+$ ein $k$-\textbf{Präfix} von $x$, + wenn gilt: + \[\tilde{x} = + \begin{cases} + x\# &\text{falls } x = x_1 \dots x_m \text{ und } m < k\\ + x_1 \dots x_k &\text{sonst} + \end{cases}\] + wobei $\#$ das Ende der Eingabe bezeichnet. In diesem Fall schreibt man + \[ \tilde{x} = k\ :\ x\] +\end{definition} + +\begin{beispiel}[$k$-Präfixe] + Sei $G = (\Set{A, B, C, S}, \Set{a, b, c}, P, S)$ mit + \begin{align*} + P = \{ &A \rightarrow aa | ab, \\ + &B \rightarrow AC,\\ + &C \rightarrow c,\\ + &S \rightarrow ABC\} + \end{align*} + + Dann gilt: + \begin{bspenum} + \item $A = 1 : S$ + \item $a = 1 : S$ + \end{bspenum} + + \todo[inline]{Das ist ein Problem! Damit wäre $k : x$ nicht wohldefiniert!} +\end{beispiel} + +\begin{definition}[First- und Follow-Menge]\xindex{Firstkx@$\text{First}_k(x)$}\xindex{Followkx@$\text{Follow}_k(x)$}% + Sei $G = (\Sigma, V, P, S)$ eine Grammatik und $x \in V$. + + \begin{defenum} + \item $\begin{aligned}[t]\First_k (x) := \{u \in (V \cup \Sigma)^+ | &\exists y \in \Sigma^*:\\ + &x \Rightarrow^* y\\ + \land &u = k : y \}\end{aligned}$ + \item $\begin{aligned}[t]\Follow_k(x) := \{u \in (V \cup \Sigma)^+ | &\exists m, y \in (V \cup \Sigma)^* :\\ + &S \Rightarrow^* mxy\\ + \land &u \in \First_k(y)\}\end{aligned}$ + \end{defenum} +\end{definition} + +\begin{beispiel}[First- und Follow-Mengen\footnotemark] + Sei $G = (\Sigma, V, P, E)$ mit + \begin{align*} + \Sigma &= \Set{+, *, (, )}\\ + V &= \Set{T, T', E, E', F}\\ + P &= \{ E \rightarrow T E'\\ + &\hphantom{= \{ } E' \rightarrow \varepsilon | +TE'\\ + &\hphantom{= \{ } T \rightarrow FT'\\ + &\hphantom{= \{ } T' \rightarrow \varepsilon | *FT'\\ + &\hphantom{= \{ } F \rightarrow \id | (E)\} + \end{align*} + + Dann gilt: + \begin{bspenum} + \item $\First(E) = \First(T) = \First(F) = \Set{\id, (\ )}$ + \item $\First(E') = \Set{\#, +}$ + \item $\First(T') = \Set{\#, *}$ + \item $\Follow(E) = \Follow(E') = \Set{\#, )}$ + \item $\Follow(T) = \Follow(T') = \Set{\#, ), +}$ + \item $\Follow(F) = \Set{\#, ), +, *}$ + \end{bspenum} +\end{beispiel} +\footnotetext{Folie 348} + \section{Literatur} Ich kann das folgende Buch empfehlen: diff --git a/documents/Programmierparadigmen/MPI.tex b/documents/Programmierparadigmen/MPI.tex index 59f56b1..6b6f7c8 100644 --- a/documents/Programmierparadigmen/MPI.tex +++ b/documents/Programmierparadigmen/MPI.tex @@ -172,9 +172,12 @@ Verteilt Daten vom Prozess \texttt{root} unter alle anderen Prozesse in der Grup \inputminted[numbersep=5pt, tabsize=4]{c}{scripts/mpi/mpi-reduce-example.c} \section{Beispiele} - +\subsection{sum-reduce Implementierung} \inputminted[numbersep=5pt, tabsize=4]{c}{scripts/mpi/mpi-sum-reduce.c} +\subsection[broadcast Implementierung]{broadcast Implementierung\footnote{Klausur WS 2012 / 2013}} +\inputminted[numbersep=5pt, tabsize=4]{c}{scripts/mpi/mpi-mybroadcast.c} + \section{Weitere Informationen} \begin{itemize} \item \url{http://mpitutorial.com/} diff --git a/documents/Programmierparadigmen/Programmierparadigmen.pdf b/documents/Programmierparadigmen/Programmierparadigmen.pdf index 1a5d4cf..f1e2129 100644 Binary files a/documents/Programmierparadigmen/Programmierparadigmen.pdf and b/documents/Programmierparadigmen/Programmierparadigmen.pdf differ diff --git a/documents/Programmierparadigmen/scripts/mpi/mpi-mybroadcast.c b/documents/Programmierparadigmen/scripts/mpi/mpi-mybroadcast.c new file mode 100644 index 0000000..c6221ef --- /dev/null +++ b/documents/Programmierparadigmen/scripts/mpi/mpi-mybroadcast.c @@ -0,0 +1,18 @@ +void my_bcast(void* data, int count, MPI_Datatype type, + int root, MPI_Comm comm) { + int my_rank; + MPI_Comm_rank(comm, &my_rank); + int comm_size; + MPI_Comm_size(comm, &comm_size); + if (my_rank == root) { + // If we are the root process, send our data to every one + for (int i = 0; i < comm_size; i++) { + if (i != my_rank) { + MPI_Send(data, count, type, i, 0, comm); + } + } + } else { + // If we are a receiver process, receive the data from root + MPI_Recv(data, count, type, root, 0, comm, MPI_STATUS_IGNORE); + } +} diff --git a/documents/Programmierparadigmen/shortcuts.sty b/documents/Programmierparadigmen/shortcuts.sty index 94f1e5b..304d2bf 100644 --- a/documents/Programmierparadigmen/shortcuts.sty +++ b/documents/Programmierparadigmen/shortcuts.sty @@ -83,6 +83,8 @@ \DeclareMathOperator{\VAR}{VAR} \DeclareMathOperator{\CONST}{CONST} \DeclareMathOperator{\APP}{APP} +\DeclareMathOperator{\First}{First} +\DeclareMathOperator{\Follow}{Follow} \let\succ\relax% Set equal to \relax so that LaTeX thinks it's not defined \DeclareMathOperator{\succ}{succ} \newcommand{\iu}{{i\mkern1mu}} % imaginary unit