Do vs do concurrent

This is Mandelbrot - hello world.

Rows are supposed to be calculated in parallel - do concurrent vs do. However - takes exactly the same time 6.9 seconds to do a 5000x5000 mandelbrot (gfortran, Macbook Air M1, 8 cores).

I was expecting the concurrent version to either be faster or slower.
Is the work load too light?

  subroutine mandelbrot(ll, ur, pixels, width, height)
      integer, intent(out) :: pixels(:,:)  ! image
      integer, intent(in)  :: width        ! pixels
      integer, intent(in)  :: height       ! pixels
      complex, intent(in)  :: ll           ! lower left
      complex, intent(in)  :: ur           ! upper right 

      real :: fwidth, fheight
      integer:: x, y
      complex :: c

      fwidth = real(ur)-real(ll)
      fheight = imag(ur)-imag(ll)
      do concurrent (y = 1:height)
      !do y = 1, height
          do x = 1, width
              c = CMPLX(real(ll) + x*fwidth/width, imag(ur) - y*fheight/height)
              pixels(x,y) = 255 - escape_time(c)
          end do
      end do
  end subroutine mandelbrot

  pure function escape_time(c) 
    complex, intent (in) :: c 
    integer :: escape_time
    complex :: z
    z=c
    do escape_time=0,255
        if (real(z)**2+imag(z)**2>4.0) then
            exit
        end if
        z = z*z + c
    end do
  end function  escape_time

Do concurrent by itself won’t do anything more than a simple do… To start exploring what you can do with do concurrent you have to activate OpenMP or with intel compilers -qparallel.

Oh well, you could get one thing though, do concurrent implies that only pure functions can be called within. So it is a good warning for “future proof” development.

You will find a lot of information in these discussions:

2 Likes