Make some changes
- Add new programs - Add command line args - Add Usage to guide user on how to use programs
This commit is contained in:
79
src/pd_estimate.cpp
Normal file
79
src/pd_estimate.cpp
Normal file
@@ -0,0 +1,79 @@
|
||||
/** @file pd_estimate.cpp
|
||||
*
|
||||
* @author Cory Alexander Balaton (coryab)
|
||||
* @author Janita Ovidie Sandtrøen Willumsen (janitaws)
|
||||
*
|
||||
* @version 1.0
|
||||
*
|
||||
* @brief execute the mcmc algorithm and write data to file after each
|
||||
* Monte Carlo cycles.
|
||||
*
|
||||
* @bug No known bugs
|
||||
* */
|
||||
#include "data_type.hpp"
|
||||
#include "monte_carlo.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
#include <getopt.h>
|
||||
#include <omp.h>
|
||||
#include <string>
|
||||
|
||||
void usage(std::string filename)
|
||||
{
|
||||
std::cout << "Usage: " << filename
|
||||
<< " <temperature> <lattice size> "
|
||||
"<cycles> <burn-in-time> <output file>\n\n"
|
||||
<< "\t[ -h | --help ]\n";
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
/** @brief The main function
|
||||
*
|
||||
* */
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
// Command options
|
||||
struct option long_options[] = {{"help", 0, 0, 0}, {NULL, 0, NULL, 0}};
|
||||
|
||||
int option_index = -1;
|
||||
int c;
|
||||
|
||||
while (true) {
|
||||
c = getopt_long(argc, argv, "h", long_options, &option_index);
|
||||
|
||||
if (c == -1)
|
||||
break;
|
||||
|
||||
switch (c) {
|
||||
case 0:
|
||||
switch (option_index) {
|
||||
case 0: // Not a mistake. This just goes to the default.
|
||||
default:
|
||||
usage(argv[0]);
|
||||
}
|
||||
break;
|
||||
case 'h':
|
||||
default:
|
||||
usage(argv[0]);
|
||||
}
|
||||
}
|
||||
// Check that the number of arguments is at least 8.
|
||||
if (argc < 6) {
|
||||
usage(argv[0]);
|
||||
}
|
||||
|
||||
// Timing variables
|
||||
double t0, t1;
|
||||
t0 = omp_get_wtime();
|
||||
|
||||
// Define/initialize variables
|
||||
double temp = atoi(argv[1]);
|
||||
int L = atoi(argv[2]), cycles = atoi(argv[3]), burn_in_time = atoi(argv[4]);
|
||||
std::string outfile = argv[5];
|
||||
|
||||
montecarlo::pd_estimate(temp, L, cycles, outfile, burn_in_time);
|
||||
|
||||
t1 = omp_get_wtime();
|
||||
|
||||
std::cout << "Time: " << t1 - t0 << " seconds\n";
|
||||
}
|
||||
Reference in New Issue
Block a user