Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Martin Reinecke
ducc
Commits
adcaefb7
Commit
adcaefb7
authored
Jan 10, 2020
by
Martin Reinecke
Browse files
allow changing default number of threads
parent
c698770d
Changes
2
Hide whitespace changes
Inline
Side-by-side
mr_util/threading.h
View file @
adcaefb7
...
...
@@ -16,7 +16,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* Copyright (C) 2019 Peter Bell, Max-Planck-Society
/* Copyright (C) 2019
-2020
Peter Bell, Max-Planck-Society
Authors: Peter Bell, Martin Reinecke */
#ifndef MRUTIL_THREADING_H
...
...
@@ -45,6 +45,18 @@ using namespace std;
#ifndef MRUTIL_NO_THREADING
static
const
size_t
max_threads_
=
max
(
1u
,
thread
::
hardware_concurrency
());
inline
atomic
<
size_t
>
&
default_nthreads
()
{
static
atomic
<
size_t
>
default_nthreads_
=
max_threads_
;
return
default_nthreads_
;
}
inline
size_t
get_default_nthreads
()
{
return
default_nthreads
();
}
inline
void
set_default_nthreads
(
size_t
new_default_nthreads
)
{
default_nthreads
()
=
max
<
size_t
>
(
1
,
new_default_nthreads
);
}
class
latch
{
atomic
<
size_t
>
num_left_
;
...
...
@@ -229,7 +241,7 @@ class Distribution
size_t
nthreads
,
size_t
chunksize
,
Func
f
)
{
mode
=
STATIC
;
nthreads_
=
(
nthreads
==
0
)
?
max_
threads
_
:
nthreads
;
nthreads_
=
(
nthreads
==
0
)
?
get_default_n
threads
()
:
nthreads
;
nwork_
=
nwork
;
chunksize_
=
(
chunksize
<
1
)
?
(
nwork_
+
nthreads_
-
1
)
/
nthreads_
:
chunksize
;
...
...
@@ -243,7 +255,7 @@ class Distribution
size_t
nthreads
,
size_t
chunksize_min
,
double
fact_max
,
Func
f
)
{
mode
=
DYNAMIC
;
nthreads_
=
(
nthreads
==
0
)
?
max_
threads
_
:
nthreads
;
nthreads_
=
(
nthreads
==
0
)
?
get_default_n
threads
()
:
nthreads
;
nwork_
=
nwork
;
chunksize_
=
(
chunksize_min
<
1
)
?
1
:
chunksize_min
;
if
(
chunksize_
*
nthreads_
>=
nwork_
)
...
...
@@ -255,7 +267,7 @@ class Distribution
template
<
typename
Func
>
void
execParallel
(
size_t
nthreads
,
Func
f
)
{
mode
=
STATIC
;
nthreads_
=
(
nthreads
==
0
)
?
max_
threads
_
:
nthreads
;
nthreads_
=
(
nthreads
==
0
)
?
get_default_n
threads
()
:
nthreads
;
nwork_
=
nthreads_
;
chunksize_
=
1
;
thread_map
(
move
(
f
));
...
...
@@ -372,6 +384,12 @@ class Sched0
template
<
typename
Func
>
void
execParallel
(
size_t
/*nthreads*/
,
Func
f
)
{
f
();
}
inline
size_t
get_default_nthreads
()
{
return
1
;
}
inline
void
set_default_nthreads
(
size_t
/*new_default_nthreads*/
)
{}
#endif
namespace
{
...
...
@@ -413,6 +431,8 @@ inline size_t max_threads()
}
// end of namespace detail
using
detail_threading
::
get_default_nthreads
;
using
detail_threading
::
set_default_nthreads
;
using
detail_threading
::
Scheduler
;
using
detail_threading
::
execSingle
;
using
detail_threading
::
execStatic
;
...
...
test/sharp2_testsuite.cc
View file @
adcaefb7
...
...
@@ -20,7 +20,7 @@
/* \file sharp_testsuite.c
*
* Copyright (C) 2012-20
19
Max-Planck-Society
* Copyright (C) 2012-20
20
Max-Planck-Society
* \author Martin Reinecke
*/
...
...
@@ -34,13 +34,14 @@ using std::complex;
#include
"mr_util/error_handling.h"
#include
"mr_util/threading.h"
#include
"mr_util/math_utils.h"
#include
"mr_util/string_utils.h"
using
namespace
std
;
using
namespace
mr
;
static
void
threading_status
(
void
)
{
cout
<<
"Threading: "
<<
mr
::
max_
threads
()
<<
" threads active."
<<
endl
;
cout
<<
"Threading: "
<<
mr
::
get_default_n
threads
()
<<
" threads active."
<<
endl
;
}
static
void
MPI_status
(
void
)
...
...
@@ -536,6 +537,13 @@ static void sharp_test (int argc, const char **argv)
int
main
(
int
argc
,
const
char
**
argv
)
{
const
char
*
tmp
=
getenv
(
"OMP_NUM_THREADS"
);
if
(
tmp
!=
nullptr
)
{
string
tmp2
(
tmp
);
if
(
trim
(
tmp2
)
!=
""
)
mr
::
set_default_nthreads
(
stringToData
<
size_t
>
(
tmp
));
}
mytask
=
0
;
ntasks
=
1
;
MR_assert
(
argc
>=
2
,
"need at least one command line argument"
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment