next up previous
Next: 5 Local data exchange Up: Course on Parallelization Previous: 3 Synchronized Communication

4 Global Operations

Let some Double Precision vector $ \underline{{u}}$ be stored blockwise disjoint, i.e., distributed over all processes s ( s = 0,..., P - 1) such that $ \underline{{u}}$ = ($ \underline{{u}}_{0}^{T}$,...,$ \underline{{u}}_{S}^{T}$)T.

\fbox{{\large E9}}
Write a routine

DebugD(nin,xin,icomm)

that prints nin Double Precision numbers of the array xin. Start the program with several processes.
$ \Longrightarrow$ All processes will write their local vectors, i.e., one has to look carefully for the data of process s.

Improve the routine DebugD such that process 0 reads the number (from terminal) of that process which is to write it's vector. Use

MPI_Bcast

to broadcast this information and let the processes react appropriately. If necessary use MPI_Barrier to synchronize the output.
\fbox{{\large E10}}
Exchange global minimum and maximum of the vector  $ \underline{{u}}$ ! Use

MPI_Gather, MPI_Scatter/ MPI_Bcast and ExchangeD.

How can you reduce the amount communication ?

Hint: Compute, first, local min./max. and afterwards let some process determine the global quantities.

Alternatively, you can use MPI_Allreduce and the operations MPI_Minloc/MPI_Maxloc.

\fbox{{\large E11}}
Write a routine for computing the global scalar product

Skalar(n,x,y,icomm)

of two Double Precision vectors x and y of local length n. Use

MPI_Allreduce with the operation MPI_SUM.


next up previous
Next: 5 Local data exchange Up: Course on Parallelization Previous: 3 Synchronized Communication
Gundolf Haase 2003-05-19