Migrate execution to GNU Parallel
GNU Parallel allows us to run several simulations at the same time and
resume the simulations in case the current run stops for some reason.
Thus, the MC-2.f90 code has been adapted to support running it via GNU
Parallel (passing the namefile via stdin), and a bash script which
replaces the previous dependenciaEn*.bash scripts has been created,
named runAll.bash.
Change-Id: I5cc8bd6fb5a176c73dd7372eb61b9eabc278c12b
diff --git a/quad10/fenomens/lab/p4/MC-2.f90 b/quad10/fenomens/lab/p4/MC-2.f90
index 48c6a11..9b8e78e 100644
--- a/quad10/fenomens/lab/p4/MC-2.f90
+++ b/quad10/fenomens/lab/p4/MC-2.f90
@@ -17,15 +17,10 @@
! Inicialitzem algunes variables sobre el problema
namelist /DADES/ L, NOM, TEMP, NSEED, SEED0, MCTOT, MCINI, MCD
- open(10, file="mc2.dat")
- read(10, DADES)
- close(10)
+ read(nml = DADES, unit = 5)
N = L*L
- ! Obrim el fitxer on escriurem els resultats a cada iteració
- open(unit = 12, file = "data_out/" // trim(NOM) // ".out")
-
! Cache dels valors de l'exponencial
do I = 0, 8
W(I) = (2**30 - 1 + 2**30)*exp(-float(I)/TEMP)
@@ -47,7 +42,6 @@
E = energ(S, L)
M = magne(S, L)
- !write (12, *) "0", E, M
! Iterem amb el mètode de Montecarlo
do IMC = 1, MCTOT
@@ -75,10 +69,9 @@
M = M + 2*S(I, J)
enddo
- if (mod(IMC, 10000) == 0) then
- print *, "Iter:", IMC, "Energia:", E, "Magn:", INT(M)
- endif
- !write (12, *) IMC, E, M
+ !if (mod(IMC, 10000) == 0) then
+ ! print *, "Iter:", IMC, "Energia:", E, "Magn:", INT(M)
+ !endif
if (IMC > MCINI .and. mod(IMC, MCD) == 0) then
SUMI = SUMI + 1
@@ -106,10 +99,9 @@
! Guardem a un fiter els promitjos
open(unit = 13, file = "data_out/" // trim(NOM) // ".res")
- !write(13, *) "L, T, <E>, <E**2>, Var(E), <M>, <M**2>, Var(M), C_V, CHI"
+ !write(13, *) "L, T, <E>, <E**2>, Var(E), <M>, <|M|>, <M**2>, Var(M), C_V, CHI"
write(13, *) L, TEMP, SUME, SUME2, VARE, SUMM, SUMAM, SUMM2, VARM, CV, CHI
! Tanquem els fitxers de sortida
- close(12)
close(13)
endprogram main
diff --git a/quad10/fenomens/lab/p4/Makefile b/quad10/fenomens/lab/p4/Makefile
index f02529f..e38dc46 100644
--- a/quad10/fenomens/lab/p4/Makefile
+++ b/quad10/fenomens/lab/p4/Makefile
@@ -20,4 +20,4 @@
$(FC) $(FC_FLAGS) -c pbc.f90
clean:
- rm -rf out data_out *.o
+ rm -rf out *.o
diff --git a/quad10/fenomens/lab/p4/README.md b/quad10/fenomens/lab/p4/README.md
index 9406d07..37bbe11 100644
--- a/quad10/fenomens/lab/p4/README.md
+++ b/quad10/fenomens/lab/p4/README.md
@@ -5,5 +5,4 @@
Per compilar, executeu `make all`. Els executables es trobaran a la carpeta `out`.
## Programes
-- `dependenciaEnT.bash`: genera gràfiques de la capacitat calorífica i la susceptibilitat magnètica en funció de la temperatura.
-- `dependenciaEnL.bash`: el mateix que el programa anterior, però a les gràfiques apareixen les corbes per Ls diferents.
+- `runAll.bash`: executa les simulacions per diferents valors de T i L, i guarda les dades finals a la carpeta `data_out/dep_en_L`.
diff --git a/quad10/fenomens/lab/p4/dependenciaEnL.bash b/quad10/fenomens/lab/p4/dependenciaEnL.bash
deleted file mode 100755
index 05badba..0000000
--- a/quad10/fenomens/lab/p4/dependenciaEnL.bash
+++ /dev/null
@@ -1,17 +0,0 @@
-#!/bin/bash
-l_list="8 16 32 64"
-out_folder="data_out/depEnL"
-
-rm -rf $out_folder
-mkdir -p $out_folder
-
-for l in $l_list; do
- echo "============================="
- echo "Executant per L = $l"
- echo "============================="
-
- ./dependenciaEnT.bash $l
- cp data_out/dep_en_T.dat "$out_folder/dep_en_T_L$l.dat"
-done
-
-./graphs/dependenciaEnL.gnu
diff --git a/quad10/fenomens/lab/p4/dependenciaEnT.bash b/quad10/fenomens/lab/p4/dependenciaEnT.bash
deleted file mode 100755
index e9f5a6a..0000000
--- a/quad10/fenomens/lab/p4/dependenciaEnT.bash
+++ /dev/null
@@ -1,34 +0,0 @@
-#!/bin/bash
-temps="1.8 2.0 2.15 2.25 2.3 2.35 2.45 2.6 3.0"
-out="data_out/dep_en_T.dat"
-out_partial="partial_dep_en_T"
-l=${1:-32}
-
-rm -f $out
-touch $out
-
-for temp in $temps; do
- echo "-----------------------------"
- echo "Executant per T = $temp"
- echo "-----------------------------"
-
- cat <<EOF > mc2.dat
-&DADES
-L=$l
-NOM="$out_partial",
-TEMP=$temp,
-NSEED=10,
-SEED0=117654,
-MCTOT=20000,
-MCINI=2000,
-MCD=20
-&END
-EOF
- ./out/mc2 $temp
- cat data_out/$out_partial.res >> $out
-done
-
-rm -f data_out/$out_partial.res
-rm -f data_out/$out_partial.out
-
-./graphs/dependenciaEnT.gnu
diff --git a/quad10/fenomens/lab/p4/drawGraphs.bash b/quad10/fenomens/lab/p4/drawGraphs.bash
new file mode 100755
index 0000000..9a55c5c
--- /dev/null
+++ b/quad10/fenomens/lab/p4/drawGraphs.bash
@@ -0,0 +1,21 @@
+#!/bin/bash
+cd data_out/dep_en_L
+LList="8 16 32 64"
+LFinalList=()
+
+mkdir -p tmpdata
+for L in $LList; do
+ if [ -d "$L" ]; then
+ (cd $L; cat *.res | sort -nk2 > "../tmpdata/$L.dat")
+ LFinalList+=("$L")
+ else
+ echo "Folder with L=$L doesn't exist, skipping."
+ fi
+done
+
+LFinalListString="${LFinalList[@]}"
+
+cd ../../
+mkdir -p data_out/dep_en_L_graphs
+./graphs/dependenciaEnL.gnu "$LFinalListString"
+rm -rf data_out/dep_en_L/tmpdata
diff --git a/quad10/fenomens/lab/p4/graphs/dependenciaEnL.gnu b/quad10/fenomens/lab/p4/graphs/dependenciaEnL.gnu
index b7d239b..ec68f46 100755
--- a/quad10/fenomens/lab/p4/graphs/dependenciaEnL.gnu
+++ b/quad10/fenomens/lab/p4/graphs/dependenciaEnL.gnu
@@ -1,15 +1,27 @@
#!/usr/bin/env -S gnuplot -c
-outputfile = 'data_out/dep_en_L' # Nom de la imatge resultant (sense extensió)
-datafilepre = 'data_out/depEnL/dep_en_T_L'
+outputfile = 'data_out/dep_en_L_graphs/' # Nom de la imatge resultant (sense extensió)
+datafilepre = 'data_out/dep_en_L/tmpdata/'
datafilepost = '.dat'
-LS="8 16 32 64"
+LS = ARG1
-set terminal svg dashed size 600, 1200 font "Computer Modern,Tinos,Helvetica,15"
-set output outputfile.'.svg'
-
-set multiplot layout 2,1
+set terminal svg dashed size 600, 600 font "Computer Modern,Tinos,Helvetica,15"
set title "Capacitat calorífica"
-plot for [L in LS] datafilepre . L . datafilepost using 2:10 with points title "L = ".L
+set output outputfile.'_capacitat_calorifica.svg'
+plot for [L in LS] datafilepre . L . datafilepost using 2:10 with linespoints title "L = ".L
+
set title "Susceptibilitat magnètica"
-plot for [L in LS] datafilepre . L . datafilepost using 2:11 with points title "L = ".L
+set output outputfile.'_susceptibilitat_magnetica.svg'
+plot for [L in LS] datafilepre . L . datafilepost using 2:11 with linespoints title "L = ".L
+
+set title "Energia"
+set output outputfile.'_energia.svg'
+set key bottom right
+plot for [L in LS] datafilepre . L . datafilepost using 2:($3/(L**2)) with linespoints title "<E>/N, L = ".L, \
+ for [L in LS] datafilepre . L . datafilepost using 2:(-sqrt($4)/(L**2)) with linespoints title "-sqrt(<E^2>)/N, L = ".L
+
+set title "Magnetització"
+set output outputfile.'_magnetitzacio.svg'
+set key top right
+plot for [L in LS] datafilepre . L . datafilepost using 2:($7/(L**2)) with linespoints title "<|M|>/N, L = ".L, \
+ for [L in LS] datafilepre . L . datafilepost using 2:(sqrt($8)/(L**2)) with linespoints title "sqrt(<M^2>)/N, L = ".L
diff --git a/quad10/fenomens/lab/p4/graphs/dependenciaEnT.gnu b/quad10/fenomens/lab/p4/graphs/dependenciaEnT.gnu
index 18a435a..ad65753 100755
--- a/quad10/fenomens/lab/p4/graphs/dependenciaEnT.gnu
+++ b/quad10/fenomens/lab/p4/graphs/dependenciaEnT.gnu
@@ -1,8 +1,6 @@
#!/usr/bin/env -S gnuplot -c
outputfile = 'data_out/dep_en_T' # Nom de la imatge resultant (sense extensió)
datafile = 'data_out/dep_en_T.dat'
-L=32
-TEMPS="1500 1800 2500 3500 4500"
set terminal svg dashed size 600, 1200 font "Computer Modern,Tinos,Helvetica,15"
set output outputfile.'.svg'
diff --git a/quad10/fenomens/lab/p4/run.bash b/quad10/fenomens/lab/p4/run.bash
new file mode 100755
index 0000000..73031d7
--- /dev/null
+++ b/quad10/fenomens/lab/p4/run.bash
@@ -0,0 +1,25 @@
+#!/bin/bash
+T="$1"
+L="$2"
+outFolder="dep_en_L/$L"
+outFilePrefix="${outFolder}/$T"
+
+if [ -f "data_out/${outFilePrefix}.res" ]; then
+ echo "Skipping computation for L=$L, T=$T (.res file already exists)"
+ exit 0
+fi
+
+echo "Starting computation for L=$L, T=$T"
+
+cat <<EOF | ./out/mc2
+&DADES
+L=$L,
+NOM="$outFilePrefix",
+TEMP=$T,
+NSEED=150,
+SEED0=117654,
+MCTOT=40000,
+MCINI=2000,
+MCD=20
+&END
+EOF
diff --git a/quad10/fenomens/lab/p4/runAll.bash b/quad10/fenomens/lab/p4/runAll.bash
new file mode 100755
index 0000000..e190a34
--- /dev/null
+++ b/quad10/fenomens/lab/p4/runAll.bash
@@ -0,0 +1,7 @@
+TList=$(seq 1.6 0.05 3.2)
+LList="8 16 32 64"
+for L in $LList; do
+ mkdir -p data_out/dep_en_L/$L
+done
+joblogFile="data_out/dep_en_L/joblog"
+parallel -P -1 --linebuffer --tag --joblog "$joblogFile" ./run.bash {1} {2} ::: $TList ::: $LList