, OpenMP . - , . - , , . , -
Program stuff
Implicit None
Real, Dimension( 1:100 ) :: a
Call Random_number( a )
!$omp parallel default( none ) shared( a )
Call sub( a )
!$omp end parallel
Contains
Subroutine sub( a )
Real, Dimension( : ), Intent( InOut ) :: a
Integer :: i
!$omp do
Do i = 1, Size( a )
a( i ) = 2.0 * a( i )
End Do
End Subroutine Sub
End Program stuff
( , ) , ! $omp, -
Call sub( a )
- . ! $Omp do , , , . .
https://computing.llnl.gov/tutorials/openMP/#Scoping
.
? , , a , , - , ! OpenMP ,
- , .. , , , .
- ( , ), SAVE ( ), .
, ! - OpenMP, , , , workhare ! , , -
Program dot_test
Implicit None
Real, Dimension( 1:100 ) :: a, b
Real :: r
a = 1.0
b = 2.0
Call dot( a, b, r )
Write( *, * ) r
Contains
Subroutine dot( a, b, r )
Real, Dimension( : ), Intent( In ) :: a, b
Real, Intent( Out ) :: r
Real, Save :: s
Integer :: i
s = 0.0
Do i = 1, Size( a )
s = s + a( i ) * b( i )
End Do
r = s
End Subroutine dot
End Program dot_test
Wot now? gfortran -std=f95 -fopenmp -O -Wall -Wextra dot.f90
Wot now? export OMP_NUM_THREADS=3
Wot now? ./a.out
200.000000
200.000000
200.000000
, ... , threadprivate.
https://computing.llnl.gov/tutorials/openMP/#THREADPRIVATE
.