Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
#include "data_type.hpp"
#include "monte_carlo.hpp"
#include "utils.hpp"
#include <csignal>
#include <cstdlib>
#include <iostream>
#include <omp.h>
void create_burn_in_time_data()
{
// Test burn-in time
monte_carlo_progression(1.0, 20, 20000,
"output/burn_in_time/unordered_1_0.txt");
monte_carlo_progression(1.0, 20, 20000, 1,
"output/burn_in_time/ordered_1_0.txt");
monte_carlo_progression(2.4, 20, 20000,
"output/burn_in_time/unordered_2_4.txt");
monte_carlo_progression(2.4, 20, 20000, 1,
"output/burn_in_time/ordered_2_4.txt");
}
void create_pd_estimate_data()
{
// Estimate pd
pd_estimate(1.0, 20, 1000000, "output/pd_estimate/estimate_1_0.txt");
pd_estimate(2.4, 20, 1000000, "output/pd_estimate/estimate_2_4.txt");
}
void test_parallel_speedup()
{
// Test the openmp speedup
data_t data;
double t0, t1, t2;
int tries = 5;
t0 = omp_get_wtime();
for (size_t i = 0; i < tries; i++)
monte_carlo_serial(20, 1.0, 10000);
t1 = omp_get_wtime();
for (size_t i = 0; i < tries; i++)
monte_carlo_parallel(20, 1.0, 10000);
t2 = omp_get_wtime();
std::cout << "Time serial : " << (t1 - t0) / tries << " seconds"
<< '\n';
std::cout << "Time parallel : " << (t2 - t1) / tries << " seconds"
<< '\n';
std::cout << "Speedup parallel: " << (t1 - t0) / (t2 - t1) << '\n';
}
void create_phase_transition_data()
{
double t0, t1;
t0 = omp_get_wtime();
// Phase transition
phase_transition(20, 2.1, 2.4, 40, monte_carlo_parallel,
"output/phase_transition/size_20.txt");
phase_transition(40, 2.1, 2.4, 40, monte_carlo_parallel,
"output/phase_transition/size_40.txt");
phase_transition(60, 2.1, 2.4, 40, monte_carlo_parallel,
"output/phase_transition/size_60.txt");
phase_transition(80, 2.1, 2.4, 40, monte_carlo_parallel,
"output/phase_transition/size_80.txt");
phase_transition(100, 2.1, 2.4, 40, monte_carlo_parallel,
"output/phase_transition/size_100.txt");
t1 = omp_get_wtime();
std::cout << "Time: " << t1 - t0 << std::endl;
}
int main(int argc, char **argv)
{
if (argc < 2) {
std::cout << "Need at least 1 argument, got " << argc - 1
<< " arguments." << std::endl;
abort();
}
int arg = atoi(argv[1]);
switch (arg) {
case 1:
create_burn_in_time_data();
break;
case 2:
create_pd_estimate_data();
break;
case 3:
test_parallel_speedup();
break;
case 4:
create_phase_transition_data();
break;
default:
std::cout << "Not a valid option!" << std::endl;
abort();
}
return 0;
}
data_t
Definition: data_type.hpp:18
data_type.hpp
Header for the data_t type.
monte_carlo.hpp
Functions for monte carlo simulations.
phase_transition
void phase_transition(int L, double start_T, double end_T, int points_T, std::function< data_t(int, double, int)> monte_carlo, std::string outfile)
Perform the MCMC algorithm using a range of temperatures.
Definition: monte_carlo.cpp:156
monte_carlo_serial
data_t monte_carlo_serial(int L, double T, int cycles)
Execute the Metropolis algorithm for a certain amount of Monte Carlo cycles.
Definition: monte_carlo.cpp:111
pd_estimate
void pd_estimate(double T, int L, int cycles, const std::string filename)
Estimate the probability distribution for the energy.
Definition: monte_carlo.cpp:85
monte_carlo_progression
void monte_carlo_progression(double T, int L, int cycles, const std::string filename)
Write the expected values for each Monte Carlo cycles to file.
Definition: monte_carlo.cpp:17
monte_carlo_parallel
data_t monte_carlo_parallel(int L, double T, int cycles)
Execute the Metropolis algorithm for a certain amount of Monte Carlo cycles in parallel.
Definition: monte_carlo.cpp:128
main
int main()
The main function.
Definition: test_suite.cpp:148
utils.hpp
Function prototypes and macros that are useful.