Fix programs

This commit is contained in:
Cory Balaton 2023-12-05 15:30:07 +01:00
parent 5915b9ae2d
commit 43c02ad3fa
No known key found for this signature in database
GPG Key ID: 3E5FCEBFD80F432B
2 changed files with 37 additions and 13 deletions

View File

@ -2,7 +2,20 @@ from os import makedirs
from pathlib import Path from pathlib import Path
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import seaborn as sns
sns.set_theme()
params = {
"font.family": "Serif",
"font.serif": "Roman",
"text.usetex": True,
"axes.titlesize": "large",
"axes.labelsize": "large",
"xtick.labelsize": "large",
"ytick.labelsize": "large",
"legend.fontsize": "medium",
}
plt.rcParams.update(params)
def plot_timing(indir, outdir): def plot_timing(indir, outdir):
if not (path := Path(outdir)).exists(): if not (path := Path(outdir)).exists():
@ -22,16 +35,19 @@ def plot_timing(indir, outdir):
for file, label, xlabel, outfile in zip(files, labels, xlabels, outfiles): for file, label, xlabel, outfile in zip(files, labels, xlabels, outfiles):
figure1, ax1 = plt.subplots() figure1, ax1 = plt.subplots()
x = [] x = []
t = [] parallel = []
serial = []
with open(Path(indir, file)) as f: with open(Path(indir, file)) as f:
lines = f.readlines() lines = f.readlines()
for line in lines: for line in lines:
l = line.strip().split(",") l = line.strip().split(",")
x.append(float(l[0])) x.append(float(l[0]))
t.append(float(l[1])) parallel.append(float(l[1]))
serial.append(float(l[2]))
ax1.plot(x, t, label=label) ax1.plot(x, parallel, label="Parallel")
ax1.plot(x, serial, label="Serial")
ax1.set_xlabel(xlabel) ax1.set_xlabel(xlabel)
ax1.set_ylabel("time (seconds)") ax1.set_ylabel("time (seconds)")
@ -44,6 +60,6 @@ def plot_timing(indir, outdir):
if __name__ == "__main__": if __name__ == "__main__":
plot_timing( plot_timing(
"data/hp/timing/", "data/hp/timing",
"./latex/images/timing", "./latex/images/timing",
) )

View File

@ -21,21 +21,25 @@
* */ * */
void time_lattice_sizes() void time_lattice_sizes()
{ {
std::string outfile = "data/timing/lattice_sizes.txt"; std::string outfile = "data/hp/timing/lattice_sizes.txt";
std::ofstream ofile; std::ofstream ofile;
int lattice_sizes[] = {20, 40, 60, 80, 100}; int lattice_sizes[] = {20, 40, 60, 80, 100};
utils::mkpath(utils::dirname(outfile)); utils::mkpath(utils::dirname(outfile));
ofile.open(outfile); ofile.open(outfile);
double t0, t1; double t0, t1, t2;
for (int L : lattice_sizes) { for (int L : lattice_sizes) {
t0 = omp_get_wtime(); t0 = omp_get_wtime();
montecarlo::phase_transition(L, 2.1, 2.4, 40, 100000, montecarlo::phase_transition(L, 2.1, 2.4, 40, 20000,
montecarlo::mcmc_parallel, "/dev/null"); montecarlo::mcmc_parallel, "/dev/null", 0);
t1 = omp_get_wtime(); t1 = omp_get_wtime();
montecarlo::phase_transition(L, 2.1, 2.4, 40, 20000,
montecarlo::mcmc_serial, "/dev/null", 0);
t2 = omp_get_wtime();
ofile << utils::scientific_format(L) << ',' ofile << utils::scientific_format(L) << ','
<< utils::scientific_format(t1 - t0) << '\n'; << utils::scientific_format(t1 - t0) << ','
<< utils::scientific_format(t2 - t1) << '\n';
} }
ofile.close(); ofile.close();
} }
@ -44,21 +48,25 @@ void time_lattice_sizes()
* */ * */
void time_sample_sizes() void time_sample_sizes()
{ {
std::string outfile = "data/timing/sample_sizes.txt"; std::string outfile = "data/hp/timing/sample_sizes.txt";
std::ofstream ofile; std::ofstream ofile;
int sample_sizes[] = {1000, 10000, 100000}; int sample_sizes[] = {1000, 10000, 100000};
utils::mkpath(utils::dirname(outfile)); utils::mkpath(utils::dirname(outfile));
ofile.open(outfile); ofile.open(outfile);
double t0, t1; double t0, t1, t2;
for (int samples : sample_sizes) { for (int samples : sample_sizes) {
t0 = omp_get_wtime(); t0 = omp_get_wtime();
montecarlo::phase_transition(20, 2.1, 2.4, 40, samples, montecarlo::phase_transition(20, 2.1, 2.4, 40, samples,
montecarlo::mcmc_parallel, "/dev/null"); montecarlo::mcmc_parallel, "/dev/null", 0);
t1 = omp_get_wtime(); t1 = omp_get_wtime();
montecarlo::phase_transition(20, 2.1, 2.4, 40, samples,
montecarlo::mcmc_serial, "/dev/null", 0);
t2 = omp_get_wtime();
ofile << utils::scientific_format(samples) << ',' ofile << utils::scientific_format(samples) << ','
<< utils::scientific_format(t1 - t0) << '\n'; << utils::scientific_format(t1 - t0) << ','
<< utils::scientific_format(t2 - t1) << '\n';
} }
ofile.close(); ofile.close();
} }