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++) {
112 i_data[i] = montecarlo::mcmc_parallel(L, i_start + dt * i, cycles,
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);
141 utils::mkpath(utils::dirname(outfile));
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);
152 / ((
double)N * temp);
154 ofile << scientific_format(temp) <<
','
155 << scientific_format(data[i].E / N) <<
','
156 << scientific_format(data[i].M_abs / N) <<
','
157 << scientific_format(CV) <<
',' << scientific_format(X)
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.
double M_abs
Absolute Magnetization.
double M2
Magnetization squared.
Header for the data_t type.
Functions for Monte Carlo simulations.
void usage(std::string filename)
A function that displays how to use the program and quits.
int main()
The main function.
Function prototypes and macros that are useful.