Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
solverstack
ScalFMM
Commits
685ddbfc
Commit
685ddbfc
authored
Oct 02, 2015
by
BRAMAS Berenger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add a binding class, and use in the uniform compare test
parent
03449d8c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
1 deletion
+67
-1
Src/Utils/FBinding.hpp
Src/Utils/FBinding.hpp
+62
-0
Tests/noDist/testBlockedUniformCompare.cpp
Tests/noDist/testBlockedUniformCompare.cpp
+5
-1
No files found.
Src/Utils/FBinding.hpp
0 → 100644
View file @
685ddbfc
#ifndef FBINDING_HPP
#define FBINDING_HPP
#include "FGlobal.hpp"
#include "FAssert.hpp"
#include <sys/types.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <sched.h>
#include <sys/resource.h>
#include <thread>
namespace
FBinding
{
#if defined(linux) || defined(__linux__) || defined(unix) || defined(__unix__)
#define FBINDING_ENABLE
#endif
inline
int
GetThreadBinding
(){
// Mask will contain the current affinity
#ifdef FBINDING_ENABLE
unsigned
long
mask
=
0
;
// We need the thread pid (even if we are in openmp)
pid_t
tid
=
(
pid_t
)
syscall
(
SYS_gettid
);
// Get the affinity
FAssertLF
(
sched_getaffinity
(
tid
,
sizeof
(
mask
),
(
cpu_set_t
*
)
&
mask
)
!=
-
1
);
return
int
(
mask
>>
1
);
#endif
return
-
1
;
}
inline
void
SetThreadBinding
(
const
int
procId
){
#ifdef FBINDING_ENABLE
cpu_set_t
set
;
CPU_ZERO
(
&
set
);
CPU_SET
(
procId
,
&
set
);
pid_t
tid
=
(
pid_t
)
syscall
(
SYS_gettid
);
FAssertLF
(
sched_setaffinity
(
tid
,
sizeof
(
set
),
&
set
)
!=
-
1
);
#endif
}
inline
void
BindThreadToAnyProcs
(){
#ifdef FBINDING_ENABLE
cpu_set_t
set
;
CPU_ZERO
(
&
set
);
const
int
nbProcs
=
(
int
)
std
::
thread
::
hardware_concurrency
();
for
(
int
idxProc
=
0
;
idxProc
<
nbProcs
;
++
idxProc
){
CPU_SET
(
idxProc
,
&
set
);
}
pid_t
tid
=
(
pid_t
)
syscall
(
SYS_gettid
);
FAssertLF
(
sched_setaffinity
(
tid
,
sizeof
(
set
),
&
set
)
!=
-
1
);
#endif
}
}
#endif // FBINDING_HPP
Tests/noDist/testBlockedUniformCompare.cpp
View file @
685ddbfc
...
...
@@ -57,7 +57,7 @@
#include "Components/FSimpleLeaf.hpp"
#include "Kernels/P2P/FP2PParticleContainerIndexed.hpp"
#include "Utils/FBinding.hpp"
#include "Utils/FTemplate.hpp"
#ifdef MEMORY_USAGE
...
...
@@ -657,6 +657,10 @@ struct RunContainer{
GroupKernelClass
groupkernel
(
NbLevels
,
loader
.
getBoxWidth
(),
loader
.
getCenterOfBox
(),
&
MatrixKernel
);
GroupAlgorithm
groupalgo
(
&
groupedTree
,
&
groupkernel
);
std
::
cout
<<
"I am bind to "
<<
(
FBinding
::
GetThreadBinding
())
<<
std
::
endl
;
FBinding
::
BindThreadToAnyProcs
();
std
::
cout
<<
"And now I am bind to "
<<
(
FBinding
::
GetThreadBinding
())
<<
std
::
endl
;
timer
.
tic
();
groupalgo
.
execute
();
std
::
cout
<<
"Done "
<<
"(@Algorithm = "
<<
timer
.
tacAndElapsed
()
<<
"s)."
<<
std
::
endl
;
...
...
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