Huge improvement in reset (by increasing a little bit push time) using

OMP locks to assign particles to cells in the pushing step.

Trying to combine push+reset and  collision+scatter did not work.
This commit is contained in:
Jorge Gonzalez 2020-10-17 18:46:10 +02:00
commit fd42e0f3f9
7 changed files with 101 additions and 92 deletions

View file

@ -10,10 +10,10 @@ set style line 10 lt 1 lw 2.0 lc rgb "black" #Black solid line
name1 = "Base Case" name1 = "Base Case"
folder1 = "base_case/" folder1 = "base_case/"
name2 = "New Version" name2 = "OMP LOCK 1"
folder2 = "2020-10-17_14.10.29/" folder2 = "OMP_LOCK_1/"
name3 = "Reset with List" name3 = "OMP LOCK 2"
folder3 = "2020-10-13_18.29.33/" folder3 = "2020-10-17_18.33.45/"
name4 = "Reset with List Parallel" name4 = "Reset with List Parallel"
folder4 = "2020-10-11_15.20.09/" folder4 = "2020-10-11_15.20.09/"
@ -65,52 +65,52 @@ plot folder1."cpuTime.dat" u 1:($2) t name1 ls 1, \
unset multiplot unset multiplot
set terminal qt enhanced 2 persist size 1600, 1000 font "Times ,10" # set terminal qt enhanced 2 persist size 1600, 1000 font "Times ,10"
#
set style line 1 pt 4 lc rgb "#B50427" #Squares red # set style line 1 pt 4 lc rgb "#B50427" #Squares red
set style line 2 pt 6 lc rgb "#3B4CC1" #Circles blue # set style line 2 pt 6 lc rgb "#3B4CC1" #Circles blue
set style line 3 pt 1 lc rgb "#2CA02C" #Crosses green # set style line 3 pt 1 lc rgb "#2CA02C" #Crosses green
set style line 4 pt 2 lc rgb "#FE7F0E" #Exes orange # set style line 4 pt 2 lc rgb "#FE7F0E" #Exes orange
set style line 5 pt 8 lc rgb "#D6696B" #Triangles light red # set style line 5 pt 8 lc rgb "#D6696B" #Triangles light red
set style line 10 lt 1 lw 2.0 lc rgb "black" #Black solid line # set style line 10 lt 1 lw 2.0 lc rgb "black" #Black solid line
#
set key box opaque # set key box opaque
set pointsize 1.5 # set pointsize 1.5
#
set ylabel "Time per particle (micros)" # set ylabel "Time per particle (micros)"
set xrange [0:500] # set xrange [0:500]
set xlabel "Iteration" # set xlabel "Iteration"
#
#
set multiplot layout 2,3 # set multiplot layout 2,3
set title "Total" # set title "Total"
plot folder1."cpuTime.dat" u 1:(1e6*$3/$2) t name1 ls 1, \ # plot folder1."cpuTime.dat" u 1:(1e6*$3/$2) t name1 ls 1, \
folder2."cpuTime.dat" u 1:(1e6*$3/$2) t name2 ls 2, \ # folder2."cpuTime.dat" u 1:(1e6*$3/$2) t name2 ls 2, \
folder3."cpuTime.dat" u 1:(1e6*$3/$2) t name3 ls 3, \ # folder3."cpuTime.dat" u 1:(1e6*$3/$2) t name3 ls 3, \
folder4."cpuTime.dat" u 1:(1e6*$3/$2) t name4 ls 4 # folder4."cpuTime.dat" u 1:(1e6*$3/$2) t name4 ls 4
#
set title "Push" # set title "Push"
plot folder1."cpuTime.dat" u 1:(1e6*$4/$2) t name1 ls 1, \ # plot folder1."cpuTime.dat" u 1:(1e6*$4/$2) t name1 ls 1, \
folder2."cpuTime.dat" u 1:(1e6*$4/$2) t name2 ls 2, \ # folder2."cpuTime.dat" u 1:(1e6*$4/$2) t name2 ls 2, \
folder3."cpuTime.dat" u 1:(1e6*$4/$2) t name3 ls 3, \ # folder3."cpuTime.dat" u 1:(1e6*$4/$2) t name3 ls 3, \
folder4."cpuTime.dat" u 1:(1e6*$4/$2) t name4 ls 4 # folder4."cpuTime.dat" u 1:(1e6*$4/$2) t name4 ls 4
#
set title "Reset" # set title "Reset"
plot folder1."cpuTime.dat" u 1:(1e6*$5/$2) t name1 ls 1, \ # plot folder1."cpuTime.dat" u 1:(1e6*$5/$2) t name1 ls 1, \
folder2."cpuTime.dat" u 1:(1e6*$5/$2) t name2 ls 2, \ # folder2."cpuTime.dat" u 1:(1e6*$5/$2) t name2 ls 2, \
folder3."cpuTime.dat" u 1:(1e6*$5/$2) t name3 ls 3, \ # folder3."cpuTime.dat" u 1:(1e6*$5/$2) t name3 ls 3, \
folder4."cpuTime.dat" u 1:(1e6*$5/$2) t name4 ls 4 # folder4."cpuTime.dat" u 1:(1e6*$5/$2) t name4 ls 4
#
set title "Collisions" # set title "Collisions"
plot folder1."cpuTime.dat" u 1:(1e6*$6/$2) t name1 ls 1, \ # plot folder1."cpuTime.dat" u 1:(1e6*$6/$2) t name1 ls 1, \
folder2."cpuTime.dat" u 1:(1e6*$6/$2) t name2 ls 2, \ # folder2."cpuTime.dat" u 1:(1e6*$6/$2) t name2 ls 2, \
folder3."cpuTime.dat" u 1:(1e6*$6/$2) t name3 ls 3, \ # folder3."cpuTime.dat" u 1:(1e6*$6/$2) t name3 ls 3, \
folder4."cpuTime.dat" u 1:(1e6*$6/$2) t name4 ls 4 # folder4."cpuTime.dat" u 1:(1e6*$6/$2) t name4 ls 4
#
set title "Weighting" # set title "Weighting"
plot folder1."cpuTime.dat" u 1:(1e6*$7/$2) t name1 ls 1, \ # plot folder1."cpuTime.dat" u 1:(1e6*$7/$2) t name1 ls 1, \
folder2."cpuTime.dat" u 1:(1e6*$7/$2) t name2 ls 2, \ # folder2."cpuTime.dat" u 1:(1e6*$7/$2) t name2 ls 2, \
folder3."cpuTime.dat" u 1:(1e6*$7/$2) t name3 ls 3, \ # folder3."cpuTime.dat" u 1:(1e6*$7/$2) t name3 ls 3, \
folder4."cpuTime.dat" u 1:(1e6*$7/$2) t name4 ls 4 # folder4."cpuTime.dat" u 1:(1e6*$7/$2) t name4 ls 4
#
unset multiplot # unset multiplot

View file

@ -17,7 +17,6 @@ PROGRAM DSMC_Neutrals
INTEGER:: t, n, e, i INTEGER:: t, n, e, i
CHARACTER(200):: arg1 CHARACTER(200):: arg1
CHARACTER(:), ALLOCATABLE:: inputFile CHARACTER(:), ALLOCATABLE:: inputFile
REAL(8), EXTERNAL::omp_get_wtime
!Gets the input file !Gets the input file
@ -45,6 +44,7 @@ PROGRAM DSMC_Neutrals
DO t = 1, tmax DO t = 1, tmax
!Insert new particles !Insert new particles
!$OMP SINGLE !$OMP SINGLE
n_part_new = 0
tStep = omp_get_wtime() tStep = omp_get_wtime()
tPush = omp_get_wtime() tPush = omp_get_wtime()
DO i=1, nInject DO i=1, nInject
@ -62,14 +62,6 @@ PROGRAM DSMC_Neutrals
!$OMP SINGLE !$OMP SINGLE
tPush = omp_get_wtime() - tPush tPush = omp_get_wtime() - tPush
tReset = omp_get_wtime()
!$OMP END SINGLE
!Reset particles
CALL resetParticles(part_inj, part_old)
!$OMP SINGLE
tReset = omp_get_wtime() - tReset
tColl = omp_get_wtime() tColl = omp_get_wtime()
!$OMP END SINGLE !$OMP END SINGLE
@ -82,6 +74,14 @@ PROGRAM DSMC_Neutrals
!$OMP SINGLE !$OMP SINGLE
tColl = omp_get_wtime() - tColl tColl = omp_get_wtime() - tColl
tReset = omp_get_wtime()
!$OMP END SINGLE
!Reset particles
CALL resetParticles(part_inj, part_old)
!$OMP SINGLE
tReset = omp_get_wtime() - tReset
!Weight !Weight
tWeight = omp_get_wtime() tWeight = omp_get_wtime()
@ -93,12 +93,14 @@ PROGRAM DSMC_Neutrals
tWeight = omp_get_wtime() - tWeight tWeight = omp_get_wtime() - tWeight
tStep = omp_get_wtime() - tStep tStep = omp_get_wtime() - tStep
!Output data !Output data
!TODO: Move to subroutine
counterOutput=counterOutput+1 counterOutput=counterOutput+1
IF (counterOutput>=triggerOutput .OR. t == tmax) THEN IF (counterOutput>=triggerOutput .OR. t == tmax) THEN
counterOutput=0 counterOutput=0
CALL mesh%printOutput(t) CALL mesh%printOutput(t)
CALL printTime(t) CALL printTime(t)
CALL mesh%printColl(t) CALL mesh%printColl(t)
!TODO: Move to subroutine
PRINT *, "t/tmax: ", t, "/", tmax PRINT *, "t/tmax: ", t, "/", tmax
PRINT *, "Particles: ", n_part_old PRINT *, "Particles: ", n_part_old
WRITE (*, "(2(5X,A26))") "total time (ms)", "avg t/particle (ns)" WRITE (*, "(2(5X,A26))") "total time (ms)", "avg t/particle (ns)"

View file

@ -19,7 +19,6 @@ MODULE moduleList
END TYPE listNode END TYPE listNode
CONTAINS CONTAINS
!Finalize node
!Adds element to list !Adds element to list
SUBROUTINE addToList(this,part) SUBROUTINE addToList(this,part)
USE moduleSpecies USE moduleSpecies

View file

@ -2,6 +2,7 @@
MODULE moduleMesh MODULE moduleMesh
USE moduleList USE moduleList
USE moduleOutput USE moduleOutput
USE OMP_LIB
IMPLICIT NONE IMPLICIT NONE
!Parent of Node element !Parent of Node element
@ -90,6 +91,8 @@ MODULE moduleMesh
REAL(8):: volume = 0.D0 REAL(8):: volume = 0.D0
!List of particles inside the volume !List of particles inside the volume
TYPE(listNode):: listPart_in TYPE(listNode):: listPart_in
!Lock indicator for listPart_in
INTEGER(KIND=OMP_LOCK_KIND):: lock
!Number of collisions per volume !Number of collisions per volume
INTEGER:: nColl = 0 INTEGER:: nColl = 0
CONTAINS CONTAINS
@ -131,7 +134,7 @@ MODULE moduleMesh
IMPORT:: meshVol IMPORT:: meshVol
CLASS(meshVol), INTENT(inout):: self CLASS(meshVol), INTENT(inout):: self
CLASS(meshVol), OPTIONAL, INTENT(in):: oldCell CLASS(meshVol), OPTIONAL, INTENT(in):: oldCell
CLASS(particle), INTENT(inout):: part CLASS(particle), INTENT(inout), TARGET:: part
END SUBROUTINE findCell_interface END SUBROUTINE findCell_interface

View file

@ -175,6 +175,8 @@ MODULE moduleMeshCyl
self%sigmaVrelMax = sigma_ref/L_ref**2 self%sigmaVrelMax = sigma_ref/L_ref**2
CALL OMP_INIT_LOCK(self%lock)
END SUBROUTINE initVolQuadCyl END SUBROUTINE initVolQuadCyl
FUNCTION fpsi(xi1,xi2) RESULT(psi) FUNCTION fpsi(xi1,xi2) RESULT(psi)
@ -433,7 +435,7 @@ MODULE moduleMeshCyl
CLASS(meshVolCylQuad), INTENT(inout):: self CLASS(meshVolCylQuad), INTENT(inout):: self
CLASS(meshVol), OPTIONAL, INTENT(in):: oldCell CLASS(meshVol), OPTIONAL, INTENT(in):: oldCell
CLASS(particle), INTENT(inout):: part CLASS(particle), INTENT(inout), TARGET:: part
REAL(8):: xLog(1:2) REAL(8):: xLog(1:2)
REAL(8):: xLogArray(1:4) REAL(8):: xLogArray(1:4)
CLASS(*), POINTER:: nextElement CLASS(*), POINTER:: nextElement
@ -445,9 +447,15 @@ MODULE moduleMeshCyl
IF (PRESENT(oldCell)) THEN IF (PRESENT(oldCell)) THEN
!If oldCell, recalculate particle weight, as particle has entered a new cell. !If oldCell, recalculate particle weight, as particle has entered a new cell.
part%weight = part%weight*oldCell%volume/self%volume part%weight = part%weight*oldCell%volume/self%volume
END IF END IF
part%e_p = self%n part%e_p = self%n
part%xLog = xLog part%xLog = xLog
!Assign particle to listPart_in
CALL OMP_SET_LOCK(self%lock)
CALL self%listPart_in%add(part)
CALL OMP_UNSET_LOCK(self%lock)
ELSE ELSE
!If not, searches for a neighbour and repeats the process. !If not, searches for a neighbour and repeats the process.
xLogArray = (/ -xLog(2), xLog(1), xLog(2), -xLog(1) /) xLogArray = (/ -xLog(2), xLog(1), xLog(2), -xLog(1) /)
@ -514,8 +522,6 @@ MODULE moduleMeshCyl
SUBROUTINE collision2DCyl(self) SUBROUTINE collision2DCyl(self)
USE moduleRefParam
USE moduleConstParam
USE moduleCollisions USE moduleCollisions
USE moduleSpecies USE moduleSpecies
USE moduleList USE moduleList
@ -549,8 +555,11 @@ MODULE moduleMeshCyl
END DO END DO
!Update maximum cross section times vrelative per each collision !Update maximum cross section*v_rel per each collision
IF (sigmaVrelMaxNew > self%sigmaVrelMax) self%sigmaVrelMax = sigmaVrelMaxNew IF (sigmaVrelMaxNew > self%sigmaVrelMax) THEN
self%sigmaVrelMax = sigmaVrelMaxNew
END IF
END DO END DO

View file

@ -1,7 +1,6 @@
MODULE moduleSolver MODULE moduleSolver
CONTAINS CONTAINS
SUBROUTINE scatterGrid(meshIn, partArray) SUBROUTINE scatterGrid(meshIn, partArray)
USE moduleSpecies USE moduleSpecies
USE moduleMesh USE moduleMesh
@ -53,15 +52,14 @@ MODULE moduleSolver
part_temp%v(3) = -sin_alpha*v_p_oh_star(2)+cos_alpha*v_p_oh_star(3) part_temp%v(3) = -sin_alpha*v_p_oh_star(2)+cos_alpha*v_p_oh_star(3)
part_temp%pt = part%pt part_temp%pt = part%pt
part_temp%e_p = part%e_p part_temp%e_p = part%e_p
!Assign cell to particle !Copy temporal particle to particle
part=part_temp part=part_temp
END SUBROUTINE push END SUBROUTINE push
SUBROUTINE resetParticles(partInj, partOld) SUBROUTINE resetParticles(partInj, partOld)
USE moduleSpecies USE moduleSpecies, ONLY: particle, &
USE moduleList n_part_old, n_part_new, nPartInj
USE moduleMesh
IMPLICIT NONE IMPLICIT NONE
TYPE(particle), INTENT(in), ALLOCATABLE:: partInj(:) TYPE(particle), INTENT(in), ALLOCATABLE:: partInj(:)
@ -88,16 +86,15 @@ MODULE moduleSolver
!$OMP BARRIER !$OMP BARRIER
!$OMP SINGLE !$OMP SINGLE
CALL MOVE_ALLOC(part_old, partTemp) CALL MOVE_ALLOC(partOld, partTemp)
n_part_new = n_inj_in + n_old_in n_part_new = n_inj_in + n_old_in
ALLOCATE(partOld(1:n_part_new)) ALLOCATE(partOld(1:n_part_new))
nn = 0 nn = 0
DO n = 1, nPartInj DO n = 1, nPartInj
IF (part_inj(n)%n_in) THEN IF (partInj(n)%n_in) THEN
nn = nn + 1 nn = nn + 1
part_old(nn) = part_inj(n) partOld(nn) = partInj(n)
CALL mesh%vols(part_old(nn)%e_p)%obj%listPart_in%add(part_old(nn))
END IF END IF
@ -107,7 +104,6 @@ MODULE moduleSolver
IF (partTemp(n)%n_in) THEN IF (partTemp(n)%n_in) THEN
nn = nn + 1 nn = nn + 1
partOld(nn) = partTemp(n) partOld(nn) = partTemp(n)
CALL mesh%vols(partOld(nn)%e_p)%obj%listPart_in%add(partOld(nn))
END IF END IF