Skip to content

Commit

Permalink
MPI
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinThoma committed Mar 16, 2014
1 parent c2db412 commit deea483
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 5 deletions.
47 changes: 42 additions & 5 deletions documents/Programmierparadigmen/MPI.tex
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ \section{Erste Schritte}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Funktionen}
\inputminted[numbersep=5pt, tabsize=4]{c}{scripts/mpi/comm-size.c}
\inputminted[numbersep=5pt, tabsize=4]{c}{scripts/mpi/comm-size.c}\xindex{MPI\_Comm\_size}
Liefert die Größe des angegebenen Kommunikators; dh. die Anzahl der Prozesse in der Gruppe.

\textbf{Parameter}
Expand All @@ -27,7 +27,7 @@ \section{Funktionen}
\textbf{Beispiel}
\inputminted[numbersep=5pt, tabsize=4]{c}{scripts/mpi/comm-size-example.c}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\rule{\textwidth}{0.4pt}
\rule{\textwidth}{0.4pt}\xindex{MPI\_Comm\_rank}
\inputminted[numbersep=5pt, tabsize=4]{c}{scripts/mpi/comm-rank.c}
Bestimmt den Rang des rufenden Prozesses innerhalb des Kommunikators.

Expand All @@ -42,7 +42,44 @@ \section{Funktionen}
\textbf{Beispiel}
\inputminted[numbersep=5pt, tabsize=4]{c}{scripts/mpi/comm-rank-example.c}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\rule{\textwidth}{0.4pt}
\rule{\textwidth}{0.4pt}\xindex{MPI\_Send}
\inputminted[numbersep=5pt, tabsize=4]{c}{scripts/mpi/mpi-send.c}
Senden einer Nachricht an einen anderen Prozeß innerhalb eines Kommunikators. (Standard-Send)

\textbf{Parameter}
\begin{itemize}
\item \textbf{buf}: Anfangsadresse des Sendepuffers
\item \textbf{count}: Anzahl der Elemente des Sendepuffers (nichtnegativ)
\item \textbf{datatype}: Typ der Elemente des Sendepuffers (handle)
\item \textbf{dest}: Rang des Empfängerprozesses in comm (integer)
\item \textbf{tag}: message tag zur Unterscheidung verschiedener Nachrichten;
Ein Kommunikationsvorgang wird durch ein Tripel (Sender, Empfänger, tag) eindeutig beschrieben.
\item \textbf{comm}: Kommunikator (handle)
\end{itemize}

\textbf{Beispiel}
\inputminted[numbersep=5pt, tabsize=4]{c}{scripts/mpi/mpi-send-example.c}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\rule{\textwidth}{0.4pt}\xindex{MPI\_Recv}
\inputminted[numbersep=5pt, tabsize=4]{c}{scripts/mpi/mpi-receive.c}
Empfangen einer Nachricht (blockierend)

\textbf{Parameter}
\begin{itemize}
\item \textbf{buf}: Anfangsadresse des Empfangspuffers
\item \textbf{status}: Status, welcher source und tag angibt (\texttt{MPI\_Status})
\item \textbf{count}: Anzahl der Elemente im Empfangspuffer (nichtnegativ)
\item \textbf{datatype}: Typ der zu empfangenden Elemente (handle)
\item \textbf{source}: Rang des Senderprozesses in comm oder \texttt{MPI\_ANY\_SOURCE}
\item \textbf{tag}: message tag zur Unterscheidung verschiedener Nachrichten
Ein Kommunikationsvorgang wird durch ein Tripel (Sender, Empfänger, tag) eindeutig beschrieben. Um Nachrichten mit beliebigen tags zu empfangen, benutzt man die Konstante \texttt{MPI\_ANY\_TAG}.
\item \textbf{comm}: Kommunikator (handle)
\end{itemize}

\textbf{Beispiel}
\inputminted[numbersep=5pt, tabsize=4]{c}{scripts/mpi/mpi-receive-example.c}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\rule{\textwidth}{0.4pt}\xindex{MPI\_Reduce}
\inputminted[numbersep=5pt, tabsize=4]{c}{scripts/mpi/mpi-reduce.c}
Führt eine globale Operation \textbf{op} aus; der Prozeß \enquote{root} erhält das Resultat.

Expand All @@ -56,7 +93,7 @@ \section{Funktionen}
\item \textbf{comm}: Kommunikator (handle)
\end{itemize}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\rule{\textwidth}{0.4pt}
\rule{\textwidth}{0.4pt}\xindex{MPI\_Bcast}
\inputminted[numbersep=5pt, tabsize=4]{c}{scripts/mpi/mpi-bcast.c}
Sendet eine Nachricht vom Prozess \texttt{root} an alle anderen Prozesse des
angegebenen Kommunikators.
Expand All @@ -70,7 +107,7 @@ \section{Funktionen}
\item \textbf{comm}: Kommunikator (handle)
\end{itemize}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\rule{\textwidth}{0.4pt}
\rule{\textwidth}{0.4pt}\xindex{MPI\_Scatter}
\inputminted[numbersep=5pt, tabsize=4]{c}{scripts/mpi/mpi-scatter.c}
Verteilt Daten vom Prozess \texttt{root} unter alle anderen Prozesse in der Gruppe, so daß, soweit möglich, alle Prozesse gleich große Anteile erhalten.

Expand Down
Binary file modified documents/Programmierparadigmen/Programmierparadigmen.pdf
Binary file not shown.
20 changes: 20 additions & 0 deletions documents/Programmierparadigmen/scripts/mpi/for-example.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <stdio.h>
#include <mpi.h>
int main (int argc, char** args) {
int size, i;
int myrank;
MPI_Init(&argc, &args);
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &myrank);

for (i=0; i<size; i++) {
MPI_Barrier(MPI_COMM_WORLD);
if (i == myrank) {
printf("Hello World, I have rank %d out of %d.\n",
myrank, size);
}
}

MPI_Finalize();
return 0;
}
18 changes: 18 additions & 0 deletions documents/Programmierparadigmen/scripts/mpi/mpi-receive-example.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "mpi.h"

int msglen, again=1;
void *buf;
MPI_Datatype datatype
MPI_Comm comm;
MPI_Status status;

...
while (again) {
MPI_Probe(ROOT, MPI_ANY_TAG, comm, &status);
MPI_Get_count(&status, datatype, &msglen);
buf=malloc(msglen*sizeof(int));
MPI_Recv(buf, msglen, datatype, status.MPI_SOURCE,
status.MPI_TAG, comm, &status);
...
}
...
3 changes: 3 additions & 0 deletions documents/Programmierparadigmen/scripts/mpi/mpi-receive.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
int MPI_Recv(void *buf, int count,
MPI_Datatype datatype, int source, int tag,
MPI_Comm comm, MPI_Status *status)
18 changes: 18 additions & 0 deletions documents/Programmierparadigmen/scripts/mpi/mpi-send-example.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "mpi.h"
...
int signal, i, numprogs, me;
MPI_Status stat;
MPI_Comm_rank(MPI_COMM_WORLD, &me);
MPI_Comm_size(MPI_COMM_WORLD,
&numprocs);
if (me==ROOT) {
...
for (i=1; i<numprocs; i++) {
MPI_Send(&signal, 1, MPI_INT, i, 0, MPI_COMM_WORLD);
}
...
else {
MPI_Recv(&sig, 1, MPI_INT, ROOT, MPI_ANY_TAG,
MPI_COMM_WORLD, &stat);
...
}
3 changes: 3 additions & 0 deletions documents/Programmierparadigmen/scripts/mpi/mpi-send.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
int MPI_Send(void *buf, int count,
MPI_Datatype datatype, int dest,
int tag, MPI_Comm comm)

0 comments on commit deea483

Please sign in to comment.