Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
ИНСАЙД ИНФА MPI.pdf
Скачиваний:
15
Добавлен:
15.04.2015
Размер:
3.3 Mб
Скачать

5.9. GLOBAL REDUCTION OPERATIONS

175

/* explain to MPI how type Complex is defined */

MPI_Type_contiguous( 2, MPI_DOUBLE, &ctype );

MPI_Type_commit( &ctype );

/* create the complex-product user-op */

MPI_Op_create( myProd, 1, &myOp );

MPI_Reduce( a, answer, 100, ctype, myOp, root, comm );

/* At this point, the answer, which consists of 100 Complexes, * resides on process root

*/

5.9.6 All-Reduce

MPI includes a variant of the reduce operations where the result is returned to all processes in a group. MPI requires that all processes from the same group participating in these operations receive identical results.

MPI_ALLREDUCE( sendbuf, recvbuf, count, datatype, op, comm)

IN

sendbuf

starting address of send bu er (choice)

OUT

recvbuf

starting address of receive bu er (choice)

IN

count

number of elements in send bu er (non-negative inte-

 

 

ger)

IN

datatype

data type of elements of send bu er (handle)

IN

op

operation (handle)

IN

comm

communicator (handle)

int MPI_Allreduce(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)

MPI_ALLREDUCE(SENDBUF, RECVBUF, COUNT, DATATYPE, OP, COMM, IERROR) <type> SENDBUF(*), RECVBUF(*)

INTEGER COUNT, DATATYPE, OP, COMM, IERROR

fvoid MPI::Comm::Allreduce(const void* sendbuf, void* recvbuf, int count, const MPI::Datatype& datatype, const MPI::Op& op) const = 0

(binding deprecated, see Section 15.2) g

If comm is an intracommunicator, MPI_ALLREDUCE behaves the same as MPI_REDUCE except that the result appears in the receive bu er of all the group members.

Advice to implementors. The all-reduce operations can be implemented as a reduce, followed by a broadcast. However, a direct implementation can lead to better performance. (End of advice to implementors.)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

176

CHAPTER 5. COLLECTIVE COMMUNICATION

1The \in place" option for intracommunicators is speci ed by passing the value

2MPI_IN_PLACE to the argument sendbuf at all processes. In this case, the input data is

3taken at each process from the receive bu er, where it will be replaced by the output data.

4If comm is an intercommunicator, then the result of the reduction of the data provided

5by processes in group A is stored at each process in group B, and vice versa. Both groups

6should provide count and datatype arguments that specify the same type signature.

7

8

The following example uses an intracommunicator.

9Example 5.21 A routine that computes the product of a vector and an array that are

10distributed across a group of processes and returns the answer at all nodes (see also Example

115.16).

12

 

 

 

 

13

SUBROUTINE

PAR_BLAS2(m, n, a, b, c, comm)

14

REAL a(m),

b(m,n)

!

local slice of array

15

REAL c(n)

 

!

result

16

REAL sum(n)

 

 

 

17

INTEGER n,

comm, i, j,

ierr

18

 

 

 

 

19! local sum

20DO j= 1, n

21sum(j) = 0.0

22DO i = 1, m

23sum(j) = sum(j) + a(i)*b(i,j)

24END DO

25END DO

26

27! global sum

28CALL MPI_ALLREDUCE(sum, c, n, MPI_REAL, MPI_SUM, comm, ierr)

29

30! return result at all nodes

31RETURN

32

33

34 5.9.7 Process-local reduction

35

The functions in this section are of importance to library implementors who may want to

36

implement special reduction patterns that are otherwise not easily covered by the standard

37

MPI operations.

38

The following function applies a reduction operator to local arguments.

39

40

41

42

43

44

45

46

47

48