diff --git a/documents/Programmierparadigmen/MPI.tex b/documents/Programmierparadigmen/MPI.tex index d59f50d..6218247 100644 --- a/documents/Programmierparadigmen/MPI.tex +++ b/documents/Programmierparadigmen/MPI.tex @@ -19,6 +19,9 @@ Das wird \texttt{mpicc hello-world.c} kompiliert.\\ Mit \texttt{mpirun -np 14 scripts/mpi/a.out} werden 14 Kopien des Programms gestartet. +Hierbei ist \texttt{MPI\_COMM\_WORLD}\xindex{MPI\_COMM\_WORLD} der Standard-Kommunikator, +der von \texttt{MPI\_Init} erstellt wird. + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{MPI Datatypes}\xindex{MPI datatypes} @@ -169,6 +172,9 @@ 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} + +\inputminted[numbersep=5pt, tabsize=4]{c}{scripts/mpi/mpi-sum-reduce.c} + \section{Weitere Informationen} \begin{itemize} \item \url{http://mpitutorial.com/} diff --git a/documents/Programmierparadigmen/Programmierparadigmen.pdf b/documents/Programmierparadigmen/Programmierparadigmen.pdf index eab63ea..8900551 100644 Binary files a/documents/Programmierparadigmen/Programmierparadigmen.pdf and b/documents/Programmierparadigmen/Programmierparadigmen.pdf differ diff --git a/documents/Programmierparadigmen/Readme.md b/documents/Programmierparadigmen/Readme.md index 72b843e..7c3a510 100644 --- a/documents/Programmierparadigmen/Readme.md +++ b/documents/Programmierparadigmen/Readme.md @@ -1,3 +1,7 @@ Dies ist ein **inoffizielles, von Studenten erstelltes Skript** zur Vorlesung "Programmierparadigmen" am KIT bei Herrn Prof. Dr. Snelting (WS 2013/2014). + +Docker +------ +You might also be interested in the [programming paradigms docker project](https://github.com/kitedu/programming-paradigms). \ No newline at end of file diff --git a/documents/Programmierparadigmen/scripts/mpi/mpi-sum-reduce.c b/documents/Programmierparadigmen/scripts/mpi/mpi-sum-reduce.c new file mode 100644 index 0000000..49550df --- /dev/null +++ b/documents/Programmierparadigmen/scripts/mpi/mpi-sum-reduce.c @@ -0,0 +1,35 @@ +// Quelle: Klausur vom SS 2013 am KIT bei +// Prof. Dr.-Ing. Gregor Snelting +void my_int_sum_reduce(int *sendbuf, + int *recvbuf, int count, + int root, MPI_Comm comm) +{ + int size, rank; + MPI_Comm_size(comm, &size); + MPI_Comm_rank(comm, &rank); + if (rank == root) { + /* Initialize recvbuf with our own values. */ + for (int i = 0; i < count; ++i) { + recvbuf[i] = sendbuf[i]; + } + + /* Receive values from every other node + and accumulate. */ + for (int i = 0; i < size; ++i) { + if (i == root) + continue; + + int other[count]; + MPI_Recv(other, count, MPI_INT, + i, 0, comm, MPI_STATUS_IGNORE); + + for (int j = 0; j < count; ++j) { + recvbuf[j] += other[j]; + } + } + } else { + /* Send our values to root. */ + MPI_Send(sendbuf, count, MPI_INT, + root, 0, comm); + } +} \ No newline at end of file