Commit b85de6d6 authored by Martin Pokorny's avatar Martin Pokorny
Browse files

Add optional arguments to initialize()

Arguments follow Kokkos::InitArguments, but defined independently
parent 4b6160ae
......@@ -23,4 +23,4 @@
# This supports aligning a git commit to each change in version
# number, and also allows parent projects to provide their own version
# number.
set(hpg_VER 0.14.1)
set(hpg_VER 0.15.0)
......@@ -97,6 +97,14 @@ ScopeGuard::ScopeGuard()
}
}
ScopeGuard::ScopeGuard(const InitArguments& args)
: init(false) {
if (!is_initialized()) {
initialize(args);
init = true;
}
}
ScopeGuard::~ScopeGuard() {
if (is_initialized() && init)
finalize();
......@@ -1366,7 +1374,19 @@ hpg::cf_layout_unspecified_version = "";
bool
hpg::initialize() {
return Impl::initialize();
InitArguments args;
args.num_threads = -1;
args.num_numa = -1;
args.device_id = -1;
args.ndevices = -1;
args.skip_device = -1;
args.disable_warnings = false;
return initialize(args);
}
bool
hpg::initialize(const InitArguments& args) {
return Impl::initialize(args);
}
void
......
......@@ -46,6 +46,52 @@
*/
namespace hpg {
/** initialization arguments
*
* This type is currently identical to the Kokkos type of the same name,
* although that could change in future versions.
*
* If you set num_threads or num_numa to zero or less, Kokkos will try to
* determine default values if possible or otherwise set them to 1. In
* particular, Kokkos can use the hwloc library to determine default settings
* using the assumption that the process binding mask is unique, i.e., that this
* process does not share any cores with another process. Note that the default
* value of each parameter is -1.
*/
struct InitArguments {
/** number of threads per NUMA region
*
* Used in conjunction with num_numa
*/
int num_threads;
/** number of NUMA regions used by process
*/
int num_numa;
/** device id to be used */
int device_id;
/** number of devices to be used per node
*
* Used when running MPI jobs. Process to device mapping happens by obtaining
* the local MPI rank and assigning devices round-robin.
*/
int ndevices;
/** device to ignore
*
* Used in conjunction with ndevices. This is most useful
* on workstations with multiple GPUs, one of which is used to drive screen
* output.
*/
int skip_device;
/** disable Kokkos warnings
*/
bool disable_warnings;
};
/** global initialization of hpg
*
* Function is idempotent, but should not be called by a process after a call to
......@@ -68,6 +114,12 @@ namespace hpg {
*/
HPG_EXPORT bool initialize();
/** global initialization of hpg, with arguments
*
* @param args initialization parameters
*/
HPG_EXPORT bool initialize(const InitArguments& args);
/** global finalization of hpg
*
* Function is idempotent, but should only be called by a process after a call
......@@ -128,8 +180,18 @@ private:
bool init;
public:
/** default constructor
*
* calls hpg::initialize()
*/
ScopeGuard();
/** constructor with initialization argument
*
* calls hpg::initialize(const InitArguments&)
*/
ScopeGuard(const InitArguments& args);
~ScopeGuard();
ScopeGuard(const ScopeGuard&) = delete;
......
......@@ -291,9 +291,16 @@ static bool hpg_impl_initialized = false;
/** implementation initialization function */
bool
initialize() {
initialize(const InitArguments& args) {
bool result = true;
K::initialize();
Kokkos::InitArguments kargs;
kargs.num_threads = args.num_threads;
kargs.num_numa = args.num_numa;
kargs.device_id = args.device_id;
kargs.ndevices = args.ndevices;
kargs.skip_device = args.skip_device;
kargs.disable_warnings = args.disable_warnings;
K::initialize(kargs);
#ifdef HPG_ENABLE_OPENMP
auto rc = fftw_init_threads();
result = rc != 0;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment