Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dgl
Commits
411bef54
Unverified
Commit
411bef54
authored
Jun 11, 2021
by
Tomasz Patejko
Committed by
GitHub
Jun 11, 2021
Browse files
[CPU, Parallel] parallel_for with default grain size (#3004)
parent
17d604b5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
1 deletion
+50
-1
include/dgl/runtime/parallel_for.h
include/dgl/runtime/parallel_for.h
+39
-1
src/runtime/parallel_for.cpp
src/runtime/parallel_for.cpp
+11
-0
No files found.
include/dgl/runtime/parallel_for.h
View file @
411bef54
...
@@ -8,6 +8,8 @@
...
@@ -8,6 +8,8 @@
#include <dmlc/omp.h>
#include <dmlc/omp.h>
#include <algorithm>
#include <algorithm>
#include <string>
#include <cstdlib>
namespace
{
namespace
{
int64_t
divup
(
int64_t
x
,
int64_t
y
)
{
int64_t
divup
(
int64_t
x
,
int64_t
y
)
{
...
@@ -24,7 +26,27 @@ size_t compute_num_threads(size_t begin, size_t end, size_t grain_size) {
...
@@ -24,7 +26,27 @@ size_t compute_num_threads(size_t begin, size_t end, size_t grain_size) {
return
std
::
min
(
static_cast
<
int64_t
>
(
omp_get_max_threads
()),
divup
(
end
-
begin
,
grain_size
));
return
std
::
min
(
static_cast
<
int64_t
>
(
omp_get_max_threads
()),
divup
(
end
-
begin
,
grain_size
));
}
}
}
struct
DefaultGrainSizeT
{
size_t
grain_size
;
DefaultGrainSizeT
()
{
auto
var
=
std
::
getenv
(
"DGL_PARALLEL_FOR_GRAIN_SIZE"
);
if
(
!
var
)
{
grain_size
=
1
;
}
else
{
grain_size
=
std
::
stoul
(
var
);
}
}
size_t
operator
()()
{
return
grain_size
;
}
};
}
// namespace
static
DefaultGrainSizeT
default_grain_size
;
/*!
/*!
* \brief OpenMP-based parallel for loop.
* \brief OpenMP-based parallel for loop.
...
@@ -62,6 +84,22 @@ void parallel_for(
...
@@ -62,6 +84,22 @@ void parallel_for(
f
(
i
);
f
(
i
);
#endif
#endif
}
}
/*!
* \brief OpenMP-based parallel for loop with default grain size.
*
* parallel_for with grain size to default value, either 1 or controlled through
* environment variable DGL_PARALLEL_FOR_GRAIN_SIZE.
* If grain size is set to 1, the function behaves the same way as OpenMP
* parallel for pragma with static scheduling.
*/
template
<
typename
F
>
void
parallel_for
(
const
size_t
begin
,
const
size_t
end
,
F
&&
f
)
{
parallel_for
(
begin
,
end
,
default_grain_size
(),
f
);
}
}
// namespace runtime
}
// namespace runtime
}
// namespace dgl
}
// namespace dgl
...
...
src/runtime/parallel_for.cpp
0 → 100644
View file @
411bef54
/*!
* Copyright (c) 2016 by Contributors
* Implementation of C API (reference: tvm/src/api/c_api.cc)
* \file c_api.cc
*/
namespace
dgl
{
namespace
runtime
{
DefaultGrainSizeT
default_grain_size
;
}
// namespace runtime
}
// namesoace dgl
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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