• 04/11/2022
  • Public Content

Sequential Program

Open the sample file:
(the sample file is located in the
folder for command-line builds). The named constants for integer and real kinds are declared using
. Select an integer kind that can hold large integers. The
is declared as the number of trials. It is set to 6,000,000 in this example. The variable total counts the number of points that are found within the circle.
The Fortran standard intrinsic
is used to generate the points for testing. The standard does not say if the random sequence is different for each run of the program, so it is called as
with no arguments. Intel® Fortran uses the time-of-day clock to initialize the random number generator.
The main body of the program is this loop:
! Run the trials. Get a random X and Y and see if the position ! is within a circle of radius 1. If it is, add one to the subtotal do bigi=1_K_BIGINT,num_trials call RANDOM_NUMBER(x) call RANDOM_NUMBER(y) if ((x*x)+(y*y) <= 1.0_K_SINGLE) total = total + 1_K_BIGINT end do
At the end of the trials, divide the total by the number of trials and then multiply by four:
! total/num_trials is an approximation of pi/4 print *, "Computed value of pi is",& REAL(4_K_BIGINT*total,K_DOUBLE)/REAL(num_trials,K_DOUBLE)
intrinsic is used to convert the integers to double precision before dividing.
The program includes code to show the elapsed time for the application.

Product and Performance Information


Performance varies by use, configuration and other factors. Learn more at www.Intel.com/PerformanceIndex.