From 1913e04594d17960cd44b5e9c42167f561617048 Mon Sep 17 00:00:00 2001 From: Cory Date: Tue, 5 Dec 2023 19:22:22 +0100 Subject: [PATCH 1/2] Tidy up --- python_scripts/burn_in_time.py | 4 ---- python_scripts/timing.py | 7 ++----- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/python_scripts/burn_in_time.py b/python_scripts/burn_in_time.py index 9625565..2549ca0 100644 --- a/python_scripts/burn_in_time.py +++ b/python_scripts/burn_in_time.py @@ -17,8 +17,6 @@ plt.rcParams.update(params) def plot_1_0(): files = [ - # "data/hp/burn_in_time/unordered_1_0_1421110368.txt", - # "data/hp/burn_in_time/ordered_1_0_611577739.txt", "data/hp/burn_in_time/unordered_1_0.txt", "data/hp/burn_in_time/ordered_1_0.txt", ] @@ -65,8 +63,6 @@ def plot_1_0(): def plot_2_4(): files = [ - # "data/hp/burn_in_time/unordered_2_4_1212892317.txt", - # "data/hp/burn_in_time/ordered_2_4_2408603856.txt", "data/hp/burn_in_time/unordered_2_4.txt", "data/hp/burn_in_time/ordered_2_4.txt", ] diff --git a/python_scripts/timing.py b/python_scripts/timing.py index 190f7bb..5ab66ab 100644 --- a/python_scripts/timing.py +++ b/python_scripts/timing.py @@ -17,6 +17,7 @@ params = { } plt.rcParams.update(params) + def plot_timing(indir, outdir): if not (path := Path(outdir)).exists(): makedirs(path) @@ -25,14 +26,10 @@ def plot_timing(indir, outdir): "lattice_sizes.txt", "sample_sizes.txt", ] - labels = [ - "Lattice sizes", - "Sample sizes", - ] xlabels = ["Lattice size", "Sampling size"] outfiles = ["lattice_size.pdf", "sample_sizes.pdf"] - for file, label, xlabel, outfile in zip(files, labels, xlabels, outfiles): + for file, xlabel, outfile in zip(files, xlabels, outfiles): figure1, ax1 = plt.subplots() x = [] parallel = [] From a9369e027493afe102f58751a66a9cc91a4df65e Mon Sep 17 00:00:00 2001 From: Cory Date: Tue, 5 Dec 2023 19:26:29 +0100 Subject: [PATCH 2/2] Update docs --- docs/index.html | 14 +- docs/main_8cpp.html | 4 +- docs/main_8cpp_source.html | 38 +-- docs/mcmc__progression_8cpp_source.html | 103 +++--- docs/monte__carlo_8cpp.html | 10 +- docs/monte__carlo_8cpp_source.html | 330 +++++++++---------- docs/monte__carlo_8hpp.html | 10 +- docs/monte__carlo_8hpp_source.html | 12 +- docs/pd__estimate_8cpp_source.html | 2 +- docs/phase__transition_8cpp_source.html | 4 +- docs/phase__transition__mpi_8cpp_source.html | 2 +- docs/time_8cpp.html | 6 +- docs/time_8cpp_source.html | 193 +++++------ 13 files changed, 374 insertions(+), 354 deletions(-) diff --git a/docs/index.html b/docs/index.html index 9f3ba18..0685e27 100644 --- a/docs/index.html +++ b/docs/index.html @@ -114,7 +114,7 @@ Operating systems
  • MacOS
      -
    • Might work, but hasn't been tested
    • +
    • Will most likely not work due to the use of getopt, which is GNU specific.
  • Windows
      @@ -188,7 +188,17 @@ Running scripts Batch system

      For the phase_transition_mpi program, there are scripts in the **./slurm_scripts** directory that come along with it. This is to be able to run it on a batch system using Slurm if you have access to one. The only program that should be executed by the user is the **./slurm_scripts/execute.script** script. You can see how to use this script by doing:

      ./slurm_scripts/execute.script --help
      -

      This is the recommended way to use this program as it takes approximately 90 minutes to complete when using 8 processes where each process has 10 threads.

      +

      This is the recommended way of using the program. Here is a table using different parameters on the Fox cluster:

      + + + + + + + + + +
      Lattice size Samples Processes threads Time (seconds)
      20 1e7 10 10 133.735
      40 1e7 10 10 814.126
      60 1e7 10 10 2575.33

      If you happen to have such a system available to you, then you should clone this repo on that system, then compile the MPI program like this:

      make bin/phase_transition_mpi

      After compiling, you can schedule it by using the **./slurm_scripts/execute.script**:

      diff --git a/docs/main_8cpp.html b/docs/main_8cpp.html index a5e86df..6ac48da 100644 --- a/docs/main_8cpp.html +++ b/docs/main_8cpp.html @@ -119,7 +119,7 @@ Functions  Create the data for the burn-in time for temperatures 1.0 and 2.4 for both unordered and ordered initial states.
        void create_pd_estimate_data () - Create the data used to estimate the probability distribution for tempratures 1.0 anbd 2.4.
      + Create the data used to estimate the probability distribution for tempratures 1.0 and 2.4.
        void test_burn_in_time ()  Create data using the same parameters except one uses burn-in time, while the other doesn't.
      @@ -183,7 +183,7 @@ Janita Ovidie Sandtrøen Willumsen (janitaws)
      -

      Create the data used to estimate the probability distribution for tempratures 1.0 anbd 2.4.

      +

      Create the data used to estimate the probability distribution for tempratures 1.0 and 2.4.

      Definition at line 37 of file main.cpp.

      diff --git a/docs/main_8cpp_source.html b/docs/main_8cpp_source.html index 727245f..5ee72db 100644 --- a/docs/main_8cpp_source.html +++ b/docs/main_8cpp_source.html @@ -125,25 +125,25 @@ $(document).ready(function(){initNavTree('main_8cpp_source.html',''); initResiza
      22{
      23 // Test burn-in time
      24 montecarlo::progression(1.0, 20, 20000,
      -
      25 "../output/burn_in_time/unordered_1_0.txt");
      +
      25 "./data/hp/burn_in_time/unordered_1_0.txt");
      26 montecarlo::progression(1.0, 20, 20000, 1,
      -
      27 "../output/burn_in_time/ordered_1_0.txt");
      +
      27 "./data/hp/burn_in_time/ordered_1_0.txt");
      28 montecarlo::progression(2.4, 20, 20000,
      -
      29 "../output/burn_in_time/unordered_2_4.txt");
      +
      29 "./data/hp/burn_in_time/unordered_2_4.txt");
      30 montecarlo::progression(2.4, 20, 20000, 1,
      -
      31 "../output/burn_in_time/ordered_2_4.txt");
      +
      31 "./data/hp/burn_in_time/ordered_2_4.txt");
      32}
      33
      34/** @brief Create the data used to estimate the probability distribution
      -
      35 * for tempratures 1.0 anbd 2.4.
      +
      35 * for tempratures 1.0 and 2.4.
      36 * */
      38{
      39 // Estimate pd
      40 montecarlo::pd_estimate(1.0, 20, 1000000,
      -
      41 "../output/pd_estimate/estimate_1_0.txt");
      +
      41 "./data/hp/pd_estimate/estimate_1_0.txt");
      42 montecarlo::pd_estimate(2.4, 20, 1000000,
      -
      43 "../output/pd_estimate/estimate_2_4.txt");
      +
      43 "./data/hp/pd_estimate/estimate_2_4.txt");
      44}
      45
      46/** @brief Create data using the same parameters except one uses burn-in time,
      @@ -153,10 +153,10 @@ $(document).ready(function(){initNavTree('main_8cpp_source.html',''); initResiza
      50{
      51 montecarlo::phase_transition(
      52 100, 2.1, 2.4, 40, 1e5, montecarlo::mcmc_serial,
      -
      53 "../output/test_burn_in_time/burn_in.txt", 5000);
      +
      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 "../output/test_burn_in_time/no_burn_in.txt", 0);
      +
      56 "./data/hp/test_burn_in_time/no_burn_in.txt", 0);
      57}
      58
      59/** @brief Test how much Openmp speeds up.*/
      @@ -191,19 +191,19 @@ $(document).ready(function(){initNavTree('main_8cpp_source.html',''); initResiza
      88 // Phase transition
      89 montecarlo::phase_transition(20, 2.1, 2.4, 40, 1e4,
      90 montecarlo::mcmc_parallel,
      -
      91 "../output/phase_transition/size_20.txt");
      +
      91 "./data/hp/phase_transition/size_20.txt");
      92 montecarlo::phase_transition(40, 2.1, 2.4, 40, 1e4,
      93 montecarlo::mcmc_parallel,
      -
      94 "../output/phase_transition/size_40.txt");
      +
      94 "./data/hp/phase_transition/size_40.txt");
      95 montecarlo::phase_transition(60, 2.1, 2.4, 40, 1e4,
      96 montecarlo::mcmc_parallel,
      -
      97 "../output/phase_transition/size_60.txt");
      +
      97 "./data/hp/phase_transition/size_60.txt");
      98 montecarlo::phase_transition(80, 2.1, 2.4, 40, 1e4,
      99 montecarlo::mcmc_parallel,
      -
      100 "../output/phase_transition/size_80.txt");
      +
      100 "./data/hp/phase_transition/size_80.txt");
      101 montecarlo::phase_transition(100, 2.1, 2.4, 40, 1e4,
      102 montecarlo::mcmc_parallel,
      -
      103 "../output/phase_transition/size_100.txt");
      +
      103 "./data/hp/phase_transition/size_100.txt");
      104 t1 = omp_get_wtime();
      105
      106 std::cout << "Time: " << t1 - t0 << std::endl;
      @@ -281,15 +281,15 @@ $(document).ready(function(){initNavTree('main_8cpp_source.html',''); initResiza
      Type to use with the IsingModel class and montecarlo module.
      Definition: data_type.hpp:19
      void test_parallel_speedup()
      Test how much Openmp speeds up.
      Definition: main.cpp:60
      int main(int argc, char **argv)
      The main function.
      Definition: main.cpp:125
      -
      void create_pd_estimate_data()
      Create the data used to estimate the probability distribution for tempratures 1.0 anbd 2....
      Definition: main.cpp:37
      +
      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
      -
      void phase_transition(int L, double start_T, double end_T, int points_T, int cycles, std::function< data_t(int, double, int, int)> monte_carlo, std::string outfile, int burn_in_time=BURN_IN_TIME)
      Perform the MCMC algorithm using a range of temperatures.
      -
      data_t mcmc_parallel(int L, double T, int cycles, int burn_in_time=BURN_IN_TIME)
      Execute the Metropolis algorithm for a certain amount of Monte Carlo cycles in parallel.
      -
      data_t mcmc_serial(int L, double T, int cycles, int burn_in_time=BURN_IN_TIME)
      Execute the Metropolis algorithm for a certain amount of Monte Carlo cycles.
      -
      void pd_estimate(double T, int L, int cycles, const std::string filename, int burn_in_time=BURN_IN_TIME)
      Estimate the probability distribution for the energy.
      Definition: monte_carlo.cpp:91
      +
      void phase_transition(int L, double start_T, double end_T, int points_T, int cycles, std::function< data_t(int, double, int, int)> monte_carlo, std::string outfile, int burn_in_time=BURN_IN_TIME)
      Perform the MCMC algorithm using a range of temperatures.
      +
      data_t mcmc_parallel(int L, double T, int cycles, int burn_in_time=BURN_IN_TIME)
      Execute the Metropolis algorithm for a certain amount of Monte Carlo cycles in parallel.
      +
      data_t mcmc_serial(int L, double T, int cycles, int burn_in_time=BURN_IN_TIME)
      Execute the Metropolis algorithm for a certain amount of Monte Carlo cycles.
      +
      void pd_estimate(double T, int L, int cycles, const std::string filename, int burn_in_time=BURN_IN_TIME)
      Estimate the probability distribution for the energy.
      Definition: monte_carlo.cpp:77
      diff --git a/docs/mcmc__progression_8cpp_source.html b/docs/mcmc__progression_8cpp_source.html index 8ce6821..1c590ff 100644 --- a/docs/mcmc__progression_8cpp_source.html +++ b/docs/mcmc__progression_8cpp_source.html @@ -108,7 +108,7 @@ $(document).ready(function(){initNavTree('mcmc__progression_8cpp_source.html',''
      5 *
      6 * @version 1.0
      7 *
      -
      8 * @brief Execute the mcmc algorithm and write data to file after each
      +
      8 * @brief Execute the mcmc algorithm and write data to file after each
      9 * Monte Carlo cycle.
      10 *
      11 * @bug No known bugs
      @@ -135,52 +135,67 @@ $(document).ready(function(){initNavTree('mcmc__progression_8cpp_source.html',''
      32int main(int argc, char **argv)
      33{
      34 // Command options
      -
      35 struct option long_options[] = {{"help", 0, 0, 0}, {NULL, 0, NULL, 0}};
      -
      36
      -
      37 int option_index = -1;
      -
      38 int c;
      -
      39
      -
      40 while (true) {
      -
      41 c = getopt_long(argc, argv, "h", long_options, &option_index);
      -
      42
      -
      43 if (c == -1)
      -
      44 break;
      -
      45
      -
      46 switch (c) {
      -
      47 case 0:
      -
      48 switch (option_index) {
      -
      49 case 0: // Not a mistake. This just goes to the default.
      -
      50 default:
      -
      51 usage(argv[0]);
      -
      52 }
      -
      53 break;
      -
      54 case 'h':
      -
      55 default:
      -
      56 usage(argv[0]);
      -
      57 }
      -
      58 }
      -
      59 // Check that the number of arguments is at least 8.
      -
      60 if (argc < 6) {
      -
      61 usage(argv[0]);
      -
      62 }
      -
      63
      -
      64 // Timing variables
      -
      65 double t0, t1;
      -
      66 t0 = omp_get_wtime();
      -
      67
      -
      68 // Define/initialize variables
      -
      69 double temp = atoi(argv[1]);
      -
      70 int L = atoi(argv[2]), cycles = atoi(argv[3]), burn_in_time = atoi(argv[4]);
      -
      71 std::string outfile = argv[5];
      -
      72
      -
      73 montecarlo::progression(temp, L, cycles, outfile, burn_in_time);
      +
      35 struct option long_options[] = {
      +
      36 {"help", 0, 0, 0}, {NULL, 0, NULL, 0}};
      +
      37
      +
      38 int option_index = -1;
      +
      39 int c;
      +
      40
      +
      41 while (true) {
      +
      42 c = getopt_long(argc, argv, "h", long_options, &option_index);
      +
      43
      +
      44 if (c == -1)
      +
      45 break;
      +
      46
      +
      47 switch (c) {
      +
      48 case 0:
      +
      49 switch (option_index) {
      +
      50 case 0: // Not a mistake. This just goes to the default.
      +
      51 default:
      +
      52 usage(argv[0]);
      +
      53 }
      +
      54 break;
      +
      55 case 'h':
      +
      56 default:
      +
      57 usage(argv[0]);
      +
      58 }
      +
      59 }
      +
      60 // Check that the number of arguments is at least 6.
      +
      61 if (argc < 6) {
      +
      62 usage(argv[0]);
      +
      63 }
      +
      64
      +
      65 bool ordered = false;
      +
      66
      +
      67 if (argc == 7) {
      +
      68 ordered = true;
      +
      69 }
      +
      70
      +
      71 // Timing variables
      +
      72 double t0, t1;
      +
      73 t0 = omp_get_wtime();
      74
      -
      75 t1 = omp_get_wtime();
      -
      76
      -
      77 std::cout << "Time: " << t1 - t0 << " seconds\n";
      -
      78}
      +
      75 // Define/initialize variables
      +
      76 double temp = atoi(argv[1]);
      +
      77 int L = atoi(argv[2]), cycles = atoi(argv[3]), burn_in_time = atoi(argv[4]);
      +
      78 std::string outfile = argv[5];
      +
      79
      +
      80 if (ordered) {
      +
      81 DEBUG("Hello");
      +
      82 montecarlo::progression(temp, L, cycles, 1, outfile, burn_in_time);
      +
      83 }
      +
      84 else {
      +
      85 montecarlo::progression(temp, L, cycles, outfile, burn_in_time);
      +
      86 }
      +
      87
      +
      88 t1 = omp_get_wtime();
      +
      89
      +
      90 std::cout << "Time: " << t1 - t0 << " seconds\n";
      +
      91}
      int main(int argc, char **argv)
      The main function.
      Definition: main.cpp:125
      void usage(std::string filename)
      A function that displays how to use the program and quits.
      Definition: main.cpp:110
      +
      void progression(double T, int L, int cycles, int value, const std::string filename, int burn_in_time=BURN_IN_TIME)
      Write the expected values for each Monte Carlo cycles to file.
      Definition: monte_carlo.cpp:46
      +
      #define DEBUG(msg)
      Writes a debug message.
      Definition: utils.hpp:39
      diff --git a/docs/monte__carlo_8cpp.html b/docs/monte__carlo_8cpp.html index 4676787..730314e 100644 --- a/docs/monte__carlo_8cpp.html +++ b/docs/monte__carlo_8cpp.html @@ -191,7 +191,7 @@ Janita Ovidie Sandtrøen Willumsen (janitaws)
      Returns
      data_t
      -

      Definition at line 141 of file monte_carlo.cpp.

      +

      Definition at line 127 of file monte_carlo.cpp.

      @@ -245,7 +245,7 @@ Janita Ovidie Sandtrøen Willumsen (janitaws)
      Returns
      data_t
      -

      Definition at line 122 of file monte_carlo.cpp.

      +

      Definition at line 108 of file monte_carlo.cpp.

      @@ -305,7 +305,7 @@ Janita Ovidie Sandtrøen Willumsen (janitaws) -

      Definition at line 91 of file monte_carlo.cpp.

      +

      Definition at line 77 of file monte_carlo.cpp.

      @@ -385,7 +385,7 @@ Janita Ovidie Sandtrøen Willumsen (janitaws) -

      Definition at line 169 of file monte_carlo.cpp.

      +

      Definition at line 155 of file monte_carlo.cpp.

      @@ -512,7 +512,7 @@ Janita Ovidie Sandtrøen Willumsen (janitaws) -

      Definition at line 53 of file monte_carlo.cpp.

      +

      Definition at line 46 of file monte_carlo.cpp.

      diff --git a/docs/monte__carlo_8cpp_source.html b/docs/monte__carlo_8cpp_source.html index cf453d5..d035ff8 100644 --- a/docs/monte__carlo_8cpp_source.html +++ b/docs/monte__carlo_8cpp_source.html @@ -126,180 +126,166 @@ $(document).ready(function(){initNavTree('monte__carlo_8cpp_source.html',''); in
      23 std::string directory = utils::dirname(filename);
      24 std::ofstream ofile;
      25
      -
      26 // Create random engine using the mersenne twister
      -
      27 std::random_device rd;
      -
      28 uint32_t rd_sample = rd();
      -
      29 std::mt19937 engine(rd_sample);
      -
      30
      -
      31 std::cout << "Seed: " << rd_sample << std::endl;
      -
      32
      -
      33 IsingModel ising(L, T);
      -
      34
      -
      35 // Create path and open file
      -
      36 utils::mkpath(directory);
      -
      37 ofile.open(filename);
      -
      38
      -
      39 for (size_t i = 0; i < burn_in_time; i++) {
      -
      40 ising.Metropolis();
      -
      41 }
      -
      42
      -
      43 // Loop through cycles
      -
      44 for (size_t i = 1; i <= cycles; i++) {
      -
      45 data += ising.Metropolis();
      -
      46 tmp = data / (i * n_spins);
      -
      47 ofile << i << ',' << tmp.E << ',' << tmp.E2 << ',' << tmp.M << ','
      -
      48 << tmp.M2 << ',' << tmp.M_abs << '\n';
      -
      49 }
      -
      50 ofile.close();
      -
      51}
      +
      26 IsingModel ising(L, T);
      +
      27
      +
      28 // Create path and open file
      +
      29 utils::mkpath(directory);
      +
      30 ofile.open(filename);
      +
      31
      +
      32 for (size_t i = 0; i < burn_in_time; i++) {
      +
      33 ising.Metropolis();
      +
      34 }
      +
      35
      +
      36 // Loop through cycles
      +
      37 for (size_t i = 1; i <= cycles; i++) {
      +
      38 data += ising.Metropolis();
      +
      39 tmp = data / (i * n_spins);
      +
      40 ofile << i << ',' << tmp.E << ',' << tmp.E2 << ',' << tmp.M << ','
      +
      41 << tmp.M2 << ',' << tmp.M_abs << '\n';
      +
      42 }
      +
      43 ofile.close();
      +
      44}
      +
      45
      +
      46void progression(double T, int L, int cycles, int value,
      +
      47 const std::string filename, int burn_in_time)
      +
      48{
      +
      49 // Set some variables
      +
      50 data_t data, tmp;
      +
      51 int n_spins = L * L;
      52
      -
      53void progression(double T, int L, int cycles, int value,
      -
      54 const std::string filename, int burn_in_time)
      -
      55{
      -
      56 // Set some variables
      -
      57 data_t data, tmp;
      -
      58 int n_spins = L * L;
      -
      59
      -
      60 // File stuff
      -
      61 std::string directory = utils::dirname(filename);
      -
      62 std::ofstream ofile;
      -
      63
      -
      64 // Create random engine using the mersenne twister
      -
      65 std::random_device rd;
      -
      66 uint32_t rd_sample = rd();
      -
      67 std::mt19937 engine(rd());
      -
      68
      -
      69 std::cout << "Seed: " << rd_sample << std::endl;
      -
      70
      -
      71 IsingModel ising(L, T, value);
      -
      72
      -
      73 for (size_t i = 0; i < burn_in_time; i++) {
      -
      74 ising.Metropolis();
      -
      75 }
      +
      53 // File stuff
      +
      54 std::string directory = utils::dirname(filename);
      +
      55 std::ofstream ofile;
      +
      56
      +
      57 IsingModel ising(L, T, value);
      +
      58
      +
      59 for (size_t i = 0; i < burn_in_time; i++) {
      +
      60 ising.Metropolis();
      +
      61 }
      +
      62
      +
      63 // Create path and open file
      +
      64 utils::mkpath(directory);
      +
      65 ofile.open(filename);
      +
      66
      +
      67 // Loop through cycles
      +
      68 for (size_t i = 1; i <= cycles; i++) {
      +
      69 data += ising.Metropolis();
      +
      70 tmp = data / (i * n_spins);
      +
      71 ofile << i << ',' << tmp.E << ',' << tmp.E2 << ',' << tmp.M << ','
      +
      72 << tmp.M2 << ',' << tmp.M_abs << '\n';
      +
      73 }
      +
      74 ofile.close();
      +
      75}
      76
      -
      77 // Create path and open file
      -
      78 utils::mkpath(directory);
      -
      79 ofile.open(filename);
      -
      80
      -
      81 // Loop through cycles
      -
      82 for (size_t i = 1; i <= cycles; i++) {
      -
      83 data += ising.Metropolis();
      -
      84 tmp = data / (i * n_spins);
      -
      85 ofile << i << ',' << tmp.E << ',' << tmp.E2 << ',' << tmp.M << ','
      -
      86 << tmp.M2 << ',' << tmp.M_abs << '\n';
      -
      87 }
      -
      88 ofile.close();
      -
      89}
      -
      90
      -
      91void pd_estimate(double T, int L, int cycles, const std::string filename,
      -
      92 int burn_in_time)
      -
      93{
      -
      94 // Set some variables
      -
      95 data_t data, tmp;
      -
      96 int n_spins = L * L;
      +
      77void pd_estimate(double T, int L, int cycles, const std::string filename,
      +
      78 int burn_in_time)
      +
      79{
      +
      80 // Set some variables
      +
      81 data_t data, tmp;
      +
      82 int n_spins = L * L;
      +
      83
      +
      84 // File stuff
      +
      85 std::string directory = utils::dirname(filename);
      +
      86 std::ofstream ofile;
      +
      87
      +
      88 IsingModel ising(L, T);
      +
      89
      +
      90 for (size_t i = 0; i < burn_in_time; i++) {
      +
      91 ising.Metropolis();
      +
      92 }
      +
      93
      +
      94 // Create path and open file
      +
      95 utils::mkpath(directory);
      +
      96 ofile.open(filename);
      97
      -
      98 // File stuff
      -
      99 std::string directory = utils::dirname(filename);
      -
      100 std::ofstream ofile;
      -
      101
      -
      102 IsingModel ising(L, T);
      -
      103
      -
      104 for (size_t i = 0; i < burn_in_time; i++) {
      -
      105 ising.Metropolis();
      -
      106 }
      -
      107
      -
      108 // Create path and open file
      -
      109 utils::mkpath(directory);
      -
      110 ofile.open(filename);
      -
      111
      -
      112 // Loop through cycles
      -
      113 for (size_t i = 1; i <= cycles; i++) {
      -
      114 data = ising.Metropolis() / n_spins;
      -
      115 ofile << data.E << ',' << data.E2 << ',' << data.M << ',' << data.M2
      -
      116 << ',' << data.M_abs << '\n';
      -
      117 }
      -
      118 ofile.close();
      -
      119}
      -
      120
      -
      121// Code for seeing phase transitions.
      -
      122data_t mcmc_serial(int L, double T, int cycles, int burn_in_time)
      -
      123{
      -
      124 data_t data;
      -
      125 IsingModel model(L, T);
      +
      98 // Loop through cycles
      +
      99 for (size_t i = 1; i <= cycles; i++) {
      +
      100 data = ising.Metropolis() / n_spins;
      +
      101 ofile << data.E << ',' << data.E2 << ',' << data.M << ',' << data.M2
      +
      102 << ',' << data.M_abs << '\n';
      +
      103 }
      +
      104 ofile.close();
      +
      105}
      +
      106
      +
      107// Code for seeing phase transitions.
      +
      108data_t mcmc_serial(int L, double T, int cycles, int burn_in_time)
      +
      109{
      +
      110 data_t data;
      +
      111 IsingModel model(L, T);
      +
      112
      +
      113 for (size_t i = 0; i < burn_in_time; i++) {
      +
      114 model.Metropolis();
      +
      115 }
      +
      116
      +
      117 double E, M;
      +
      118 for (size_t i = 0; i < (uint)cycles; i++) {
      +
      119 data += model.Metropolis();
      +
      120 }
      +
      121
      +
      122 double norm = 1. / (double)cycles;
      +
      123
      +
      124 return data * norm;
      +
      125}
      126
      -
      127 for (size_t i = 0; i < burn_in_time; i++) {
      -
      128 model.Metropolis();
      -
      129 }
      -
      130
      -
      131 double E, M;
      -
      132 for (size_t i = 0; i < (uint)cycles; i++) {
      -
      133 data += model.Metropolis();
      -
      134 }
      -
      135
      -
      136 double norm = 1. / (double)cycles;
      -
      137
      -
      138 return data * norm;
      -
      139}
      +
      127data_t mcmc_parallel(int L, double T, int cycles, int burn_in_time)
      +
      128{
      +
      129 data_t data;
      +
      130#pragma omp parallel
      +
      131 {
      +
      132 // Each thread creates an instance of IsingModel.
      +
      133 IsingModel model(L, T);
      +
      134
      +
      135 // Each thread runs the Metropolis algorithm before starting to collect
      +
      136 // samples
      +
      137 for (size_t i = 0; i < burn_in_time; i++) {
      +
      138 model.Metropolis();
      +
      139 }
      140
      -
      141data_t mcmc_parallel(int L, double T, int cycles, int burn_in_time)
      -
      142{
      -
      143 data_t data;
      -
      144#pragma omp parallel
      -
      145 {
      -
      146 // Each thread creates an instance of IsingModel.
      -
      147 IsingModel model(L, T);
      -
      148
      -
      149 // Each thread runs the Metropolis algorithm before starting to collect
      -
      150 // samples
      -
      151 for (size_t i = 0; i < burn_in_time; i++) {
      -
      152 model.Metropolis();
      -
      153 }
      +
      141 // Now each thread work on one loop together, but using their own
      +
      142 // instances of things, but the total of cycles add up.
      +
      143 // static ensure that each thread gets the same amount of iterations
      +
      144#pragma omp for schedule(static) reduction(+ : data)
      +
      145 for (size_t i = 0; i < (uint)cycles; i++) {
      +
      146 data += model.Metropolis();
      +
      147 }
      +
      148 }
      +
      149
      +
      150 double norm = 1. / (double)cycles;
      +
      151
      +
      152 return data * norm;
      +
      153}
      154
      -
      155 // Now each thread work on one loop together, but using their own
      -
      156 // instances of things, but the total of cycles add up.
      -
      157 // static ensure that each thread gets the same amount of iterations
      -
      158#pragma omp for schedule(static) reduction(+ : data)
      -
      159 for (size_t i = 0; i < (uint)cycles; i++) {
      -
      160 data += model.Metropolis();
      -
      161 }
      -
      162 }
      -
      163
      -
      164 double norm = 1. / (double)cycles;
      -
      165
      -
      166 return data * norm;
      -
      167}
      -
      168
      -
      169void phase_transition(int L, double start, double end, int points, int cycles,
      -
      170 std::function<data_t(int, double, int, int)> monte_carlo,
      -
      171 std::string outfile, int burn_in_time)
      -
      172{
      -
      173 double dt = (end - start) / (double)points;
      -
      174 int N = L * L;
      -
      175 std::ofstream ofile;
      +
      155void phase_transition(int L, double start, double end, int points, int cycles,
      +
      156 std::function<data_t(int, double, int, int)> monte_carlo,
      +
      157 std::string outfile, int burn_in_time)
      +
      158{
      +
      159 double dt = (end - start) / (double)points;
      +
      160 int N = L * L;
      +
      161 std::ofstream ofile;
      +
      162
      +
      163 data_t data;
      +
      164
      +
      165 utils::mkpath(utils::dirname(outfile));
      +
      166 ofile.open(outfile);
      +
      167
      +
      168 double temp, CV, X, E_var, M_var;
      +
      169
      +
      170 using utils::scientific_format;
      +
      171 for (size_t i = 0; i < points; i++) {
      +
      172 temp = start + dt * i;
      +
      173 data = monte_carlo(L, temp, cycles, burn_in_time);
      +
      174 E_var = (data.E2 - data.E * data.E) / (double)N;
      +
      175 M_var = (data.M2 - data.M_abs * data.M_abs) / (double)N;
      176
      -
      177 data_t data;
      -
      178
      -
      179 utils::mkpath(utils::dirname(outfile));
      -
      180 ofile.open(outfile);
      -
      181
      -
      182 double temp, CV, X, E_var, M_var;
      -
      183
      -
      184 using utils::scientific_format;
      -
      185 for (size_t i = 0; i < points; i++) {
      -
      186 temp = start + dt * i;
      -
      187 data = monte_carlo(L, temp, cycles, burn_in_time);
      -
      188 E_var = (data.E2 - data.E * data.E) / (double)N;
      -
      189 M_var = (data.M2 - data.M_abs * data.M_abs) / (double)N;
      -
      190
      -
      191 ofile << scientific_format(temp) << ','
      -
      192 << scientific_format(data.E / (double)N) << ','
      -
      193 << scientific_format(data.M_abs / N) << ','
      -
      194 << scientific_format(E_var / (temp * temp)) << ','
      -
      195 << scientific_format(M_var / temp) << '\n';
      -
      196 }
      -
      197 ofile.close();
      -
      198}
      -
      199} // namespace montecarlo
      +
      177 ofile << scientific_format(temp) << ','
      +
      178 << scientific_format(data.E / (double)N) << ','
      +
      179 << scientific_format(data.M_abs / N) << ','
      +
      180 << scientific_format(E_var / (temp * temp)) << ','
      +
      181 << scientific_format(M_var / temp) << '\n';
      +
      182 }
      +
      183 ofile.close();
      +
      184}
      +
      185} // namespace montecarlo
      The Ising model in 2 dimensions.
      Definition: IsingModel.hpp:36
      IsingModel(int L, double T, int val)
      Constructor for the Ising model.
      Definition: IsingModel.cpp:31
      IsingModel(int L, double T)
      Constructor for the Ising model.
      Definition: IsingModel.cpp:19
      @@ -311,12 +297,12 @@ $(document).ready(function(){initNavTree('monte__carlo_8cpp_source.html',''); in
      double M2
      Magnetization squared.
      Definition: data_type.hpp:24
      double E2
      Energy squared.
      Definition: data_type.hpp:23
      double M
      Magnetization.
      Definition: data_type.hpp:22
      -
      void progression(double T, int L, int cycles, int value, const std::string filename, int burn_in_time=BURN_IN_TIME)
      Write the expected values for each Monte Carlo cycles to file.
      Definition: monte_carlo.cpp:53
      -
      void phase_transition(int L, double start_T, double end_T, int points_T, int cycles, std::function< data_t(int, double, int, int)> monte_carlo, std::string outfile, int burn_in_time=BURN_IN_TIME)
      Perform the MCMC algorithm using a range of temperatures.
      +
      void progression(double T, int L, int cycles, int value, const std::string filename, int burn_in_time=BURN_IN_TIME)
      Write the expected values for each Monte Carlo cycles to file.
      Definition: monte_carlo.cpp:46
      +
      void phase_transition(int L, double start_T, double end_T, int points_T, int cycles, std::function< data_t(int, double, int, int)> monte_carlo, std::string outfile, int burn_in_time=BURN_IN_TIME)
      Perform the MCMC algorithm using a range of temperatures.
      void progression(double T, int L, int cycles, const std::string filename, int burn_in_time=BURN_IN_TIME)
      Write the expected values for each Monte Carlo cycles to file.
      Definition: monte_carlo.cpp:15
      -
      data_t mcmc_parallel(int L, double T, int cycles, int burn_in_time=BURN_IN_TIME)
      Execute the Metropolis algorithm for a certain amount of Monte Carlo cycles in parallel.
      -
      data_t mcmc_serial(int L, double T, int cycles, int burn_in_time=BURN_IN_TIME)
      Execute the Metropolis algorithm for a certain amount of Monte Carlo cycles.
      -
      void pd_estimate(double T, int L, int cycles, const std::string filename, int burn_in_time=BURN_IN_TIME)
      Estimate the probability distribution for the energy.
      Definition: monte_carlo.cpp:91
      +
      data_t mcmc_parallel(int L, double T, int cycles, int burn_in_time=BURN_IN_TIME)
      Execute the Metropolis algorithm for a certain amount of Monte Carlo cycles in parallel.
      +
      data_t mcmc_serial(int L, double T, int cycles, int burn_in_time=BURN_IN_TIME)
      Execute the Metropolis algorithm for a certain amount of Monte Carlo cycles.
      +
      void pd_estimate(double T, int L, int cycles, const std::string filename, int burn_in_time=BURN_IN_TIME)
      Estimate the probability distribution for the energy.
      Definition: monte_carlo.cpp:77
      bool mkpath(std::string path, int mode=0777)
      Make path given.
      Definition: utils.cpp:32
      std::string scientific_format(double d, int width=20, int prec=10)
      Turns a double into a string written in scientific format.
      Definition: utils.cpp:16
      std::string dirname(const std::string &path)
      Get the directory name of the path.
      Definition: utils.cpp:58
      diff --git a/docs/monte__carlo_8hpp.html b/docs/monte__carlo_8hpp.html index 8810cbd..35dc9f4 100644 --- a/docs/monte__carlo_8hpp.html +++ b/docs/monte__carlo_8hpp.html @@ -219,7 +219,7 @@ Janita Ovidie Sandtrøen Willumsen (janitaws)
      Returns
      data_t
      -

      Definition at line 141 of file monte_carlo.cpp.

      +

      Definition at line 127 of file monte_carlo.cpp.

      @@ -273,7 +273,7 @@ Janita Ovidie Sandtrøen Willumsen (janitaws)
      Returns
      data_t
      -

      Definition at line 122 of file monte_carlo.cpp.

      +

      Definition at line 108 of file monte_carlo.cpp.

      @@ -333,7 +333,7 @@ Janita Ovidie Sandtrøen Willumsen (janitaws) -

      Definition at line 91 of file monte_carlo.cpp.

      +

      Definition at line 77 of file monte_carlo.cpp.

      @@ -413,7 +413,7 @@ Janita Ovidie Sandtrøen Willumsen (janitaws) -

      Definition at line 169 of file monte_carlo.cpp.

      +

      Definition at line 155 of file monte_carlo.cpp.

      @@ -540,7 +540,7 @@ Janita Ovidie Sandtrøen Willumsen (janitaws) -

      Definition at line 53 of file monte_carlo.cpp.

      +

      Definition at line 46 of file monte_carlo.cpp.

      diff --git a/docs/monte__carlo_8hpp_source.html b/docs/monte__carlo_8hpp_source.html index b04f385..2f04bf6 100644 --- a/docs/monte__carlo_8hpp_source.html +++ b/docs/monte__carlo_8hpp_source.html @@ -207,18 +207,18 @@ $(document).ready(function(){initNavTree('monte__carlo_8hpp_source.html',''); in
      Type to use with the IsingModel class and montecarlo module.
      Definition: data_type.hpp:19
      void test_parallel_speedup()
      Test how much Openmp speeds up.
      Definition: main.cpp:60
      int main(int argc, char **argv)
      The main function.
      Definition: main.cpp:125
      -
      void create_pd_estimate_data()
      Create the data used to estimate the probability distribution for tempratures 1.0 anbd 2....
      Definition: main.cpp:37
      +
      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
      -
      void progression(double T, int L, int cycles, int value, const std::string filename, int burn_in_time=BURN_IN_TIME)
      Write the expected values for each Monte Carlo cycles to file.
      Definition: monte_carlo.cpp:53
      -
      void phase_transition(int L, double start_T, double end_T, int points_T, int cycles, std::function< data_t(int, double, int, int)> monte_carlo, std::string outfile, int burn_in_time=BURN_IN_TIME)
      Perform the MCMC algorithm using a range of temperatures.
      +
      void progression(double T, int L, int cycles, int value, const std::string filename, int burn_in_time=BURN_IN_TIME)
      Write the expected values for each Monte Carlo cycles to file.
      Definition: monte_carlo.cpp:46
      +
      void phase_transition(int L, double start_T, double end_T, int points_T, int cycles, std::function< data_t(int, double, int, int)> monte_carlo, std::string outfile, int burn_in_time=BURN_IN_TIME)
      Perform the MCMC algorithm using a range of temperatures.
      #define BURN_IN_TIME
      Definition: monte_carlo.hpp:24
      void progression(double T, int L, int cycles, const std::string filename, int burn_in_time=BURN_IN_TIME)
      Write the expected values for each Monte Carlo cycles to file.
      Definition: monte_carlo.cpp:15
      -
      data_t mcmc_parallel(int L, double T, int cycles, int burn_in_time=BURN_IN_TIME)
      Execute the Metropolis algorithm for a certain amount of Monte Carlo cycles in parallel.
      -
      data_t mcmc_serial(int L, double T, int cycles, int burn_in_time=BURN_IN_TIME)
      Execute the Metropolis algorithm for a certain amount of Monte Carlo cycles.
      -
      void pd_estimate(double T, int L, int cycles, const std::string filename, int burn_in_time=BURN_IN_TIME)
      Estimate the probability distribution for the energy.
      Definition: monte_carlo.cpp:91
      +
      data_t mcmc_parallel(int L, double T, int cycles, int burn_in_time=BURN_IN_TIME)
      Execute the Metropolis algorithm for a certain amount of Monte Carlo cycles in parallel.
      +
      data_t mcmc_serial(int L, double T, int cycles, int burn_in_time=BURN_IN_TIME)
      Execute the Metropolis algorithm for a certain amount of Monte Carlo cycles.
      +
      void pd_estimate(double T, int L, int cycles, const std::string filename, int burn_in_time=BURN_IN_TIME)
      Estimate the probability distribution for the energy.
      Definition: monte_carlo.cpp:77
      diff --git a/docs/pd__estimate_8cpp_source.html b/docs/pd__estimate_8cpp_source.html index 7885bae..678da62 100644 --- a/docs/pd__estimate_8cpp_source.html +++ b/docs/pd__estimate_8cpp_source.html @@ -183,7 +183,7 @@ $(document).ready(function(){initNavTree('pd__estimate_8cpp_source.html',''); in
      80}
      int main(int argc, char **argv)
      The main function.
      Definition: main.cpp:125
      void usage(std::string filename)
      A function that displays how to use the program and quits.
      Definition: main.cpp:110
      -
      void pd_estimate(double T, int L, int cycles, const std::string filename, int burn_in_time=BURN_IN_TIME)
      Estimate the probability distribution for the energy.
      Definition: monte_carlo.cpp:91
      +
      void pd_estimate(double T, int L, int cycles, const std::string filename, int burn_in_time=BURN_IN_TIME)
      Estimate the probability distribution for the energy.
      Definition: monte_carlo.cpp:77
      diff --git a/docs/phase__transition_8cpp_source.html b/docs/phase__transition_8cpp_source.html index c233f9f..1259f10 100644 --- a/docs/phase__transition_8cpp_source.html +++ b/docs/phase__transition_8cpp_source.html @@ -186,8 +186,8 @@ $(document).ready(function(){initNavTree('phase__transition_8cpp_source.html',''
      83}
      int main(int argc, char **argv)
      The main function.
      Definition: main.cpp:125
      void usage(std::string filename)
      A function that displays how to use the program and quits.
      Definition: main.cpp:110
      -
      void phase_transition(int L, double start_T, double end_T, int points_T, int cycles, std::function< data_t(int, double, int, int)> monte_carlo, std::string outfile, int burn_in_time=BURN_IN_TIME)
      Perform the MCMC algorithm using a range of temperatures.
      -
      data_t mcmc_parallel(int L, double T, int cycles, int burn_in_time=BURN_IN_TIME)
      Execute the Metropolis algorithm for a certain amount of Monte Carlo cycles in parallel.
      +
      void phase_transition(int L, double start_T, double end_T, int points_T, int cycles, std::function< data_t(int, double, int, int)> monte_carlo, std::string outfile, int burn_in_time=BURN_IN_TIME)
      Perform the MCMC algorithm using a range of temperatures.
      +
      data_t mcmc_parallel(int L, double T, int cycles, int burn_in_time=BURN_IN_TIME)
      Execute the Metropolis algorithm for a certain amount of Monte Carlo cycles in parallel.
      diff --git a/docs/phase__transition__mpi_8cpp_source.html b/docs/phase__transition__mpi_8cpp_source.html index f608f12..0a1787b 100644 --- a/docs/phase__transition__mpi_8cpp_source.html +++ b/docs/phase__transition__mpi_8cpp_source.html @@ -279,7 +279,7 @@ $(document).ready(function(){initNavTree('phase__transition__mpi_8cpp_source.htm
      Type to use with the IsingModel class and montecarlo module.
      Definition: data_type.hpp:19
      int main(int argc, char **argv)
      The main function.
      Definition: main.cpp:125
      void usage(std::string filename)
      A function that displays how to use the program and quits.
      Definition: main.cpp:110
      -
      data_t mcmc_parallel(int L, double T, int cycles, int burn_in_time=BURN_IN_TIME)
      Execute the Metropolis algorithm for a certain amount of Monte Carlo cycles in parallel.
      +
      data_t mcmc_parallel(int L, double T, int cycles, int burn_in_time=BURN_IN_TIME)
      Execute the Metropolis algorithm for a certain amount of Monte Carlo cycles in parallel.
      bool mkpath(std::string path, int mode=0777)
      Make path given.
      Definition: utils.cpp:32
      std::string scientific_format(double d, int width=20, int prec=10)
      Turns a double into a string written in scientific format.
      Definition: utils.cpp:16
      std::string dirname(const std::string &path)
      Get the directory name of the path.
      Definition: utils.cpp:58
      diff --git a/docs/time_8cpp.html b/docs/time_8cpp.html index 809c11e..2aaa24c 100644 --- a/docs/time_8cpp.html +++ b/docs/time_8cpp.html @@ -168,7 +168,7 @@ Janita Ovidie Sandtrøen Willumsen (janitaws)

      The main function.

      -

      Definition at line 79 of file time.cpp.

      +

      Definition at line 87 of file time.cpp.

      @@ -210,7 +210,7 @@ Janita Ovidie Sandtrøen Willumsen (janitaws)

      Time phase transition using different sample sizes.

      -

      Definition at line 45 of file time.cpp.

      +

      Definition at line 49 of file time.cpp.

      @@ -232,7 +232,7 @@ Janita Ovidie Sandtrøen Willumsen (janitaws)

      A function that displays how to use the program and quits.

      -

      Definition at line 67 of file time.cpp.

      +

      Definition at line 75 of file time.cpp.

      diff --git a/docs/time_8cpp_source.html b/docs/time_8cpp_source.html index b4559b7..19b3f8a 100644 --- a/docs/time_8cpp_source.html +++ b/docs/time_8cpp_source.html @@ -124,110 +124,119 @@ $(document).ready(function(){initNavTree('time_8cpp_source.html',''); initResiza
      21 * */
      23{
      -
      24 std::string outfile = "data/timing/lattice_sizes.txt";
      +
      24 std::string outfile = "data/hp/timing/lattice_sizes.txt";
      25 std::ofstream ofile;
      26
      27 int lattice_sizes[] = {20, 40, 60, 80, 100};
      28
      29 utils::mkpath(utils::dirname(outfile));
      30 ofile.open(outfile);
      -
      31 double t0, t1;
      +
      31 double t0, t1, t2;
      32 for (int L : lattice_sizes) {
      33 t0 = omp_get_wtime();
      -
      34 montecarlo::phase_transition(L, 2.1, 2.4, 40, 100000,
      -
      35 montecarlo::mcmc_parallel, "/dev/null");
      +
      34 montecarlo::phase_transition(L, 2.1, 2.4, 40, 20000,
      +
      35 montecarlo::mcmc_parallel, "/dev/null", 0);
      36 t1 = omp_get_wtime();
      -
      37 ofile << utils::scientific_format(L) << ','
      -
      38 << utils::scientific_format(t1 - t0) << '\n';
      -
      39 }
      -
      40 ofile.close();
      -
      41}
      -
      42
      -
      43/** @brief Time phase transition using different sample sizes.
      -
      44 * */
      - -
      46{
      -
      47 std::string outfile = "data/timing/sample_sizes.txt";
      -
      48 std::ofstream ofile;
      -
      49
      -
      50 int sample_sizes[] = {1000, 10000, 100000};
      -
      51
      -
      52 utils::mkpath(utils::dirname(outfile));
      -
      53 ofile.open(outfile);
      -
      54 double t0, t1;
      -
      55 for (int samples : sample_sizes) {
      -
      56 t0 = omp_get_wtime();
      -
      57 montecarlo::phase_transition(20, 2.1, 2.4, 40, samples,
      -
      58 montecarlo::mcmc_parallel, "/dev/null");
      -
      59 t1 = omp_get_wtime();
      -
      60 ofile << utils::scientific_format(samples) << ','
      -
      61 << utils::scientific_format(t1 - t0) << '\n';
      -
      62 }
      -
      63 ofile.close();
      -
      64}
      -
      65
      -
      66/** @brief A function that displays how to use the program and quits.*/
      -
      67void usage(std::string filename)
      -
      68{
      -
      69 std::cout << "Usage: " << filename << " OPTION ...\n"
      -
      70 << "At least one option should be used.\n\n"
      -
      71 << "\t[ -h | --help ]\n"
      -
      72 << "\t[ --all ]\n"
      -
      73 << "\t[ --time-lattice-sizes ]\n"
      -
      74 << "\t[ --time-sample-sizes ]\n";
      -
      75 exit(-1);
      -
      76}
      -
      77
      -
      78/** @brief The main function.*/
      -
      79int main(int argc, char **argv)
      -
      80{
      -
      81 struct option long_options[] = {{"all", 0, 0, 0},
      -
      82 {"time-lattice-sizes", 0, 0, 0},
      -
      83 {"time-sample-sizes", 0, 0, 0},
      -
      84 {"help", 0, 0, 0},
      -
      85 {NULL, 0, NULL, 0}};
      -
      86
      -
      87 int option_index = -1;
      -
      88 int c;
      -
      89
      -
      90 while (true) {
      -
      91 c = getopt_long(argc, argv, "h", long_options, &option_index);
      -
      92
      -
      93 if (c == -1)
      -
      94 break;
      -
      95
      -
      96 switch (c) {
      -
      97 case 0:
      -
      98 switch (option_index) {
      -
      99 case 0:
      - - -
      102 break;
      -
      103 case 1:
      - -
      105 break;
      -
      106 case 2:
      - -
      108 break;
      -
      109 case 3: // Not a mistake. This just goes to the default.
      -
      110 default:
      -
      111 usage(argv[0]);
      -
      112 }
      -
      113 break;
      -
      114 case 'h':
      -
      115 default:
      -
      116 usage(argv[0]);
      -
      117 }
      -
      118 }
      -
      119
      -
      120 return 0;
      -
      121}
      +
      37 montecarlo::phase_transition(L, 2.1, 2.4, 40, 20000,
      +
      38 montecarlo::mcmc_serial, "/dev/null", 0);
      +
      39 t2 = omp_get_wtime();
      +
      40 ofile << utils::scientific_format(L) << ','
      +
      41 << utils::scientific_format(t1 - t0) << ','
      +
      42 << utils::scientific_format(t2 - t1) << '\n';
      +
      43 }
      +
      44 ofile.close();
      +
      45}
      +
      46
      +
      47/** @brief Time phase transition using different sample sizes.
      +
      48 * */
      + +
      50{
      +
      51 std::string outfile = "data/hp/timing/sample_sizes.txt";
      +
      52 std::ofstream ofile;
      +
      53
      +
      54 int sample_sizes[] = {1000, 10000, 100000};
      +
      55
      +
      56 utils::mkpath(utils::dirname(outfile));
      +
      57 ofile.open(outfile);
      +
      58 double t0, t1, t2;
      +
      59 for (int samples : sample_sizes) {
      +
      60 t0 = omp_get_wtime();
      +
      61 montecarlo::phase_transition(20, 2.1, 2.4, 40, samples,
      +
      62 montecarlo::mcmc_parallel, "/dev/null", 0);
      +
      63 t1 = omp_get_wtime();
      +
      64 montecarlo::phase_transition(20, 2.1, 2.4, 40, samples,
      +
      65 montecarlo::mcmc_serial, "/dev/null", 0);
      +
      66 t2 = omp_get_wtime();
      +
      67 ofile << utils::scientific_format(samples) << ','
      +
      68 << utils::scientific_format(t1 - t0) << ','
      +
      69 << utils::scientific_format(t2 - t1) << '\n';
      +
      70 }
      +
      71 ofile.close();
      +
      72}
      +
      73
      +
      74/** @brief A function that displays how to use the program and quits.*/
      +
      75void usage(std::string filename)
      +
      76{
      +
      77 std::cout << "Usage: " << filename << " OPTION ...\n"
      +
      78 << "At least one option should be used.\n\n"
      +
      79 << "\t[ -h | --help ]\n"
      +
      80 << "\t[ --all ]\n"
      +
      81 << "\t[ --time-lattice-sizes ]\n"
      +
      82 << "\t[ --time-sample-sizes ]\n";
      +
      83 exit(-1);
      +
      84}
      +
      85
      +
      86/** @brief The main function.*/
      +
      87int main(int argc, char **argv)
      +
      88{
      +
      89 struct option long_options[] = {{"all", 0, 0, 0},
      +
      90 {"time-lattice-sizes", 0, 0, 0},
      +
      91 {"time-sample-sizes", 0, 0, 0},
      +
      92 {"help", 0, 0, 0},
      +
      93 {NULL, 0, NULL, 0}};
      +
      94
      +
      95 int option_index = -1;
      +
      96 int c;
      +
      97
      +
      98 while (true) {
      +
      99 c = getopt_long(argc, argv, "h", long_options, &option_index);
      +
      100
      +
      101 if (c == -1)
      +
      102 break;
      +
      103
      +
      104 switch (c) {
      +
      105 case 0:
      +
      106 switch (option_index) {
      +
      107 case 0:
      + + +
      110 break;
      +
      111 case 1:
      + +
      113 break;
      +
      114 case 2:
      + +
      116 break;
      +
      117 case 3: // Not a mistake. This just goes to the default.
      +
      118 default:
      +
      119 usage(argv[0]);
      +
      120 }
      +
      121 break;
      +
      122 case 'h':
      +
      123 default:
      +
      124 usage(argv[0]);
      +
      125 }
      +
      126 }
      +
      127
      +
      128 return 0;
      +
      129}
      int main(int argc, char **argv)
      The main function.
      Definition: main.cpp:125
      void usage(std::string filename)
      A function that displays how to use the program and quits.
      Definition: main.cpp:110
      -
      void phase_transition(int L, double start_T, double end_T, int points_T, int cycles, std::function< data_t(int, double, int, int)> monte_carlo, std::string outfile, int burn_in_time=BURN_IN_TIME)
      Perform the MCMC algorithm using a range of temperatures.
      -
      data_t mcmc_parallel(int L, double T, int cycles, int burn_in_time=BURN_IN_TIME)
      Execute the Metropolis algorithm for a certain amount of Monte Carlo cycles in parallel.
      +
      void phase_transition(int L, double start_T, double end_T, int points_T, int cycles, std::function< data_t(int, double, int, int)> monte_carlo, std::string outfile, int burn_in_time=BURN_IN_TIME)
      Perform the MCMC algorithm using a range of temperatures.
      +
      data_t mcmc_parallel(int L, double T, int cycles, int burn_in_time=BURN_IN_TIME)
      Execute the Metropolis algorithm for a certain amount of Monte Carlo cycles in parallel.
      +
      data_t mcmc_serial(int L, double T, int cycles, int burn_in_time=BURN_IN_TIME)
      Execute the Metropolis algorithm for a certain amount of Monte Carlo cycles.
      void time_lattice_sizes()
      Time phase transition using different lattice sizes.
      Definition: time.cpp:22
      -
      void time_sample_sizes()
      Time phase transition using different sample sizes.
      Definition: time.cpp:45
      +
      void time_sample_sizes()
      Time phase transition using different sample sizes.
      Definition: time.cpp:49
      bool mkpath(std::string path, int mode=0777)
      Make path given.
      Definition: utils.cpp:32
      std::string scientific_format(double d, int width=20, int prec=10)
      Turns a double into a string written in scientific format.
      Definition: utils.cpp:16
      std::string dirname(const std::string &path)
      Get the directory name of the path.
      Definition: utils.cpp:58