Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
OpenSource
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jan Willem Thorbecke
OpenSource
Commits
58ee56a8
Commit
58ee56a8
authored
8 years ago
by
Jan Thorbecke
Browse files
Options
Downloads
Patches
Plain Diff
adding missing file
parent
f964799a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
fdelmodc/fdelmodc.c
+2
-2
2 additions, 2 deletions
fdelmodc/fdelmodc.c
fdelmodc/threadAffinity.c
+107
-0
107 additions, 0 deletions
fdelmodc/threadAffinity.c
with
109 additions
and
2 deletions
fdelmodc/fdelmodc.c
+
2
−
2
View file @
58ee56a8
...
...
@@ -12,7 +12,7 @@
double
wallclock_time
(
void
);
void
threadAffi
c
ity
(
void
);
void
threadAffi
n
ity
(
void
);
int
getParameters
(
modPar
*
mod
,
recPar
*
rec
,
snaPar
*
sna
,
wavPar
*
wav
,
srcPar
*
src
,
shotPar
*
shot
,
bndPar
*
bnd
,
int
verbose
);
...
...
@@ -505,7 +505,7 @@ shared (tt, t2, t3) \
shared (shot, bnd, mod, src, wav, rec, ixsrc, izsrc, it, src_nwav, verbose)
{
if
(
it
==
it0
)
{
threadAffi
c
ity
();
threadAffi
n
ity
();
}
switch
(
mod
.
ischeme
)
{
// case -2 : /* test code for PML */
...
...
This diff is collapsed.
Click to expand it.
fdelmodc/threadAffinity.c
0 → 100644
+
107
−
0
View file @
58ee56a8
#define _GNU_SOURCE
#include
<stdio.h>
#include
<unistd.h>
#include
<string.h>
#include
<omp.h>
#ifdef __USE_GNU
#include
<sched.h>
#else
/* for OSX */
#include
<sched.h>
#include
<sys/types.h>
#include
<sys/sysctl.h>
#define CPU_SETSIZE 1024
#define SYSCTL_CORE_COUNT "machdep.cpu.core_count"
typedef
struct
cpu_set
{
uint32_t
count
;
}
cpu_set_t
;
static
inline
void
CPU_ZERO
(
cpu_set_t
*
cs
)
{
cs
->
count
=
0
;
}
static
inline
void
CPU_SET
(
int
num
,
cpu_set_t
*
cs
)
{
cs
->
count
|=
(
1
<<
num
);
}
static
inline
int
CPU_ISSET
(
int
num
,
cpu_set_t
*
cs
)
{
return
(
cs
->
count
&
(
1
<<
num
));
}
int
sched_getaffinity
(
pid_t
pid
,
size_t
cpu_size
,
cpu_set_t
*
cpu_set
)
{
int32_t
core_count
=
0
;
size_t
len
=
sizeof
(
core_count
);
int
ret
=
sysctlbyname
(
SYSCTL_CORE_COUNT
,
&
core_count
,
&
len
,
0
,
0
);
if
(
ret
)
{
printf
(
"error while get core count %d
\n
"
,
ret
);
return
-
1
;
}
cpu_set
->
count
=
0
;
for
(
int
i
=
0
;
i
<
core_count
;
i
++
)
{
cpu_set
->
count
|=
(
1
<<
i
);
}
return
0
;
}
#endif
/* Borrowed from util-linux-2.13-pre7/schedutils/taskset.c */
static
char
*
cpuset_to_cstr
(
cpu_set_t
*
mask
,
char
*
str
)
{
char
*
ptr
=
str
;
int
i
,
j
,
entry_made
=
0
;
for
(
i
=
0
;
i
<
CPU_SETSIZE
;
i
++
)
{
if
(
CPU_ISSET
(
i
,
mask
))
{
int
run
=
0
;
entry_made
=
1
;
for
(
j
=
i
+
1
;
j
<
CPU_SETSIZE
;
j
++
)
{
if
(
CPU_ISSET
(
j
,
mask
))
run
++
;
else
break
;
}
if
(
!
run
)
sprintf
(
ptr
,
"%d,"
,
i
);
else
if
(
run
==
1
)
{
sprintf
(
ptr
,
"%d,%d,"
,
i
,
i
+
1
);
i
++
;
}
else
{
sprintf
(
ptr
,
"%d-%d,"
,
i
,
i
+
run
);
i
+=
run
;
}
while
(
*
ptr
!=
0
)
ptr
++
;
}
}
ptr
-=
entry_made
;
*
ptr
=
0
;
return
(
str
);
}
void
threadAffinity
(
void
)
{
int
rank
,
thread
;
cpu_set_t
coremask
;
char
clbuf
[
7
*
CPU_SETSIZE
],
hnbuf
[
64
];
char
prefix
[
200
];
memset
(
clbuf
,
0
,
sizeof
(
clbuf
));
memset
(
hnbuf
,
0
,
sizeof
(
hnbuf
));
(
void
)
gethostname
(
hnbuf
,
sizeof
(
hnbuf
));
strcpy
(
prefix
,
"Hello world from"
);
// #pragma omp parallel private(thread, coremask, clbuf)
/* for use inside parallel region */
#pragma omp critical
{
thread
=
omp_get_thread_num
();
(
void
)
sched_getaffinity
(
0
,
sizeof
(
coremask
),
&
coremask
);
cpuset_to_cstr
(
&
coremask
,
clbuf
);
printf
(
"%s thread %d, on %s. (core affinity = %s)
\n
"
,
prefix
,
thread
,
hnbuf
,
clbuf
);
}
return
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment