The Computer Language
Benchmarks Game

mandelbrot Fortran Intel #4 program

source code

! The Computer Language Benchmarks Game
! http://benchmarksgame.alioth.debian.org/
!
! Contributed by Jason Blevins
! Adapted from Fortran versions by George R. Gonzalez and Simon Geard
!
! ifort -fast -openmp -o mandelbrot mandelbrot.f90
program mandelbrot
  implicit none

  integer, parameter :: dp = selected_real_kind(15, 307)
  integer, parameter :: int8 = selected_int_kind(2)
  integer, parameter :: iter = 50
  real(dp), parameter :: limit2 = 4.0_dp
  character(len=8) :: argv
  integer :: w, h, x, y, i, pos, bit_num
  integer(int8) :: byte
  real(dp) :: inv_w, inv_h, Zi, Zr, Ti, Tr, Cr, Ci
  logical :: inside
  integer(int8), dimension(:,:), allocatable :: buf

  ! read dimension from command line
  call get_command_argument(1, argv)
  read(argv, *) w
  h = w

  ! allocate output buffer
  allocate(buf(ceiling(w/8.0_dp),h))

  ! precalculate constants
  inv_w = 2.0_dp / w
  inv_h = 2.0_dp / h

  ! pbm header
  write(*,'("P4",/,i0," ",i0)') w, h

  !$OMP PARALLEL DO PRIVATE(y, x, bit_num, pos, byte, Zr, Cr, Ci, inside, i)
  do y = 0, h - 1
     bit_num = 8 ! when moving left to right, bits are numbered 7 to 0
     byte = 0_int8
     pos = 0
     do x = 0, w - 1
        bit_num = bit_num - 1

        Zr = 0.0_dp; Zi = 0.0_dp; Tr = 0.0_dp; Ti = 0.0_dp;
        Cr = inv_w * x - 1.5_dp
        Ci = inv_h * y - 1.0_dp
        inside = .true.
        do i = 1, iter
           Zi = 2.0 * Zr * Zi + Ci
           Zr = Tr - Ti + Cr
           Ti = Zi * Zi
           Tr = Zr * Zr
           if (Tr + Ti > limit2) then
              inside = .false.
              exit
           end if
        end do

        ! We're in the set, set this bit to 0
        if (inside) byte = ibset(byte, bit_num)

        if (bit_num == 0 .or. x == w - 1) then
           ! All bits set or end of row, so store full byte
           pos = pos + 1
           buf(pos,y+1) = byte
           byte = 0_int8
           bit_num = 8
        end if
     end do
  end do
  !$OMP END PARALLEL DO

  ! print output
  do y = 1, h
     write(*, '(10000000a1)', advance='no') buf(:,y)
  end do
  deallocate(buf)
end program mandelbrot
    

notes, command-line, and program output

NOTES:
64-bit Ubuntu quad core
Intel(R) Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 17.0.1.132 Build 20161005
Copyright (C) 1985-2016 Intel Corporation.  All rights reserved.
FOR NON-COMMERCIAL USE ONLY


Thu, 12 Jan 2017 20:05:00 GMT

MAKE:
/usr/local/src/intel/bin/ifort -O3 -fast -openmp mandelbrot.ifc-4.f90 -o mandelbrot.ifc-4.ifc_run
ifort: command line remark #10411: option '-openmp' is deprecated and will be removed in a future release. Please use the replacement option '-qopenmp'
rm mandelbrot.ifc-4.f90
0.40s to complete and log all make actions

COMMAND LINE:
./mandelbrot.ifc-4.ifc_run 16000

(BINARY) PROGRAM OUTPUT NOT SHOWN