program main
use omp_lib
use basicmod
use mpimod
use boundarymod
use config, only: benchmarkmode
implicit none
real(8)::time_begin,time_end
logical::is_final
logical,parameter:: forceoutput=.true., usualoutput=.false.
data is_final /.false./
call InitializeMPI
if(myid_w == 0) print *, "setup grids and fields"
if(myid_w == 0) print *, "grid size for x y z",ngrid1*ntiles(1),ngrid2*ntiles(2),ngrid3*ntiles(3)
if(myid_w == 0 .and. benchmarkmode ) print *, "Only initial and final snaps are dampped. Intermediate steps are not damped for benchmark."
call GenerateGrid
call GenerateProblem
call ConsvVariable
call Output(forceoutput)
if(myid_w == 0) print *, "entering main loop"
! main loop
if(myid_w == 0 .and. .not. benchmarkmode) print *,"step ","time ","dt"
time_begin = omp_get_wtime()
mloop: do nhy=1,nhymax
call TimestepControl
if(mod(nhy,nhydis) .eq. 0 .and. .not. benchmarkmode .and. myid_w == 0) print *,nhy,time,dt
call BoundaryCondition
call StateVevtor
call GravForce
call EvaulateCh
call NumericalFlux1
call NumericalFlux2
call NumericalFlux3
call UpdateConsv
call DampPsi
call PrimVariable
time=time+dt
if(.not. benchmarkmode ) call Output(usualoutput)
if(time > timemax) exit mloop
enddo mloop
time_end = omp_get_wtime()
if(myid_w == 0) print *, "total step, final dt, final time:", nhy,dt,time
if(myid_w == 0) print *, "sim time [s]:", time_end-time_begin
if(myid_w == 0) print *, "time/count/cell", (time_end-time_begin)/(ngrid1*ngrid2*ngrid3*ntiles(1)*ntiles(2)*ntiles(3))/nhy
is_final = .true.
call Output(forceoutput)
call FinalizeMPI
if(myid_w == 0) print *, "program has been finished"
end program main