I am fairly new to openMP and at the moment I'm trying to parallelize a code which does some computations on the image. It's a big image, so it's being read from the file strip by strip. Then each strip is divided into squares which then are being modified by the code. After that is done, squares are copied back to strips, which are then being saved to a new file.
I parallelized the code in a way that each thread processes one square at a time. Strip is divided to 47 squares, so if I use 2 threads 24 squares are processed by one thread and another 23 by second thread. The problem only squares processed by 'master' thread are correct, the rest is not read/copied/wrote correctly; please see the attachment.
Here is the important part of the code:
- Code: Select all
c get and b/g subtract strip between iy1 and iy2; pad with zeroes to width m if needed
if (istat.ne.0.) then
write(0,*) 'igetsecpad failed. code = ',istat
c write(0,*) 'Read lines ',iy1,iy2,' of ',ny
!$OMP DO SCHEDULE(DYNAMIC)
if (ixsub.eq.1) then
if (ix2.gt.nx+nmask) then
c write(0,*) 'Getting image section ',ix1,ix2,iy1,iy2
c convolve with shmap here
c taper the array to reduce aliasing
c convolution done, result in out
c write(0,*) 'Writing subsection ',ixsub,iysub,ix1,iy1
c pick out the part of out that is unaffected by aliasing (strip off border)
c write(0,*) 'Write to section starting at ',ix1,iy1
!$OMP END CRITICAL
c call putsec(61,zz,mx-2*nmask,my-2*nmask,ix1+nmask,iy1+nmask,naxlen)
!$OMP END DO
!$OMP END PARALLEL
c write(0,*) 'Write out lines ',iy1+nmask,iy1-nmask+my-1,' of ',nx,ny
write(0,*) 'Finished strip ',iysub,' / ',nysub,
: ' = pix ',iy1_array(iysub)+nmask,' - ',iy1_array(iysub)+my-nmask-1
nxsub and nysub determines number of rows and columns (47x47 here). frombuf and tobuf pull out data from the strip and put back, respectively. If there is more explanation needed, please let me know. How can I fix my problem?
I'm using gfortran on Fedora 18.