óÌÅÄÕÀÝÉÅ ÐÒÅÄÏÐÒÅÄÅÌÅÎÎÙÅ ÏÐÅÒÁÃÉÉ ÍÏÇÕÔ ÉÓÐÏÌØÚÏ×ÁÔØÓÑ MPI_REDUCE É ÒÏÄÓÔ×ÅÎÎÙÍÉ ÆÕÎËÃÉÑÍÉ MPI_ALLREDUCE, MPI_REDUCE_SCATTER É MPI_SCAN. áÒÇÕÍÅÎÔ op ÍÏÖÅÔ ÐÒÉÎÉÍÁÔØ ÓÌÅÄÕÀÝÉÅ ÚÎÁÞÅÎÉÑ:
éÍÑ | úÎÁÞÅÎÉÅ |
MPI_MAX | ÍÁËÓÉÍÕÍ |
MPI_MIN | ÍÉÎÉÍÕÍ |
MPI_SUM | ÓÕÍÍÁ |
MPI_PROD | ÐÒÏÉÚ×ÅÄÅÎÉÅ |
MPI_LAND | ÌÏÇÉÞÅÓËÏÅ é |
MPI_BAND | ÐÏÒÁÚÒÑÄÎÏÅ é |
MPI_LOR | ÌÏÇÉÞÅÓËÏÅ éìé |
MPI_BOR | ÐÏÒÁÚÒÑÄÎÏÅ éìé |
MPI_LXOR | ÌÏÇÉÞÅÓËÏÅ ÉÓËÌÀÞÁÀÝÅÅ éìé |
MPI_BXOR | ÐÏÒÁÚÒÑÄÎÏÅ ÉÓËÌÀÞÁÀÝÅÅ éìé |
MPI_MAXLOC | ÍÁËÓÉÍÁÌØÎÏÅ ÚÎÁÞÅÎÉÅ É ÍÅÓÔÏÎÁÈÏÖÄÅÎÉÑ |
MPI_MINLOC | ÍÉÎÉÍÁÌØÎÏÅ ÚÎÁÞÅÎÉÅ É ÍÅÓÔÏÎÁÈÏÖÄÅÎÉÑ |
ïÐÅÒÁÃÉÉ MPI_MINLOC É MPI_MAXLOC ÏÂÓÕÖÄÁÀÔÓÑ ÄÁÌÅÅ × ÒÁÚÄÅÌÅ 4.9.3. äÌÑ ÏÓÔÁÌØÎÙÈ ÐÒÅÄÏÐÒÅÄÅÌÅÎÎÙÈ ÏÐÅÒÁÃÉÊ ÎÉÖÅ ÐÒÉ×ÏÄÑÔÓÑ ÒÁÚÒÅÛÅÎÎÙÅ ËÏÍÂÉÎÁÃÉÉ ÁÒÇÕÍÅÎÔÏ× op É datatype. îÏ ÐÒÅÖÄÅ ÏÐÒÅÄÅÌÉÍ ÇÒÕÐÐÕ ÏÓÎÏ×ÎÙÈ ÔÉÐÏ× ÄÁÎÎÙÈ MPI ÓÌÅÄÕÀÝÉÍ ÏÂÒÁÚÏÍ:
óÉ integer: | MPI_INT, MPI_LONG, MPI_SHORT, MPI_UNSIGNED_SHORT, MPI_UNSIGNED, MPI_UNSIGNED_LONG |
æïòôòáî integer: | MPI_INTEGER |
Floating point: | MPI_FLOAT, MPI_DOUBLE, MPI_REAL, MPI_DOUBLE_PRECISION, MPI_LONG_DOUBLE |
Logical: | MPI_LOGICAL |
Complex: | MPI_COMPLEX |
Byte: | MPI_BYTE |
ðÒÁ×ÉÌØÎÙÅ ÔÉÐÙ ÄÁÎÎÙÈ ÄÌÑ ËÁÖÄÏÊ ÏÐÅÒÁÃÉÉ ÏÐÒÅÄÅÌÅÎÙ ÎÉÖÅ.
Op | òÁÚÒÅÛÅÎÎÙÅ ÔÉÐÙ |
MPI_MAX, MPI_MIN | óÉ integer, æïòôòáî integer, Floating point |
MPI_SUM, MPI_PROD | óÉ integer, æïòôòáî integer, Floating point, Complex |
MPI_LAND, MPI_LOR, MPI_LXOR | óÉ integer, Logical |
MPI_BAND, MPI_BOR, MPI_BXOR | óÉ integer, æïòôòáî integer, Byte |
ðÒÉÍÅÒ 4.15 ðÒÏÃÅÄÕÒÁ ×ÙÞÉÓÌÑÅÔ ÓËÁÌÑÒÎÏÅ ÐÒÏÉÚ×ÅÄÅÎÉÅ Ä×ÕÈ ×ÅËÔÏÒÏ×, ÒÁÓÐÒÅÄÅÌÅÎÎÙÈ × ÇÒÕÐÐÅ ÐÒÏÃÅÓÓÏ×, É ×ÏÚ×ÒÁÝÁÅÔ ÒÅÚÕÌØÔÁÔ × ÎÕÌÅ×ÏÊ ÕÚÅÌ.
SUBROUTINE PAR_BLAS1(m, a, b, c, comm)
REAL a(m), b(m) ! ÌÏËÁÌØÎÁÑ ÞÁÓÔØ ÍÁÓÓÉ×Á
REAL c ! ÒÅÚÕÌØÔÁÔ (ÎÁ ÕÚÌÅ ÎÏÌØ)
REAL sum
INTEGER m, comm, i, ierr
! ÌÏËÁÌØÎÁÑ ÓÕÍÍÁ
sum = 0.0
DO i = 1, m
sum = sum + a(i)*b(i)
END DO }
!ÇÌÏÂÁÌØÎÁÑ ÓÕÍÍÁ
CALL MPI_REDUCE(sum, c, 1, MPI_REAL, MPI_SUM, 0, comm, ierr)
RETURN
ðÒÉÍÅÒ 4.16 ðÒÏÃÅÄÕÒÁ ×ÙÞÉÓÌÑÅÔ ÐÒÏÉÚ×ÅÄÅÎÉÅ ×ÅËÔÏÒÁ ÎÁ ÍÁÓÓÉ×, ËÏÔÏÒÙÅ ÒÁÓÐÒÅÄÅÌÅÎÙ × ÇÒÕÐÐÅ ÐÒÏÃÅÓÓÏ×, É ×ÏÚ×ÒÁÝÁÅÔ ÒÅÚÕÌØÔÁÔ × ÎÕÌÅ×ÏÊ ÕÚÅÌ.
SUBROUTINE PAR_BLAS2(m, n, a, b, c, comm)
REAL a(m), b(m,n) ! ÌÏËÁÌØÎÁÑ ÞÁÓÔØ ÍÁÓÓÉ×Á
REAL c(n) ! ÒÅÚÕÌØÔÁÔ
REAL sum(n)
INTEGER n, comm, i, j, ierr
!ÌÏËÁÌØÎÁÑ ÓÕÍÍÁ
DO j= 1, n
sum(j) = 0.0
DO i = 1, m
sum(j) = sum(j) + a(i)*b(i,j)
END DO
END DO
! ÇÌÏÂÁÌØÎÁÑ ÓÕÍÍÁ
CALL MPI_REDUCE(sum, c, n, MPI_REAL, MPI_SUM, 0, comm, ierr)
RETURN