Hello all,
So I want to parallelize a histogram filling and I searched around and found this video and I went ahead and tried his example, thinking "seems simple enough". So here's mine (basically the same):
!initialize matrix, hist do i=1,Nbins call omp_init_lock(hist_locks(i)) enddo !$omp parallel do do i=1,N bin=nint(matrix(i)/dr) call omp_set_lock(hist_locks(bin)) hist(bin)=hist(bin)+1 call omp_unset_lock(hist_locks(bin)) enddo !$omp end parallel do print*, 'end'
(sorry, I can't make it to fomat into a code segment)
But when I run it (ctrl+F5), it always comes up with the same error "forrt1: severe (157): Program Exception - access violation" in the line where the omp_unset_lock is. What's going on? I really don't get this error. I mean, if it was in the line where I set the lock it would MAYBE kind of make sense ("2 threads tried to modify the same memory address at the same time", although it would defeat the whole purpose of the locks but whatever). But 2 threads trying to unlock the same lock? How? (I hope I'm interpreting the error correct, but whatever the case. How do I fix it?). I know there are other methods to parallelize a histogram filling but I need to know what's happening with this and doesn't work. Also, I know that in the video he uses an example with c++ and the calls are all made by reference (if I'm not mistaken), (using &). But how do you do that in Fortran? I tried using LOC but it doesn't help. I still get the same errors. Should I use pointers somehow?
Another question: If I insert a " print*, 'a'" command anywhere inside the do loop then the program will run (ctrl+F5) and terminate "normally" without any errors BUT without printing 'end', meaning it did have problems and terminated prematurely and indeed if I run it with the debugger (F5) it comes up with the same errors as before (without the print). Please, any explanations cause I'm starting to go crazy.