Dear Friends,
I have a very simple Fortran code that counts the even numbers in an array. I have defined a shared variable and I am changing it at each subprocces. I have tested shared, dynamic, reduction and also atomic keyword. But the program is not working properly.
Do you have any idea?
Here is my code
use omp_lib ! paralell processing
implicit real*4 (a-h,o-z)
implicit integer*4(i-n)
parameter(is=1000)
dimension r(is)
dimension i1(is),i2(is)
call RANDOM_NUMBER(r)
i1=int(100*r)
nnz=0
!$omp parallel do default(private) schedule(dynamic) &
!$omp shared (i1,i2,i3,nnz) ! reduction(+: nnz)
do i=1,is
if(mod(i1(i),2).eq.0) then
!omp atomic update
nnz=nnz+1
i2(nnz)=i1(i)
!omp end atomic
endif
end do
!$omp end parallel do
write(*,*) nnz
stop
end