Exemplo mpi , caulo do pi

Exemplo mpi , caulo do pi


DisciplinaProgramacao Cientifica30 materiais442 seguidores
Pré-visualização1 página
program pi
implicit none 
real*8 var,aux
real*8 :: monte 
integer*8 numpoints
var=acos(-1.0)
print*,var
numpoints=1000000
aux=monte(numpoints)
end program pi
real*8 function monte(numpoints)
real*8 ::x,randnum,xmin
integer*8 ::n,numpoints
Real*8 ::I2d,I2dsquare,EstimError,xmax
I2d=0
I2dsquare=0
xmin=-1.0
xmax=1.0
do n=1,numpoints
call random_number(randnum)
x=(xmax-xmin)*randnum+xmin
!print*,x
I2d =I2d+1/(sqrt(1-x**2))
I2dsquare= I2dsquare +(1/(sqrt(1-x**2)))**2
!print*,I2d
enddo
I2d=I2d*2/numpoints
I2dsquare=2*I2dsquare/numpoints
EstimError=2*sqrt((I2dsquare-I2d**2)/numpoints)
print*,'Num de points',numpoints,'valor da int',I2d ,'+/-',EstimError
monte=I2d
end function monte