Skip to content

Commit 38a7aba

Browse files
Add timers for openmp/multithreaded runs
1 parent c66d8e2 commit 38a7aba

17 files changed

+250
-32
lines changed

CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,11 @@ if( SELF_ENABLE_MULTITHREADING )
126126
set( OFFLOAD_FLAGS "-stdpar=multicore -Minfo=stdpar,accel" )
127127
endif()
128128

129-
set( CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${OFFLOAD_FLAGS}" )
130-
set( CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} ${OFFLOAD_FLAGS}" )
131-
set( CMAKE_Fortran_FLAGS_COVERAGE "${CMAKE_Fortran_FLAGS_COVERAGE} ${OFFLOAD_FLAGS}")
132-
set( CMAKE_Fortran_FLAGS_PROFILE "${CMAKE_Fortran_FLAGS_PROFILE} ${OFFLOAD_FLAGS}")
133-
set( CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE} ${OFFLOAD_FLAGS}" )
129+
set( CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${OFFLOAD_FLAGS} -DMULTITHREADING" )
130+
set( CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} ${OFFLOAD_FLAGS} -DMULTITHREADING" )
131+
set( CMAKE_Fortran_FLAGS_COVERAGE "${CMAKE_Fortran_FLAGS_COVERAGE} ${OFFLOAD_FLAGS} -DMULTITHREADING")
132+
set( CMAKE_Fortran_FLAGS_PROFILE "${CMAKE_Fortran_FLAGS_PROFILE} ${OFFLOAD_FLAGS} -DMULTITHREADING")
133+
set( CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE} ${OFFLOAD_FLAGS} -DMULTITHREADING" )
134134

135135
endif()
136136

examples/euler2d_thermal_bubble.f90

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
! //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// !
2+
!
3+
! Maintainers : support@fluidnumerics.com
4+
! Official Repository : https://github.com/FluidNumerics/self/
5+
!
6+
! Copyright © 2024 Fluid Numerics LLC
7+
!
8+
! Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
9+
!
10+
! 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
11+
!
12+
! 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in
13+
! the documentation and/or other materials provided with the distribution.
14+
!
15+
! 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from
16+
! this software without specific prior written permission.
17+
!
18+
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
! LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20+
! HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21+
! LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22+
! THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23+
! THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24+
!
25+
! //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// !
26+
27+
program Euler_Example
28+
29+
use self_data
30+
use self_Euler2D
31+
32+
implicit none
33+
34+
! Adapted from https://github.com/trixi-framework/Trixi.jl/blob/main/src/equations/compressible_euler_2d.jl#L157
35+
! A weak blast wave taken from
36+
! - Sebastian Hennemann, Gregor J. Gassner (2020)
37+
! A provably entropy stable subcell shock capturing approach for high order split form DG
38+
! [arXiv: 2008.12044](https://arxiv.org/abs/2008.12044)
39+
real(prec),parameter :: rho0 = 1.225_prec
40+
real(prec),parameter :: rhoprime = 0.1_prec
41+
real(prec),parameter :: Lr = 75.0_prec
42+
real(prec),parameter :: P0 = 101325.0_prec ! 1 atm
43+
real(prec),parameter :: Eprime = 35900.0_prec
44+
real(prec),parameter :: Le = 50.0_prec
45+
real(prec),parameter :: x0 = 250.0_prec
46+
real(prec),parameter :: y0 = 250.0_prec
47+
real(prec),parameter :: nu = 1.020408163_prec ! Viscosity
48+
real(prec),parameter :: kappa = 1.020408163_prec ! Thermal diffusivity (Pr = 1)
49+
! Grid parameters
50+
real(prec),parameter :: dx = 5.0_prec ! Grid spacing in the x-direction
51+
real(prec),parameter :: dy = 5.0_prec ! Grid spacing in the y-direction
52+
integer,parameter :: ny = 50 ! Number of x grid points per tile
53+
integer,parameter :: nx = 50 ! Number of y grid points per tile
54+
integer,parameter :: nTx = 2 ! Number of tiles in the x-direction
55+
integer,parameter :: nTy = 2 ! Number of tiles in the y-direction
56+
57+
character(SELF_INTEGRATOR_LENGTH),parameter :: integrator = 'rk3'
58+
integer,parameter :: controlDegree = 7
59+
integer,parameter :: targetDegree = 15
60+
real(prec),parameter :: dt = 10.0_prec**(-4) ! time-step size
61+
real(prec),parameter :: endtime = 10.0_prec**(-2) ! end time
62+
real(prec),parameter :: iointerval = 10.0_prec**(-3)
63+
real(prec) :: e0,ef ! Initial and final entropy
64+
type(Euler2D) :: modelobj
65+
type(Lagrange),target :: interp
66+
type(Mesh2D),target :: mesh
67+
type(SEMQuad),target :: geometry
68+
integer :: bcids(1:4)
69+
70+
! Create a structured mesh
71+
bcids(1:4) = [SELF_BC_NONORMALFLOW, & ! South
72+
SELF_BC_NONORMALFLOW, & ! East
73+
SELF_BC_NONORMALFLOW, & ! North
74+
SELF_BC_NONORMALFLOW] ! West
75+
76+
call mesh%StructuredMesh(nx,ny,nTx,nTy,dx,dy,bcids)
77+
78+
! Create an interpolant
79+
call interp%Init(N=controlDegree, &
80+
controlNodeType=GAUSS, &
81+
M=targetDegree, &
82+
targetNodeType=UNIFORM)
83+
84+
! Generate geometry (metric terms) from the mesh elements
85+
call geometry%Init(interp,mesh%nElem)
86+
call geometry%GenerateFromMesh(mesh)
87+
88+
! Initialize the model
89+
call modelobj%Init(mesh,geometry)
90+
modelobj%prescribed_bcs_enabled = .false. ! Disables prescribed boundary condition block for gpu accelerated implementations
91+
modelobj%tecplot_enabled = .false. ! Disable tecplot output
92+
modelobj%primitive_gradient_enabled = .true. ! Enable primitive gradient calculation for momentum and energy diffusion
93+
94+
! Set up blast wave initial conditions
95+
call modelobj%ThermalBubble(rho0,rhoprime,Lr,P0,Eprime,Le,x0,y0)
96+
97+
call modelobj%WriteModel()
98+
call modelobj%IncrementIOCounter()
99+
100+
call modelobj%CalculateEntropy()
101+
call modelobj%ReportEntropy()
102+
e0 = modelobj%entropy
103+
! Set the model's time integration method
104+
call modelobj%SetTimeIntegrator(integrator)
105+
106+
! forward step the model to `endtime` using a time step
107+
! of `dt` and outputing model data every `iointerval`
108+
call modelobj%ForwardStep(endtime,dt,iointerval)
109+
110+
ef = modelobj%entropy
111+
112+
if(ef > e0) then
113+
print*,"Error: Final absmax greater than initial absmax! ",e0,ef
114+
stop 1
115+
endif
116+
! Clean up
117+
call modelobj%free()
118+
call mesh%free()
119+
call geometry%free()
120+
call interp%free()
121+
122+
endprogram Euler_Example
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
! //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// !
2+
!
3+
! Maintainers : support@fluidnumerics.com
4+
! Official Repository : https://github.com/FluidNumerics/self/
5+
!
6+
! Copyright © 2024 Fluid Numerics LLC
7+
!
8+
! Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
9+
!
10+
! 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
11+
!
12+
! 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in
13+
! the documentation and/or other materials provided with the distribution.
14+
!
15+
! 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from
16+
! this software without specific prior written permission.
17+
!
18+
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
! LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20+
! HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21+
! LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22+
! THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23+
! THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24+
!
25+
! //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// !
26+
27+
program LinearEuler_Example
28+
29+
use self_data
30+
use self_LinearEuler3D
31+
32+
implicit none
33+
real(prec),parameter :: rho0 = 1.225_prec
34+
real(prec),parameter :: rhoprime = 0.01_prec
35+
real(prec),parameter :: c = 1.0_prec ! Speed of sound
36+
real(prec),parameter :: Lr = 0.06_prec
37+
real(prec),parameter :: x0 = 0.5_prec
38+
real(prec),parameter :: y0 = 0.5_prec
39+
real(prec),parameter :: z0 = 0.5_prec
40+
41+
character(SELF_INTEGRATOR_LENGTH),parameter :: integrator = 'rk3'
42+
integer,parameter :: controlDegree = 7
43+
integer,parameter :: targetDegree = 15
44+
real(prec),parameter :: dt = 5.0_prec*10.0_prec**(-4) ! time-step size
45+
real(prec),parameter :: endtime = 0.1_prec
46+
real(prec),parameter :: iointerval = 0.1_prec
47+
real(prec) :: e0,ef ! Initial and final entropy
48+
type(LinearEuler3D) :: modelobj
49+
type(Lagrange),target :: interp
50+
type(Mesh3D),target :: mesh
51+
type(SEMHex),target :: geometry
52+
integer :: bcids(1:6)
53+
54+
! Create a structured mesh
55+
bcids(1:6) = [SELF_BC_RADIATION, & ! Bottom
56+
SELF_BC_RADIATION, & ! South
57+
SELF_BC_RADIATION, & ! East
58+
SELF_BC_RADIATION, & ! North
59+
SELF_BC_RADIATION, & ! West
60+
SELF_BC_RADIATION] ! Top
61+
62+
call mesh%StructuredMesh(5,5,5,1,1,1, &
63+
0.2_prec,0.2_prec,0.2_prec,bcids)
64+
65+
! Create an interpolant
66+
call interp%Init(N=controlDegree, &
67+
controlNodeType=GAUSS, &
68+
M=targetDegree, &
69+
targetNodeType=UNIFORM)
70+
71+
! Generate geometry (metric terms) from the mesh elements
72+
call geometry%Init(interp,mesh%nElem)
73+
call geometry%GenerateFromMesh(mesh)
74+
75+
! Initialize the model
76+
call modelobj%Init(mesh,geometry)
77+
modelobj%prescribed_bcs_enabled = .false. ! Disables prescribed boundary condition block for gpu accelerated implementations
78+
modelobj%tecplot_enabled = .false. ! Disables tecplot output
79+
modelobj%rho0 = rho0 ! optional, set the reference density
80+
modelobj%c = c ! optional set the reference sound wave speed
81+
82+
! Set the initial condition
83+
call modelobj%SphericalSoundWave(rhoprime,Lr,x0,y0,z0)
84+
85+
call modelobj%WriteModel()
86+
call modelobj%IncrementIOCounter()
87+
88+
call modelobj%CalculateEntropy()
89+
call modelobj%ReportEntropy()
90+
e0 = modelobj%entropy
91+
! Set the model's time integration method
92+
call modelobj%SetTimeIntegrator(integrator)
93+
94+
! forward step the model to `endtime` using a time step
95+
! of `dt` and outputing model data every `iointerval`
96+
call modelobj%ForwardStep(endtime,dt,iointerval)
97+
98+
ef = modelobj%entropy
99+
100+
if(ef /= ef) then
101+
print*,"Error: Final entropy is inf or nan",ef
102+
stop 1
103+
endif
104+
! Clean up
105+
call modelobj%free()
106+
call mesh%free()
107+
call geometry%free()
108+
call interp%free()
109+
110+
endprogram LinearEuler_Example

src/SELF_Constants.f90

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ module SELF_Constants
3030
use iso_fortran_env
3131

3232
implicit none
33-
#include "SELF_Macros.h"
3433

3534
#ifdef DOUBLE_PRECISION
3635
integer,parameter :: prec = c_double

src/SELF_DGModel1D_t.f90

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ module SELF_DGModel1D_t
3737

3838
implicit none
3939

40-
#include "SELF_Macros.h"
41-
4240
type,extends(Model) :: DGModel1D_t
4341
type(MappedScalar1D) :: solution
4442
type(MappedScalar1D) :: solutionGradient
@@ -566,7 +564,7 @@ subroutine Write_DGModel1D_t(this,fileName)
566564
pickupFile = 'solution.'//timeStampString//'.h5'
567565
endif
568566

569-
INFO("Writing pickup file : "//trim(pickupFile))
567+
print*,__FILE__," : Writing pickup file : "//trim(pickupFile)
570568
call this%solution%UpdateHost()
571569

572570
call Open_HDF5(pickupFile,H5F_ACC_TRUNC_F,fileId)

src/SELF_DGModel2D_t.f90

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ module SELF_DGModel2D_t
3939

4040
implicit none
4141

42-
#include "SELF_Macros.h"
43-
4442
type,extends(Model) :: DGModel2D_t
4543
type(MappedScalar2D) :: solution
4644
type(MappedVector2D) :: solutionGradient

src/SELF_Data.f90

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ module SELF_Data
3737

3838
implicit none
3939

40-
#include "SELF_Macros.h"
41-
4240
type,public :: SELF_DataObj
4341
!! The SELF_DataObj class is a base class for all data objects in SELF.
4442
!! A data object in SELF is a multidimensional array of data, represented

src/SELF_Geometry_1D.f90

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ module SELF_Geometry_1D
3535

3636
implicit none
3737

38-
#include "SELF_Macros.h"
39-
4038
type,public :: Geometry1D
4139
type(Scalar1D) :: x ! Physical Positions
4240
type(Scalar1D) :: dxds ! Conversion from computational to physical space

src/SELF_Geometry_2D.f90

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ module SELF_Geometry_2D
3737

3838
implicit none
3939

40-
#include "SELF_Macros.h"
41-
4240
type,public :: SEMQuad
4341
type(Vector2D) :: x ! Physical positions
4442
type(Tensor2D) :: dxds ! Covariant basis vectors

src/SELF_Macros.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,10 @@
2828
#define INFO(msg) PRINT('("INFO : [",A,"] : ",A)'),__FUNC__,msg
2929
#define WARNING(msg) PRINT('("WARNING : [",A,"] : ",A)'),__FUNC__,msg
3030
#define ERROR(msg) PRINT('("ERROR : [",A,"] : ",A)'),__FUNC__,msg
31+
32+
#ifdef MULTITHREADING
33+
use omp_lib
34+
#define TIMER(t) t=omp_get_wtime()
35+
#else
36+
#define TIMER(t) call cpu_time(t)
37+
#endif

0 commit comments

Comments
 (0)