Hello,is this code safe?
subroutine pca(nth) use omp_lib integer :: p, n, i integer, parameter :: maxnth=100 integer, volatile :: prog(0:maxnth-1) prog=-1 !$omp parallel private(p) shared(prog) num_threads(nth) p = omp_get_thread_num() if(p.ne.nth-1) then do while(prog(p) .ge. prog(p+1)) end do end if write(*,*)p prog(p) = prog(p)+1 !$omp end parallel return end subroutine pcaAssume this is part of a bigger code (i.e., there is much more code in the parallel region) and that the "do while" loop is used to synchronize all threads (no, I don't want to use a barrier :-) ). Is it possible that prog(p+1) is kept inside a register and its update is not seen by thread p ? Because of the "volatile" I would say no and in fact the code appears to be working. can anybody confirm?The question may seem stupid but if prog is instead declared of size nth instead of maxnth, the code does not work anymore. Can anybody explain me the difference between these two cases? I guess that the difference is in the fact that nth is an argument of the routine but still this does not help me understand.Thanks in advance,Alfredo