mirror of
https://github.com/MartinThoma/LaTeX-examples.git
synced 2025-04-26 06:48:04 +02:00
added docker project
This commit is contained in:
parent
04d3181251
commit
74dfdb42b2
4 changed files with 45 additions and 0 deletions
35
documents/Programmierparadigmen/scripts/mpi/mpi-sum-reduce.c
Normal file
35
documents/Programmierparadigmen/scripts/mpi/mpi-sum-reduce.c
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue