Skip to content

Commit

Permalink
Fortran: removed C++ main
Browse files Browse the repository at this point in the history
  • Loading branch information
WeiqunZhang committed Jul 26, 2017
1 parent be3e897 commit 2a9d06f
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 54 deletions.
2 changes: 0 additions & 2 deletions GNUmakefile.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

USE_AMREX_FI_MAIN = FALSE

AMREX_HOME := $(shell pwd)

include $(AMREX_HOME)/Tools/GNUMake/Make.defs
Expand Down
10 changes: 10 additions & 0 deletions Src/F_Interfaces/AmrCore/AMReX_amrcore_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,16 @@ subroutine amrex_fi_regrid (baselev, t, amrcore) bind(c)
end subroutine amrex_fi_regrid
end interface

logical, save, private :: call_amrex_finalize = .false.

contains

subroutine amrex_amrcore_init ()
integer :: ilev
if (.not.amrex_initialized()) then
call amrex_init()
call_amrex_finalize = .true.
end if
call amrex_fi_new_amrcore(amrcore)
amrex_max_level = amrex_fi_get_max_level(amrcore)
allocate(amrex_ref_ratio(0:amrex_max_level-1))
Expand All @@ -178,6 +184,10 @@ end subroutine amrex_amrcore_init
subroutine amrex_amrcore_finalize ()
call amrex_fi_delete_amrcore(amrcore)
amrcore = c_null_ptr
if (call_amrex_finalize) then
call amrex_finalize()
call_amrex_finalize = .false.
end if
end subroutine amrex_amrcore_finalize

logical function amrex_amrcore_initialized ()
Expand Down
20 changes: 0 additions & 20 deletions Src/F_Interfaces/Base/AMReX_fi_main.cpp

This file was deleted.

10 changes: 9 additions & 1 deletion Src/F_Interfaces/Base/AMReX_init_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ module amrex_init_module
implicit none

private
public :: amrex_init, amrex_finalize
public :: amrex_init, amrex_finalize, amrex_initialized

logical, save, private :: initialized = .false.

contains

Expand All @@ -27,6 +29,7 @@ end subroutine amrex_fi_init
else
call amrex_string_build(cmd_string, cmd)
call amrex_fi_init(cmd_string%data)
initialized = .true.
end if
end subroutine amrex_init

Expand All @@ -38,6 +41,11 @@ subroutine amrex_fi_finalize() bind(c)
end subroutine amrex_fi_finalize
end interface
call amrex_fi_finalize()
initialized = .false.
end subroutine amrex_finalize

pure logical function amrex_initialized ()
amrex_initialized = initialized
end function amrex_initialized

end module amrex_init_module
6 changes: 0 additions & 6 deletions Src/F_Interfaces/Base/Make.package
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
DEFINES += -DBL_USE_F_INTERFACES

USE_AMREX_FI_MAIN ?= TRUE

ifeq ($(USE_AMREX_FI_MAIN),TRUE)
CEXE_sources += AMReX_fi_main.cpp
endif

F90EXE_sources += AMReX_init_mod.F90

F90EXE_sources += AMReX_parallel_mod.F90
Expand Down
6 changes: 4 additions & 2 deletions Tutorials/Amr/Advection_F/Source/fmain.F90
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

subroutine amrex_fmain () bind(c)
program main

use amrex_amr_module

Expand All @@ -9,6 +9,7 @@ subroutine amrex_fmain () bind(c)

implicit none

call amrex_init()
call amrex_amrcore_init()

call my_amr_init()
Expand All @@ -20,5 +21,6 @@ subroutine amrex_fmain () bind(c)
call my_amr_finalize()

call amrex_amrcore_finalize()
call amrex_finalize()

end subroutine amrex_fmain
end program main
19 changes: 13 additions & 6 deletions Tutorials/Amr/Advection_F/Source/my_amr_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ module my_amr_module
real(rt) :: stop_time = huge(1._rt)
real(rt) :: cfl = 0.7_rt
!
character(len=127) :: check_file = "chk"
character(len=127) :: plot_file = "plt"
character(len=127) :: restart = ""
character(len=:), allocatable, save :: check_file
character(len=:), allocatable, save :: plot_file
character(len=:), allocatable, save :: restart

integer, allocatable :: stepno(:)
integer, allocatable :: nsubsteps(:)
integer, allocatable, save :: stepno(:)
integer, allocatable, save :: nsubsteps(:)

real(rt), allocatable :: dt(:)
real(rt), allocatable, save :: dt(:)

integer, private, parameter :: ncomp = 1, nghost = 0

Expand All @@ -47,6 +47,13 @@ subroutine my_amr_init ()
& my_clear_level, &
& my_error_estimate)

! some default parameters
allocate(character(len=3)::check_file)
check_file = "chk"
allocate(character(len=3)::plot_file)
plot_file = "plt"
allocate(character(len=0)::restart)

! Read parameters
call amrex_parmparse_build(pp)
call pp%query("max_step", max_step)
Expand Down
8 changes: 4 additions & 4 deletions Tutorials/Amr/Advection_octree_F/Source/fmain.F90
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

subroutine amrex_fmain () bind(c)
program main

use amrex_amr_module
use amrex_octree_module
Expand All @@ -10,8 +10,8 @@ subroutine amrex_fmain () bind(c)

implicit none

call amrex_init()
call amrex_octree_init()

call amrex_amrcore_init()

call my_amr_init()
Expand All @@ -23,7 +23,7 @@ subroutine amrex_fmain () bind(c)
call my_amr_finalize()

call amrex_amrcore_finalize()

call amrex_octree_finalize()
call amrex_finalize()

end subroutine amrex_fmain
end program main
17 changes: 12 additions & 5 deletions Tutorials/Amr/Advection_octree_F/Source/my_amr_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ module my_amr_module
real(rt) :: stop_time = huge(1._rt)
real(rt) :: cfl = 0.7_rt
!
character(len=127) :: check_file = "chk"
character(len=127) :: plot_file = "plt"
character(len=127) :: restart = ""
character(len=:), allocatable, save :: check_file
character(len=:), allocatable, save :: plot_file
character(len=:), allocatable, save :: restart

integer :: stepno
real(rt) :: dtstep
integer, save :: stepno
real(rt), save :: dtstep

integer, private, parameter :: ncomp = 1, nghost = 0

Expand All @@ -42,6 +42,13 @@ subroutine my_amr_init ()
& my_clear_level, &
& my_error_estimate)

! some default parameters
allocate(character(len=3)::check_file)
check_file = "chk"
allocate(character(len=3)::plot_file)
plot_file = "plt"
allocate(character(len=0)::restart)

! Read parameters
call amrex_parmparse_build(pp)
call pp%query("max_step", max_step)
Expand Down
2 changes: 0 additions & 2 deletions Tutorials/Basic/HeatEquation_EX1_F/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ COMP = g++

DIM = 3

USE_AMREX_FI_MAIN = TRUE

EBASE = main

include ./Make.package
Expand Down
9 changes: 7 additions & 2 deletions Tutorials/Basic/HeatEquation_EX1_F/fmain.f90
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

subroutine amrex_fmain () bind(c)
program main

use amrex_base_module

Expand All @@ -19,6 +19,8 @@ subroutine amrex_fmain () bind(c)
type(amrex_geometry) :: geom
type(amrex_multifab) :: new_phi, old_phi

call amrex_init()

! amrex_parmparse is way of reading inputs from the inputs file
! "get" means it must be set in the inputs file, whereas
! "query" means it may not may not be in the inputs file
Expand Down Expand Up @@ -87,4 +89,7 @@ subroutine amrex_fmain () bind(c)

call amrex_geometry_destroy(geom)

end subroutine amrex_fmain
call amrex_finalize()

end program main

8 changes: 6 additions & 2 deletions Tutorials/Basic/HelloWorld_F/fmain.f90
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@

subroutine amrex_fmain () bind(c)
program main

use amrex_base_module

implicit none

call amrex_init()

if (amrex_parallel_ioprocessor()) then
print *, "Hello world!"
end if

end subroutine amrex_fmain
call amrex_finalize()

end program main
2 changes: 0 additions & 2 deletions Tutorials/Basic/main_F/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ COMP = gnu
USE_MPI = TRUE
USE_OMP = FALSE

USE_AMREX_FI_MAIN = FALSE

include $(AMREX_HOME)/Tools/GNUMake/Make.defs

include ./Make.package
Expand Down

0 comments on commit 2a9d06f

Please sign in to comment.