Skip to content
Snippets Groups Projects
Select Git revision
  • cb131082e8712209e69b15e5e05c6ad3da0c7a3f
  • master default protected
  • 67-multithreading-is-plattform-dependent
  • cmake_windows
  • v0.8.4
  • v0.8.3
  • v0.8.2
  • v0.8
  • v0.7
  • v0.6
  • v0.5-alpha
  • v0.4
12 results

SimpleVisualisationWindow.cpp

Blame
  • pi_serial.f90 1.13 KiB
    program pi
    
    implicit none
    
    integer, parameter :: DARTS = 50000, ROUNDS = 10, MASTER = 0
    
    real(8) :: pi_est
    real(8) :: homepi, avepi, pirecv, pisum
    integer :: rank
    integer :: i, n
    integer, allocatable :: seed(:)
    
    ! we set it to zero in the sequential run
    rank = 0
    
    ! initialize the random number generator
    ! we make sure the seed is different for each task
    call random_seed()
    call random_seed(size = n)
    allocate(seed(n))
    seed = 12 + rank*11
    call random_seed(put=seed(1:n))
    deallocate(seed)
    
    avepi = 0
    do i = 0, ROUNDS-1
       pi_est = dboard(DARTS)
    
       ! calculate the average value of pi over all iterations
       avepi = ((avepi*i) + pi_est)/(i + 1)
    
       print *, "After ", DARTS*(i+1), " throws, average value of pi =", avepi
    end do
    
    contains
    
       real(8) function dboard(darts)
    
          integer, intent(in) :: darts
    
          real(8) :: x_coord, y_coord
          integer :: score, n
    
          score = 0
          do n = 1, darts
             call random_number(x_coord)
             call random_number(y_coord)
    
             if ((x_coord**2 + y_coord**2) <= 1.0d0) then
                score = score + 1
             end if
          end do
          dboard = 4.0d0*score/darts
    
       end function
    
    end program