-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #244 from PDoakORNL/parallel-block
Introduce MiniqmcOptions to capture miniQMC input options
- Loading branch information
Showing
8 changed files
with
557 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// This file is distributed under the University of Illinois/NCSA Open Source | ||
// License. See LICENSE file in top directory for details. | ||
// | ||
// Copyright (c) 2019 QMCPACK developers. | ||
// | ||
// File developed by: | ||
// Peter Doak, [email protected], Oak Ridge National Lab | ||
// | ||
// File created by: | ||
// Peter Doak, [email protected], Oak Ridge National Lab | ||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
#include "Drivers/MiniQMCOptions.h" | ||
#include "Utilities/OutputManager.h" | ||
|
||
namespace qmcplusplus | ||
{ | ||
MiniQMCOptions readOptions(int argc, char** argv) | ||
{ | ||
MiniQMCOptions mq_opt; | ||
using QMCT = QMCTraits; | ||
int opt; | ||
while (optind < argc) | ||
{ | ||
if ((opt = getopt(argc, argv, "bhjvVa:c:C:d:g:m:n:N:r:s:t:w:x:z:")) != -1) | ||
{ | ||
switch (opt) | ||
{ | ||
case 'a': | ||
mq_opt.splines_per_block = atoi(optarg); | ||
break; | ||
case 'b': | ||
mq_opt.useRef = true; | ||
break; | ||
case 'C': | ||
mq_opt.num_crowds = atoi(optarg); | ||
break; | ||
case 'c': | ||
mq_opt.crowd_size = atoi(optarg); | ||
break; | ||
// case 'd': // Device choice | ||
// mq_opt.device_number = atoi(optarg); | ||
// break; | ||
case 'g': // tiling1 tiling2 tiling3 | ||
sscanf(optarg, "%d %d %d", &mq_opt.na, &mq_opt.nb, &mq_opt.nc); | ||
break; | ||
case 'h': | ||
mq_opt.print_help(); | ||
//should throw | ||
mq_opt.valid = false; | ||
return mq_opt; | ||
break; | ||
case 'j': | ||
mq_opt.enableJ3 = true; | ||
break; | ||
case 'm': | ||
{ | ||
const QMCT::RealType meshfactor = atof(optarg); | ||
mq_opt.nx *= meshfactor; | ||
mq_opt.ny *= meshfactor; | ||
mq_opt.nz *= meshfactor; | ||
} | ||
break; | ||
case 'n': | ||
mq_opt.nsteps = atoi(optarg); | ||
break; | ||
case 'N': | ||
mq_opt.nsubsteps = atoi(optarg); | ||
break; | ||
case 'r': | ||
mq_opt.accept_ratio = atof(optarg); | ||
break; | ||
case 's': | ||
mq_opt.iseed = atoi(optarg); | ||
break; | ||
case 't': | ||
mq_opt.timer_level_name = std::string(optarg); | ||
break; | ||
case 'v': | ||
mq_opt.verbose = true; | ||
break; | ||
case 'V': | ||
::print_version(true); | ||
return mq_opt; | ||
break; | ||
case 'w': | ||
mq_opt.walkers_per_rank = atoi(optarg); | ||
break; | ||
case 'x': | ||
mq_opt.Rmax = atof(optarg); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
else // disallow non-option arguments | ||
{ | ||
app_error() << "Non-option arguments not allowed = " << std::endl; | ||
mq_opt.valid = false; | ||
mq_opt.print_help(); | ||
return mq_opt; | ||
} | ||
} | ||
return mq_opt; | ||
} | ||
|
||
void MiniQMCOptions::print_help() | ||
{ | ||
app_summary() << "usage:" << '\n'; | ||
app_summary() << " miniqmc [-bhjvV] [-g \"n0 n1 n2\"] [-m meshfactor]" << '\n'; | ||
app_summary() << " [-n steps] [-N substeps] [-x rmax]" << '\n'; | ||
app_summary() << " [-r AcceptanceRatio] [-s seed] [-w walkers]" << '\n'; | ||
app_summary() << " [-a tile_size] [-t timer_level]" << '\n'; | ||
app_summary() << "options:" << '\n'; | ||
app_summary() << " -a splines per spline block default: num of orbs" << '\n'; | ||
app_summary() << " -b use reference implementations default: off" << '\n'; | ||
app_summary() << " -g set the 3D tiling. default: 1 1 1" << '\n'; | ||
app_summary() << " -h print help and exit" << '\n'; | ||
app_summary() << " -j enable three body Jastrow default: off" << '\n'; | ||
app_summary() << " -m meshfactor default: 1.0" << '\n'; | ||
app_summary() << " -n number of MC steps default: 5" << '\n'; | ||
app_summary() << " -N number of MC substeps default: 1" << '\n'; | ||
app_summary() << " -c crowd size default: 1\n"; | ||
app_summary() << " -C number of crowds default: 1\n"; | ||
app_summary() << " -r set the acceptance ratio. default: 0.5" << '\n'; | ||
app_summary() << " -s set the random seed. default: 11" << '\n'; | ||
app_summary() << " -t timer level: coarse or fine default: fine" << '\n'; | ||
app_summary() << " -w walkers per rank default: 1" << '\n'; | ||
app_summary() << " -v verbose output" << '\n'; | ||
app_summary() << " -V print version information and exit" << '\n'; | ||
app_summary() << " -x set the Rmax. default: 1.7" << '\n'; | ||
//app_summary() << " -d device implementation. default: CPU " << '\n'; | ||
//app_summary() << " Available devices:" << '\n'; | ||
// hana::for_each(devices_range, [&](auto x) { | ||
// std::string enum_name(hana::to<char const*>(device_names[x])); | ||
// app_summary() << " " << x << ". " << enum_name << '\n'; | ||
// }); | ||
} | ||
|
||
} // namespace qmcplusplus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// This file is distributed under the University of Illinois/NCSA Open Source | ||
// License. See LICENSE file in top directory for details. | ||
// | ||
// Copyright (c) 2019 QMCPACK developers. | ||
// | ||
// File developed by: | ||
// Peter Doak, [email protected], Oak Ridge National Lab | ||
// | ||
// File created by: | ||
// Peter Doak, [email protected], Oak Ridge National Lab | ||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
#ifndef QMCPLUSPLUS_MINIQMC_OPTIONS_H | ||
#define QMCPLUSPLUS_MINIQMC_OPTIONS_H | ||
|
||
#include <getopt.h> | ||
#include <iostream> | ||
#include <cstdio> | ||
#include "Utilities/qmcpack_version.h" | ||
#include "Utilities/NewTimer.h" | ||
|
||
namespace qmcplusplus | ||
{ | ||
enum MiniQMCTimers | ||
{ | ||
Timer_Total, | ||
Timer_Init, | ||
Timer_Diffusion, | ||
Timer_ECP, | ||
Timer_Value, | ||
Timer_evalGrad, | ||
Timer_evalVGH, | ||
Timer_ratioGrad, | ||
Timer_Update, | ||
}; | ||
|
||
/** Reads and holds the options to support more flexible non 'c main()' drivers | ||
* | ||
*/ | ||
class MiniQMCOptions | ||
{ | ||
public: | ||
TimerNameList_t<MiniQMCTimers> MiniQMCTimerNames{ | ||
{Timer_Total, "Total"}, | ||
{Timer_Init, "Initialization"}, | ||
{Timer_Diffusion, "Diffusion"}, | ||
{Timer_ECP, "Pseudopotential"}, | ||
{Timer_Value, "Value"}, | ||
{Timer_evalGrad, "Current Gradient"}, | ||
{Timer_evalVGH, "Spline Hessian Evaluation"}, | ||
{Timer_ratioGrad, "New Gradient"}, | ||
{Timer_Update, "Update"}, | ||
}; | ||
|
||
static void print_help(); | ||
|
||
using QMCT = QMCTraits; | ||
//Devices device = Devices::CPU; | ||
bool valid = true; | ||
//int device_number = 0; | ||
int na = 1; | ||
int nb = 1; | ||
int nc = 1; | ||
int nsteps = 5; | ||
int iseed = 11; | ||
int nx = 37, ny = 37, nz = 37; | ||
int num_crowds = 1; | ||
int splines_per_block = -1; | ||
int nsubsteps = 1; | ||
int nels = 0; | ||
// Set cutoff for NLPP use. | ||
// This makes precision an issue to select at run time. | ||
QMCT::RealType Rmax = 1.7; | ||
QMCT::RealType accept_ratio = 0.5; | ||
//useRef is a particular implementation of numerous objects fix that remove this option | ||
//and many branch statements | ||
bool useRef = false; | ||
bool enableJ3 = false; | ||
bool enableCrowd = false; | ||
bool verbose = false; | ||
std::string timer_level_name = "fine"; | ||
TimerList_t Timers; | ||
int crowd_size = 1; | ||
int walkers_per_rank = 0; | ||
MiniQMCOptions() = default; | ||
MiniQMCOptions(const MiniQMCOptions&) = default; | ||
}; | ||
|
||
MiniQMCOptions readOptions(int argc,char** argv); | ||
|
||
} // namespace qmcplusplus | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#////////////////////////////////////////////////////////////////////////////////////// | ||
#// This file is distributed under the University of Illinois/NCSA Open Source License. | ||
#// See LICENSE file in top directory for details. | ||
#// | ||
#// Copyright (c) 2019 QMCPACK developers. | ||
#// | ||
#// File developed by: | ||
#// Peter Doak, [email protected], Oak Ridge National Lab | ||
#// | ||
#// File created by: | ||
#// Peter Doak, [email protected], Oak Ridge National Lab | ||
#//////////////////////////////////////////////////////////////////////////////// | ||
|
||
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${QMCPACK_UNIT_TEST_DIR}) | ||
|
||
SET(SRC_DIR Drivers) | ||
SET(UTEST_EXE test_${SRC_DIR}) | ||
SET(UTEST_NAME unit_test_${SRC_DIR}) | ||
|
||
|
||
ADD_EXECUTABLE(${UTEST_EXE} ../../Utilities/catch-main.cpp ../MiniQMCOptions.cpp test_MiniQMCOptions.cpp) | ||
TARGET_LINK_LIBRARIES(${UTEST_EXE} qmcutil ${MPI_LIBRARY}) | ||
|
||
ADD_UNIT_TEST(${UTEST_NAME} "${QMCPACK_UNIT_TEST_DIR}/${UTEST_EXE}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// This file is distributed under the University of Illinois/NCSA Open Source | ||
// License. See LICENSE file in top directory for details. | ||
// | ||
// Copyright (c) 2019 QMCPACK developers. | ||
// | ||
// File developed by: | ||
// Peter Doak, [email protected], Oak Ridge National Lab | ||
// | ||
// File created by: | ||
// Peter Doak, [email protected], Oak Ridge National Lab | ||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
#include <string> | ||
#include <vector> | ||
#include "catch.hpp" | ||
#include "Drivers/MiniQMCOptions.h" | ||
|
||
/** @file | ||
* | ||
* For now we omit testing help and version output | ||
*/ | ||
|
||
namespace qmcplusplus | ||
{ | ||
|
||
TEST_CASE("MiniQMCOptions Read", "[Application]") { | ||
int argc = 28; | ||
std::vector<std::string> opt_strs = {"dummy_progname", | ||
"-a","256", | ||
"-b", | ||
"-c","8", | ||
"-g","2 1 3", | ||
"-j", | ||
"-m","256", | ||
"-n","10", | ||
"-N","1", | ||
"-r","0.75", | ||
"-s","140", | ||
"-t","fine", | ||
"-v", | ||
"-w","200", | ||
"-C","10", | ||
"-x","1.7" | ||
}; | ||
|
||
std::vector<char*> option_ptrs; | ||
option_ptrs.reserve(argc + 1); | ||
std::transform(begin(opt_strs), end(opt_strs), | ||
std::back_inserter(option_ptrs), | ||
[](std::string& s) { char * ptr = new char[s.length() + 1]; | ||
std::strcpy(ptr, s.c_str() ); | ||
return ptr;}); | ||
option_ptrs.push_back(nullptr); | ||
MiniQMCOptions mq_opt = readOptions(argc, option_ptrs.data()); | ||
REQUIRE(mq_opt.valid); | ||
std::for_each(begin(option_ptrs), end(option_ptrs), | ||
[](char* c) { delete[] c; }); | ||
REQUIRE(mq_opt.splines_per_block == 256); | ||
REQUIRE(mq_opt.useRef); | ||
REQUIRE(mq_opt.crowd_size == 8); | ||
REQUIRE(mq_opt.num_crowds == 10); | ||
REQUIRE(mq_opt.na == 2); | ||
REQUIRE(mq_opt.nb == 1); | ||
REQUIRE(mq_opt.nc == 3); | ||
REQUIRE(mq_opt.enableJ3); | ||
REQUIRE(mq_opt.nx == 256 * 37); // PD: yes this 37 is hard coded into the options | ||
REQUIRE(mq_opt.ny == 256 * 37); // I carried it over from miniqmc_sync_move.cpp | ||
REQUIRE(mq_opt.nz == 256 * 37); | ||
REQUIRE(mq_opt.nsteps == 10); | ||
REQUIRE(mq_opt.nsubsteps == 1); | ||
REQUIRE(mq_opt.accept_ratio == 0.75); | ||
REQUIRE(mq_opt.iseed == 140); | ||
REQUIRE(mq_opt.timer_level_name == "fine"); | ||
REQUIRE(mq_opt.verbose); | ||
REQUIRE(mq_opt.walkers_per_rank == 200); | ||
REQUIRE(mq_opt.Rmax == 1.7); | ||
|
||
|
||
} | ||
|
||
} | ||
|
Oops, something went wrong.