! A program to the Navier_Stokes equations flate plate with ports at quarter markers of the plate
!
Program IDS
use Variables
use mpi
implicit none
open(32, file = 'error.dat')

!Setting up the partition for each processor and initializing MPI
Call MPI_Subroutine

Call Freestream


!Call Create_InputData_File
!kk=kk+1
 DO kk=1, 2001
......
!A lot of calculation in here
......
! communicating the maximum error among the processes and delta t
call MPI_REDUCE(eps,epsGlobal,1,MPI_DOUBLE_PRECISION,MPI_MAX,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(epsGlobal,1,MPI_DOUBLE_PRECISION,0,MPI_COMM_WORLD,ierr)
call MPI_REDUCE(delta_t,delta_tGlobal,1,MPI_DOUBLE_PRECISION,MPI_MIN,0,MPI_COMM_WORLD,ierr)

if(MyRank.eq.0) delta_t = delta_tGlobal

call MPI_BCAST(delta_t,1,MPI_DOUBLE_PRECISION,0,MPI_COMM_WORLD,ierr)


if(MyRank.eq.0) then
  write(*,*) kk,epsGlobal,(kk*delta_t)
  write(32,*) kk,epsGlobal
endif

Call Swap
call mpi_startall(4,req,ierr)
call mpi_waitall(4,req,status,ierr)

if (epsGlobal.le.10.0**(-8.0)) then
	exit
	endif
 enddo

Call Output


End Program IDS
