2 Dimensional Ising Model
Simulate the change in energy and magnetization in a ferro magnet
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1
12#include "data_type.hpp"
13#include "monte_carlo.hpp"
14#include "utils.hpp"
15
16#include <getopt.h>
17
22{
23 // Test burn-in time
24 montecarlo::progression(1.0, 20, 20000,
25 "./data/hp/burn_in_time/unordered_1_0.txt");
26 montecarlo::progression(1.0, 20, 20000, 1,
27 "./data/hp/burn_in_time/ordered_1_0.txt");
28 montecarlo::progression(2.4, 20, 20000,
29 "./data/hp/burn_in_time/unordered_2_4.txt");
30 montecarlo::progression(2.4, 20, 20000, 1,
31 "./data/hp/burn_in_time/ordered_2_4.txt");
32}
33
38{
39 // Estimate pd
40 montecarlo::pd_estimate(1.0, 20, 1000000,
41 "./data/hp/pd_estimate/estimate_1_0.txt");
42 montecarlo::pd_estimate(2.4, 20, 1000000,
43 "./data/hp/pd_estimate/estimate_2_4.txt");
44}
45
50{
51 montecarlo::phase_transition(
52 100, 2.1, 2.4, 40, 1e5, montecarlo::mcmc_serial,
53 "./data/hp/test_burn_in_time/burn_in.txt", 5000);
54 montecarlo::phase_transition(
55 100, 2.1, 2.4, 40, 1e5, montecarlo::mcmc_serial,
56 "./data/hp/test_burn_in_time/no_burn_in.txt", 0);
57}
58
61{
62 // Test the openmp speedup
63 data_t data;
64 double t0, t1, t2;
65 int tries = 5;
66 t0 = omp_get_wtime();
67 for (size_t i = 0; i < tries; i++)
68 montecarlo::mcmc_serial(20, 1.0, 10000);
69 t1 = omp_get_wtime();
70 for (size_t i = 0; i < tries; i++)
71 montecarlo::mcmc_parallel(20, 1.0, 10000);
72 t2 = omp_get_wtime();
73
74 std::cout << "Time serial : " << (t1 - t0) / tries << " seconds"
75 << '\n';
76 std::cout << "Time parallel : " << (t2 - t1) / tries << " seconds"
77 << '\n';
78 std::cout << "Speedup parallel: " << (t1 - t0) / (t2 - t1) << '\n';
79}
80
84{
85 double t0, t1;
86
87 t0 = omp_get_wtime();
88 // Phase transition
89 montecarlo::phase_transition(20, 2.1, 2.4, 40, 1e4,
90 montecarlo::mcmc_parallel,
91 "./data/hp/phase_transition/size_20.txt");
92 montecarlo::phase_transition(40, 2.1, 2.4, 40, 1e4,
93 montecarlo::mcmc_parallel,
94 "./data/hp/phase_transition/size_40.txt");
95 montecarlo::phase_transition(60, 2.1, 2.4, 40, 1e4,
96 montecarlo::mcmc_parallel,
97 "./data/hp/phase_transition/size_60.txt");
98 montecarlo::phase_transition(80, 2.1, 2.4, 40, 1e4,
99 montecarlo::mcmc_parallel,
100 "./data/hp/phase_transition/size_80.txt");
101 montecarlo::phase_transition(100, 2.1, 2.4, 40, 1e4,
102 montecarlo::mcmc_parallel,
103 "./data/hp/phase_transition/size_100.txt");
104 t1 = omp_get_wtime();
105
106 std::cout << "Time: " << t1 - t0 << std::endl;
107}
108
110void usage(std::string filename)
111{
112 std::cout << "Usage: " << filename << " OPTION ...\n"
113 << "At least one option should be used.\n\n"
114 << "\t[ -h | --help ]\n"
115 << "\t[ --all ]\n"
116 << "\t[ --create-burn-in-data ]\n"
117 << "\t[ --create-pd-estimate-data ]\n"
118 << "\t[ --create-phase-transition-data ]\n"
119 << "\t[ --test-parallel-speedup ]\n"
120 << "\t[ --test-burn-in-time ]\n";
121 exit(-1);
122}
123
125int main(int argc, char **argv)
126{
127 static struct option long_options[] = {
128 {"all", no_argument, 0, 0},
129 {"create-burn-in-data", no_argument, 0, 0},
130 {"create-pd-estimate-data", no_argument, 0, 0},
131 {"test-parallel-speedup", no_argument, 0, 0},
132 {"create-phase-transition-data", no_argument, 0, 0},
133 {"test-burn-in-time", no_argument, 0, 0},
134 {"help", no_argument, 0, 0}};
135
136 int option_index = -1;
137 int c;
138
139 while (true) {
140 c = getopt_long(argc, argv, "h", long_options, &option_index);
141
142 if (c == -1)
143 break;
144 else if (c == 'h')
145 usage(argv[0]);
146
147 switch (option_index) {
148 case 0:
154 break;
155 case 1:
157 break;
158 case 2:
160 break;
161 case 3:
163 break;
164 case 4:
166 break;
167 case 5:
169 break;
170 case 6: // Not a mistake. This just goes to the default.
171 default:
172 usage(argv[0]);
173 }
174 }
175
176 return 0;
177}
Type to use with the IsingModel class and montecarlo module.
Definition: data_type.hpp:19
Header for the data_t type.
void test_parallel_speedup()
Test how much Openmp speeds up.
Definition: main.cpp:60
void create_pd_estimate_data()
Create the data used to estimate the probability distribution for tempratures 1.0 and 2....
Definition: main.cpp:37
void create_burn_in_time_data()
Create the data for the burn-in time for temperatures 1.0 and 2.4 for both unordered and ordered init...
Definition: main.cpp:21
void test_burn_in_time()
Create data using the same parameters except one uses burn-in time, while the other doesn't.
Definition: main.cpp:49
void create_phase_transition_data()
Create data for studying phase transition.
Definition: main.cpp:83
void usage(std::string filename)
A function that displays how to use the program and quits.
Definition: main.cpp:110
Functions for Monte Carlo simulations.
int main()
The main function.
Definition: test_suite.cpp:110
Function prototypes and macros that are useful.