From 60f38a2d95b0124646cf34de55956ca083057cd2 Mon Sep 17 00:00:00 2001 From: Jorge Gonzalez Date: Sat, 10 Oct 2020 21:25:49 +0200 Subject: [PATCH] Commit befor trying to convert particle array to linked list to improve performance. --- runs/cylFlow/compCPUTime.gp | 54 ++++++++++++++++++++++++++++++++++ runs/cylFlow/input.json | 9 ++++-- runs/cylFlow/plotCPUTime.gp | 49 ++++++++++++++++++++++++++++++ src/DSMC_Neutrals.f95 | 10 ++++--- src/makefile | 2 +- src/modules/makefile | 5 ++-- src/modules/moduleInput.f95 | 33 +++++++++++++++++++-- src/modules/moduleParallel.f95 | 10 +++++++ 8 files changed, 160 insertions(+), 12 deletions(-) create mode 100644 runs/cylFlow/compCPUTime.gp create mode 100644 runs/cylFlow/plotCPUTime.gp create mode 100644 src/modules/moduleParallel.f95 diff --git a/runs/cylFlow/compCPUTime.gp b/runs/cylFlow/compCPUTime.gp new file mode 100644 index 0000000..7b1155d --- /dev/null +++ b/runs/cylFlow/compCPUTime.gp @@ -0,0 +1,54 @@ + +set terminal qt enhanced 1 size 1600, 1000 font "Times ,10" + +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 3 pt 1 lc rgb "#2CA02C" #Crosses green +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 10 lt 1 lw 2.0 lc rgb "black" #Black solid line + +folder1 = "2020-09-27_10.46.31/" +folder2 = "2020-09-28_10.49.22/" +folder3 = "2020-09-30_20.40.04/" +folder4 = "2020-10-01_08.53.50/" + +set key box opaque +set pointsize 1.5 + +set ylabel "Time per particle (ms)" +set xrange [0:8000] +set xlabel "Iteration" + + +set multiplot layout 2,3 +set title "Total" +plot folder1."cpuTime.dat" u 1:(1e3*$3) t "Step 1" ls 1, \ + folder2."cpuTime.dat" u 1:(1e3*$3) t "Step 2" ls 2, \ + folder3."cpuTime.dat" u 1:(1e3*$3) t "Step 3" ls 3, \ + folder4."cpuTime.dat" u 1:(1e3*$3) t "Step 4" ls 4 + +set title "Push" +plot folder1."cpuTime.dat" u 1:(1e3*$4) t "Step 1" ls 1, \ + folder2."cpuTime.dat" u 1:(1e3*$4) t "Step 2" ls 2, \ + folder3."cpuTime.dat" u 1:(1e3*$4) t "Step 3" ls 3, \ + folder4."cpuTime.dat" u 1:(1e3*$4) t "Step 4" ls 4 + +set title "Reset" +plot folder1."cpuTime.dat" u 1:(1e3*$5) t "Step 1" ls 1, \ + folder2."cpuTime.dat" u 1:(1e3*$5) t "Step 2" ls 2, \ + folder3."cpuTime.dat" u 1:(1e3*$5) t "Step 3" ls 3, \ + folder4."cpuTime.dat" u 1:(1e3*$5) t "Step 4" ls 4 + +set title "Collisions" +plot folder1."cpuTime.dat" u 1:(1e3*$6) t "Step 1" ls 1, \ + folder2."cpuTime.dat" u 1:(1e3*$6) t "Step 2" ls 2, \ + folder3."cpuTime.dat" u 1:(1e3*$6) t "Step 3" ls 3, \ + folder4."cpuTime.dat" u 1:(1e3*$6) t "Step 4" ls 4 + +set title "Weighting" +plot folder1."cpuTime.dat" u 1:(1e3*$7) t "Step 1" ls 1, \ + folder2."cpuTime.dat" u 1:(1e3*$7) t "Step 2" ls 2, \ + folder3."cpuTime.dat" u 1:(1e3*$7) t "Step 3" ls 3, \ + folder4."cpuTime.dat" u 1:(1e3*$7) t "Step 4" ls 4 + \ No newline at end of file diff --git a/runs/cylFlow/input.json b/runs/cylFlow/input.json index b73cbb0..e50d719 100644 --- a/runs/cylFlow/input.json +++ b/runs/cylFlow/input.json @@ -1,8 +1,8 @@ { "output": { "path": "./runs/cylFlow/", - "trigger": 100, - "cpuTime": false, + "trigger": 10, + "cpuTime": true, "numColl": false }, "geometry": { @@ -38,5 +38,10 @@ "collisions": [ {"species_i": "Argon", "species_j": "Argon", "crossSections": ["Ar-Ar_Elastic.dat"]} ] + }, + "parallel": { + "OpenMP":{ + "nThreads": 24 + } } } diff --git a/runs/cylFlow/plotCPUTime.gp b/runs/cylFlow/plotCPUTime.gp new file mode 100644 index 0000000..62c9314 --- /dev/null +++ b/runs/cylFlow/plotCPUTime.gp @@ -0,0 +1,49 @@ +reset +set terminal qt enhanced 1 size 1800, 400 font "Times ,10" + +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 3 pt 1 lc rgb "#2CA02C" #Crosses green +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 10 lt 1 lw 2.0 lc rgb "black" #Black solid line + +set style data histogram +set style histogram rowstacked title offset 0,-1 +set style fill solid border -1 +set boxwidth 0.50 + +set key box opaque + +set yrange [0:100] +set ylabel "CPU Time (%)" +set xrange [0:] + + +plot "cpuTime.dat" u ($4/$3*100) t "Push" ls 1, \ + "" u ($5/$3*100) t "Reset" ls 2, \ + "" u ($6/$3*100) t "Collisions" ls 3, \ + "" u ($7/$3*100) t "Weighting" ls 4 + +reset +set terminal qt enhanced 2 size 800, 600 font "Times ,10" + +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 3 pt 1 lc rgb "#2CA02C" #Crosses green +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 10 lt 1 lw 2.0 lc rgb "black" #Black solid line + +set key box opaque +set pointsize 1.5 + +set ylabel "Time per particle ({/Symbol m}s)" +set xrange [0:] +set xlabel "Iteration" + + +plot "cpuTime.dat" u 1:(1e6*$4/$2) t "Push" ls 1, \ + "" u 1:(1e6*$5/$2) t "Reset" ls 2, \ + "" u 1:(1e6*$6/$2) t "Collisions" ls 3, \ + "" u 1:(1e6*$7/$2) t "Weighting" ls 4 \ No newline at end of file diff --git a/src/DSMC_Neutrals.f95 b/src/DSMC_Neutrals.f95 index ab537cd..7d6ab1d 100644 --- a/src/DSMC_Neutrals.f95 +++ b/src/DSMC_Neutrals.f95 @@ -10,17 +10,15 @@ PROGRAM DSMC_Neutrals USE moduleList USE moduleOutput USE moduleCaseParam + USE moduleParallel IMPLICIT NONE ! t = time step; n = number of particle; e = number of element; i = number of inject INTEGER:: t, n, e, i CHARACTER(200):: arg1 CHARACTER(:), ALLOCATABLE:: inputFile - REAL(8), EXTERNAL::omp_get_wtime, omp_get_wtick + REAL(8), EXTERNAL::omp_get_wtime - !Starts threads for OpenMP parallelization - !TODO: make this an input parameter - CALL OMP_SET_NUM_THREADS(8) !Gets the input file CALL getarg(1, arg1) @@ -39,6 +37,10 @@ PROGRAM DSMC_Neutrals PRINT *, "t/tmax: ", t, "/", tmax PRINT *, "Particles: ", n_part_old + !Starts threads for OpenMP parallelization + !TODO: make this an input parameter + CALL OMP_SET_NUM_THREADS(openMP%nThreads) + !$OMP PARALLEL PRIVATE(t) DEFAULT(SHARED) DO t = 1, tmax tStep = omp_get_wtime() diff --git a/src/makefile b/src/makefile index ecc2529..b0dfff0 100644 --- a/src/makefile +++ b/src/makefile @@ -4,7 +4,7 @@ OBJECTS = $(OBJDIR)/$(OUTPUT).o \ $(OBJDIR)/moduleErrors.o $(OBJDIR)/moduleList.o $(OBJDIR)/moduleOutput.o \ $(OBJDIR)/moduleMeshCyl.o $(OBJDIR)/moduleMeshCylRead.o $(OBJDIR)/moduleMeshCylBoundary.o \ $(OBJDIR)/moduleBoundary.o $(OBJDIR)/moduleCaseParam.o $(OBJDIR)/moduleRefParam.o \ - $(OBJDIR)/moduleCollisions.o $(OBJDIR)/moduleTable.o + $(OBJDIR)/moduleCollisions.o $(OBJDIR)/moduleTable.o $(OBJDIR)/moduleParallel.o all: $(OUTPUT) diff --git a/src/modules/makefile b/src/modules/makefile index 5b59144..a7df1b5 100644 --- a/src/modules/makefile +++ b/src/modules/makefile @@ -2,14 +2,15 @@ OBJS = moduleCaseParam.o moduleCompTime.o moduleList.o\ moduleMesh.o moduleMeshCyl.o moduleMeshCylBoundary.o\ moduleMeshCylRead.o moduleOutput.o moduleInput.o \ - moduleSolver.o moduleCollisions.o moduleTable.o + moduleSolver.o moduleCollisions.o moduleTable.o \ + moduleParallel.o all: $(OBJS) moduleCollisions.o: moduleTable.o moduleSpecies.o moduleRefParam.o moduleConstParam.o moduleMeshCyl.f95 $(FC) $(FCFLAGS) -c $(subst .o,.f95, $@) -o $(OBJDIR)/$@ -moduleInput.o: moduleRefParam.o moduleCaseParam.o moduleSolver.o moduleInject.o moduleBoundary.o moduleMesh.o moduleMeshCylRead.o moduleErrors.o moduleSpecies.o moduleInput.f95 +moduleInput.o: moduleParallel.o moduleRefParam.o moduleCaseParam.o moduleSolver.o moduleInject.o moduleBoundary.o moduleMesh.o moduleMeshCylRead.o moduleErrors.o moduleSpecies.o moduleInput.f95 $(FC) $(FCFLAGS) -c $(subst .o,.f95, $@) -o $(OBJDIR)/$@ moduleInject.o: moduleSpecies.o moduleSolver.o moduleMesh.o moduleMeshCyl.o moduleInject.f95 diff --git a/src/modules/moduleInput.f95 b/src/modules/moduleInput.f95 index 79a9438..fe0d096 100644 --- a/src/modules/moduleInput.f95 +++ b/src/modules/moduleInput.f95 @@ -45,6 +45,9 @@ MODULE moduleInput !Read injection of particles CALL readInject(config) + !Read parallel parameters + CALL readParallel(config) + END SUBROUTINE readConfig !Reads the reference parameters @@ -325,9 +328,9 @@ MODULE moduleInput TYPE(json_file), INTENT(inout):: config INTEGER:: i - character(2):: istring - character(:), allocatable:: object - logical:: found + CHARACTER(2):: istring + CHARACTER(:), ALLOCATABLE:: object + LOGICAL:: found CHARACTER(:), ALLOCATABLE:: speciesName CHARACTER(:), ALLOCATABLE:: name REAL(8):: v @@ -366,4 +369,28 @@ MODULE moduleInput END SUBROUTINE readInject + SUBROUTINE readParallel(config) + USE moduleParallel + USE moduleErrors + USE json_module + IMPLICIT NONE + + TYPE(json_file), INTENT(inout):: config + CHARACTER(:), ALLOCATABLE:: object + LOGICAL:: found + + !Reads OpenMP parameters + object = 'parallel.OpenMP' + + CALL config%get(object // '.nThreads', openMP%nThreads, found) + + IF (.NOT. found) THEN + openMP%nthreads = 8 + CALL warningError('No OpenMP configuration detected, using 8 threads as default.') + + END IF + + END SUBROUTINE readParallel + + END MODULE moduleInput diff --git a/src/modules/moduleParallel.f95 b/src/modules/moduleParallel.f95 new file mode 100644 index 0000000..9c83385 --- /dev/null +++ b/src/modules/moduleParallel.f95 @@ -0,0 +1,10 @@ +MODULE moduleParallel + + TYPE openMP_type + INTEGER:: nThreads + + END TYPE + + TYPE(openMP_type):: openMP + +END MODULE moduleParallel