2
3
4
5
6
7
8
9
10
11
12
13
14
15
28 <<
"Usage: " << filename
29 <<
" <start temperature> <end temperature> <lattice size> "
30 "<points> <cycles> <burn-in-time> <output file>\n"
31 <<
"This should be used with mpiexec or mpirun for maximum "
33 <<
"\t[ -h | --help ]\n";
38int main(
int argc,
char **argv)
41 struct option long_options[] = {{
"help", 0, 0, 0}, {NULL, 0, NULL, 0}};
43 int option_index = -1;
47 c = getopt_long(argc, argv,
"h", long_options, &option_index);
54 switch (option_index) {
75 double start = atof(argv[1]), end = atof(argv[2]);
76 int points = atoi(argv[3]), cycles = atoi(argv[5]), L = atoi(argv[4]),
77 burn_in_time = atoi(argv[6]), N = L * L;
78 double dt = (end - start) / points;
80 std::string outfile = argv[7];
84 int rank, cluster_size;
87 MPI_Init(&argc, &argv);
90 MPI_Comm_size(MPI_COMM_WORLD, &cluster_size);
91 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
93 int remainder = points % cluster_size;
98 if (rank < remainder) {
99 i_points = points / cluster_size + 1;
100 i_start = start + dt * i_points * rank;
103 i_points = points / cluster_size;
104 i_start = start + dt * (i_points * rank + remainder);
111 for (size_t i = 0; i < i_points; i++) {
120 std::copy_n(i_data, i_points, data);
123 for (size_t i = 1; i < cluster_size; i++) {
124 if (rank < remainder) {
125 MPI_Recv((
void *)i_data,
126 sizeof(data_t) * (points / cluster_size + 1), MPI_CHAR,
127 i, MPI_ANY_TAG, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
128 std::copy_n(i_data, points / cluster_size + 1,
129 data + (points / cluster_size) * i);
132 MPI_Recv((
void *)i_data,
133 sizeof(data_t) * (points / cluster_size), MPI_CHAR, i,
134 MPI_ANY_TAG, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
135 std::copy_n(i_data, points / cluster_size,
136 data + (points / cluster_size) * i + remainder);
146 using utils::scientific_format;
147 for (size_t i = 0; i < points; i++) {
148 temp = start + dt * i;
149 CV = (data[i].E2 - data[i].E * data[i].E)
150 / ((
double)N * temp * temp);
151 X = (data[i].M2 - data[i].M_abs * data[i].M_abs)
152 / ((
double)N * temp);
155 << scientific_format(data[i].E / N) <<
','
156 << scientific_format(data[i].M_abs / N) <<
','
164 MPI_Send(i_data, i_points *
sizeof(data_t), MPI_CHAR, 0, rank,
171 std::cout <<
"Time: " << t1 - t0 <<
" seconds\n";
Type to use with the IsingModel class and montecarlo module.
int main(int argc, char **argv)
The main function.
void usage(std::string filename)
A function that displays how to use the program and quits.
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.
std::string scientific_format(double d, int width=20, int prec=10)
Turns a double into a string written in scientific format.
std::string dirname(const std::string &path)
Get the directory name of the path.