Parallel Smoothing Algorithm Implementation Using OpenMP
60 likes | 189 Vues
This document provides an implementation of a parallel smoothing algorithm using OpenMP, designed for efficient computation on shared memory systems. The algorithm computes the average of neighboring values in a grid, iterating through specified indices while employing barrier synchronization to ensure thread safety. It leverages features such as dynamic scheduling and thread synchronization. This is particularly beneficial for computational tasks involving large matrices and can be adapted for various applications in scientific computing.
Parallel Smoothing Algorithm Implementation Using OpenMP
E N D
Presentation Transcript
DO J=2,N-1 DO I=2,N-1 А(I,J) = A(I-1,J) + A(I,J-1) + A(I+1,J) + A(I,J+1) / 4 ENDDO ENDDO
Нить 0 Нить 1 Нить N
Нить 0 Нить 1 Нить 2
!$OMP PARALLEL DEFAULT(SHARED) PRIVATE(I,J,IAM,NUMT,ILIMIT) !$ IAM = OMP_GET_THREAD_NUM () !$ NUMT = OMP_GET_NUM_THREADS () !$ ISYNC (IAM) = 0 !$ ILIMIT=MIN(NUMT-1, N-1-2) !$OMP BARRIER DO J=2,N-1 !$ IF (IAM .GT. 0 .AND. IAM .LE. ILIMIT) THEN !$ DO WHILE (ISYNC(IAM-1) .EQ. 0) !$OMP FLUSH(ISYNC) !$ ENDDO !$ ISYNC(IAM-1)=0 !$OMP FLUSH(ISYNC) !$ ENDIF !$OMP DO DO I=2,N-1 А(I,J) = (A(I-1,J) + A(I,J-1) + A(I+1,J) + A(I,J+1)) / 4 ENDDO !$OMP ENDDO NOWAIT !$ IF (IAM .LT. ILIMIT) THEN !$ DO WHILE (ISYNC(IAM) .EQ. 1) !$OMP FLUSH(ISYNC) !$ ENDDO !$ ISYNC(IAM)=1 !$OMP FLUSH(ISYNC) !$ ENDIF ENDDO !$OMP END PARALLEL
!$OMP PARALLEL PRIVATE(J,I,IAM,NEWJ) !$ IAM = OMP_GET_THREAD_NUM() DO NEWJ = 2, N-1 + OMP_GET_NUM_THREADS () - 1 J = NEWJ-IAM !$OMP DO SCHEDULE (STATIC) DO I = 2, N-1 !$ IF (J .LT. 2 .OR. J .GT. N-1) THEN !$ CYCLE !$ ENDIF A( I, J ) = (A( I-1, J ) + A( I+1, J ) + A( I, J-1 ) +A( I, J+1 ))/4 ENDDO ENDDO !$OMP END PARALLEL
Материалы по курсу: ftp://ftp.keldysh.ru/K_student/OpenMp