Update documentation
This commit is contained in:
@@ -10,7 +10,6 @@
|
||||
* @bug No known bugs
|
||||
* */
|
||||
#include "IsingModel.hpp"
|
||||
#include <random>
|
||||
|
||||
IsingModel::IsingModel()
|
||||
{
|
||||
@@ -34,8 +33,7 @@ IsingModel::IsingModel(int L, double T, int val)
|
||||
this->L = L;
|
||||
this->T = T;
|
||||
this->initialize_engine();
|
||||
this->lattice.set_size(this->L, this->L);
|
||||
this->lattice.fill(val);
|
||||
this->initialize_lattice(val);
|
||||
this->initialize_neighbors();
|
||||
this->initialize_energy_diff();
|
||||
this->initialize_magnetization();
|
||||
@@ -58,6 +56,17 @@ void IsingModel::initialize_lattice()
|
||||
this->lattice(i) = 2 * coin_flip(this->engine) - 1;
|
||||
}
|
||||
|
||||
void IsingModel::initialize_lattice(int val)
|
||||
{
|
||||
// If val is neither 1 or -1, then initialize random values.
|
||||
if (val != 1 && val != -1) {
|
||||
this->initialize_lattice();
|
||||
return;
|
||||
}
|
||||
this->lattice.set_size(this->L, this->L);
|
||||
this->lattice.fill(val);
|
||||
}
|
||||
|
||||
void IsingModel::initialize_neighbors()
|
||||
{
|
||||
this->neighbors.set_size(this->L, 2);
|
||||
@@ -133,13 +142,3 @@ data_t IsingModel::Metropolis()
|
||||
return data_t((double)this->E, (double)(this->E * this->E), (double)this->M,
|
||||
(double)(this->M * this->M), std::fabs((double)this->M));
|
||||
}
|
||||
|
||||
int IsingModel::get_E()
|
||||
{
|
||||
return this->E;
|
||||
}
|
||||
|
||||
int IsingModel::get_M()
|
||||
{
|
||||
return this->M;
|
||||
}
|
||||
|
||||
66
src/Makefile
66
src/Makefile
@@ -1,66 +0,0 @@
|
||||
#CC=g++
|
||||
CC=mpic++
|
||||
|
||||
LIBSRCS=utils.cpp testlib.cpp data_type.cpp
|
||||
LIBOBJS=$(LIBSRCS:.cpp=.o)
|
||||
LIBPROFOBJS=$(addprefix prof/, $(LIBOBJS))
|
||||
|
||||
CLASSSRCS=IsingModel.cpp monte_carlo.cpp
|
||||
CLASSOBJS=$(CLASSSRCS:.cpp=.o)
|
||||
CLASSPROFOBJS=$(addprefix prof/, $(CLASSOBJS))
|
||||
|
||||
INCLUDE=../include
|
||||
|
||||
CFLAGS=-Wall -larmadillo -std=c++11 -O3 -fomit-frame-pointer
|
||||
#CFLAGS=-Wall -larmadillo -lblas -llapack -std=c++11 -O3 -fomit-frame-pointer
|
||||
OPENMP=-fopenmp
|
||||
|
||||
# Add a debug flag when compiling (For the DEBUG macro in utils.hpp)
|
||||
DEBUG ?= 0
|
||||
ifeq ($(DEBUG), 1)
|
||||
DBGFLAG=-DDBG -g
|
||||
else
|
||||
DBGFLAG=
|
||||
endif
|
||||
|
||||
# Add profiling for serial code
|
||||
PROFILE ?= 0
|
||||
ifeq ($(PROFILE), 1)
|
||||
PROFFLAG=-pg -fno-inline-functions
|
||||
else
|
||||
PROFFLAG=
|
||||
endif
|
||||
|
||||
.PHONY: clean instrument
|
||||
|
||||
all: main phase_transition_mpi test_suite time
|
||||
#all: main
|
||||
|
||||
# Instrumentation using scorep for parallel analysis
|
||||
instrument: prof/phase_transition_mpi.o $(LIBPROFOBJS) $(CLASSPROFOBJS)
|
||||
scorep $(CC) $(LIBPROFOBJS) $(CLASSPROFOBJS) $< -o phase_transition_mpi_prof $(CFLAGS) $(DBGFLAG) $(PROFFLAG) -I$(INCLUDE) $(OPENMP)
|
||||
|
||||
# Rules for executables
|
||||
main: main.o $(LIBOBJS) $(CLASSOBJS)
|
||||
$(CC) $^ -o $@ $(CFLAGS) $(DBGFLAG) $(PROFFLAG) -I$(INCLUDE) $(OPENMP)
|
||||
|
||||
phase_transition_mpi: phase_transition_mpi.o $(LIBOBJS) $(CLASSOBJS)
|
||||
$(CC) $^ -o $@ $(CFLAGS) $(DBGFLAG) $(PROFFLAG) -I$(INCLUDE) $(OPENMP)
|
||||
|
||||
test_suite: test_suite.o $(LIBOBJS) $(CLASSOBJS)
|
||||
$(CC) $^ -o $@ $(CFLAGS) $(DBGFLAG) $(PROFFLAG) -I$(INCLUDE) $(OPENMP)
|
||||
|
||||
time: time.o $(LIBOBJS) $(CLASSOBJS)
|
||||
$(CC) $^ -o $@ $(CFLAGS) $(DBGFLAG) $(PROFFLAG) -I$(INCLUDE) $(OPENMP)
|
||||
|
||||
# Rule for object files
|
||||
%.o: %.cpp
|
||||
$(CC) -c $^ -o $@ $(CFLAGS) $(DBGFLAG) $(PROFFLAG) -I$(INCLUDE) $(OPENMP)
|
||||
|
||||
# Rule for instrumented object files
|
||||
prof/%.o: %.cpp
|
||||
scorep $(CC) -c $^ -o $@ $(CFLAGS) $(DBGFLAG) $(PROFFLAG) -I$(INCLUDE) $(OPENMP)
|
||||
|
||||
clean:
|
||||
find . -maxdepth 2 -name "*.o" -type f -delete
|
||||
rm test_suite main phase_transition_mpi phase_transition_mpi_prof time
|
||||
@@ -43,14 +43,17 @@ void create_pd_estimate_data()
|
||||
"../output/pd_estimate/estimate_2_4.txt");
|
||||
}
|
||||
|
||||
/** @brief Create data using the same parameters except one uses burn-in time,
|
||||
* while the other doesn't.
|
||||
* */
|
||||
void test_burn_in_time()
|
||||
{
|
||||
montecarlo::phase_transition(
|
||||
100, 2.1, 2.4, 40, 1e5, montecarlo::mcmc_serial,
|
||||
"../output/test_burn_in_time/no_burn_in.txt", 0);
|
||||
"../output/test_burn_in_time/burn_in.txt", 5000);
|
||||
montecarlo::phase_transition(
|
||||
100, 2.1, 2.4, 40, 1e5, montecarlo::mcmc_serial,
|
||||
"../output/test_burn_in_time/burn_in.txt", 5000);
|
||||
"../output/test_burn_in_time/no_burn_in.txt", 0);
|
||||
}
|
||||
|
||||
/** @brief Test how much Openmp speeds up.*/
|
||||
@@ -103,6 +106,7 @@ void create_phase_transition_data()
|
||||
std::cout << "Time: " << t1 - t0 << std::endl;
|
||||
}
|
||||
|
||||
/** @brief A function that displays how to use the program and quits.*/
|
||||
void usage(std::string filename)
|
||||
{
|
||||
std::cout << "Usage: " << filename << " OPTION ...\n"
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <omp.h>
|
||||
#include <string>
|
||||
|
||||
/** @brief A function that displays how to use the program and quits.*/
|
||||
void usage(std::string filename)
|
||||
{
|
||||
std::cout << "Usage: " << filename
|
||||
@@ -27,9 +28,7 @@ void usage(std::string filename)
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
/** @brief The main function
|
||||
*
|
||||
* */
|
||||
/** @brief The main function.*/
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
// Command options
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <omp.h>
|
||||
#include <string>
|
||||
|
||||
/** @brief A function that displays how to use the program and quits.*/
|
||||
void usage(std::string filename)
|
||||
{
|
||||
std::cout << "Usage: " << filename
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <omp.h>
|
||||
#include <string>
|
||||
|
||||
/** @brief A function that displays how to use the program and quits.*/
|
||||
void usage(std::string filename)
|
||||
{
|
||||
std::cout << "Usage: " << filename
|
||||
@@ -30,9 +31,7 @@ void usage(std::string filename)
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
/** @brief The main function
|
||||
*
|
||||
* */
|
||||
/** @brief The main function.*/
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
// Command options
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <mpi.h>
|
||||
#include <string>
|
||||
|
||||
/** @brief A function that displays how to use the program and quits.*/
|
||||
void usage(std::string filename)
|
||||
{
|
||||
std::cout
|
||||
@@ -33,9 +34,7 @@ void usage(std::string filename)
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
/** @brief The main function
|
||||
*
|
||||
* */
|
||||
/** @brief The main function.*/
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
// Command options
|
||||
|
||||
@@ -12,13 +12,21 @@
|
||||
#include "IsingModel.hpp"
|
||||
#include "testlib.hpp"
|
||||
|
||||
/** @brief The analytic expected energy for a \f$ 2 \times 2 \f$ lattice.
|
||||
* */
|
||||
#define EPS_2 (-2 * std::sinh(8.)) / (std::cosh(8.) + 3)
|
||||
|
||||
/** @brief The analytic expected magnetization for a \f$ 2 \times 2 \f$
|
||||
* lattice.
|
||||
* */
|
||||
#define MAG_2 (std::exp(8.) + 1) / (2 * (cosh(8.) + 3))
|
||||
|
||||
/** @brief The analytic heat capacity for a \f$ 2 \times 2 \f$ lattice.
|
||||
* */
|
||||
#define CV_2 \
|
||||
16 * (3 * std::cosh(8.) + 1) / ((std::cosh(8.) + 3) * (std::cosh(8.) + 3))
|
||||
|
||||
/** @brief The analytic susceptibility for a \f$ 2 \times 2 \f$ lattice.*/
|
||||
#define X_2 \
|
||||
(3 * std::exp(8.) + std::exp(-8.) + 3) \
|
||||
/ ((std::cosh(8.) + 3) * (std::cosh(8.) + 3))
|
||||
@@ -87,10 +95,10 @@ public:
|
||||
tmp = data / cycles;
|
||||
if (testlib::close_to(EPS_2, tmp.E / n_spins, tol)
|
||||
&& testlib::close_to(MAG_2, tmp.M_abs / n_spins, tol)
|
||||
&& testlib::close_to(CV_2, (tmp.E2 - tmp.E * tmp.E) / (T * T)
|
||||
/ n_spins, tol)
|
||||
&& testlib::close_to(X_2, (tmp.M2 - tmp.M_abs * tmp.M_abs) / T
|
||||
/ n_spins, tol)) {
|
||||
&& testlib::close_to(
|
||||
CV_2, (tmp.E2 - tmp.E * tmp.E) / (T * T) / n_spins, tol)
|
||||
&& testlib::close_to(
|
||||
X_2, (tmp.M2 - tmp.M_abs * tmp.M_abs) / T / n_spins, tol)) {
|
||||
return cycles;
|
||||
}
|
||||
}
|
||||
@@ -111,7 +119,7 @@ int main()
|
||||
int accepted_values = 0;
|
||||
|
||||
// Run through the test multiple times to get a better estimate.
|
||||
for (size_t i=0; i < iterations; i++) {
|
||||
for (size_t i = 0; i < iterations; i++) {
|
||||
tmp = test.test_2x2_lattice(1e-2, 1e5);
|
||||
if (tmp == 0) {
|
||||
continue;
|
||||
@@ -119,7 +127,7 @@ int main()
|
||||
accepted_values++;
|
||||
res += tmp;
|
||||
}
|
||||
|
||||
|
||||
std::cout << "Res: " << res / accepted_values << std::endl;
|
||||
|
||||
return 0;
|
||||
|
||||
12
src/time.cpp
12
src/time.cpp
@@ -5,7 +5,7 @@
|
||||
*
|
||||
* @version 0.1
|
||||
*
|
||||
* @brief Timing various things
|
||||
* @brief Timing various things.
|
||||
*
|
||||
* @bug No known bugs
|
||||
* */
|
||||
@@ -17,9 +17,11 @@
|
||||
#include <omp.h>
|
||||
#include <ostream>
|
||||
|
||||
/** @brief Time phase transition using different lattice sizes.
|
||||
* */
|
||||
void time_lattice_sizes()
|
||||
{
|
||||
std::string outfile = "output/timing/lattice_sizes.txt";
|
||||
std::string outfile = "data/timing/lattice_sizes.txt";
|
||||
std::ofstream ofile;
|
||||
|
||||
int lattice_sizes[] = {20, 40, 60, 80, 100};
|
||||
@@ -38,9 +40,11 @@ void time_lattice_sizes()
|
||||
ofile.close();
|
||||
}
|
||||
|
||||
/** @brief Time phase transition using different sample sizes.
|
||||
* */
|
||||
void time_sample_sizes()
|
||||
{
|
||||
std::string outfile = "output/timing/sample_sizes.txt";
|
||||
std::string outfile = "data/timing/sample_sizes.txt";
|
||||
std::ofstream ofile;
|
||||
|
||||
int sample_sizes[] = {1000, 10000, 100000};
|
||||
@@ -59,6 +63,7 @@ void time_sample_sizes()
|
||||
ofile.close();
|
||||
}
|
||||
|
||||
/** @brief A function that displays how to use the program and quits.*/
|
||||
void usage(std::string filename)
|
||||
{
|
||||
std::cout << "Usage: " << filename << " OPTION ...\n"
|
||||
@@ -70,6 +75,7 @@ void usage(std::string filename)
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
/** @brief The main function.*/
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct option long_options[] = {{"all", 0, 0, 0},
|
||||
|
||||
Reference in New Issue
Block a user