Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SWIFT
SWIFTsim
Commits
a473067b
Commit
a473067b
authored
Jul 30, 2017
by
Pedro Gonnet
Committed by
Matthieu Schaller
Aug 03, 2017
Browse files
use the new barrier.
parent
b6392d82
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/engine.c
View file @
a473067b
...
...
@@ -2926,16 +2926,14 @@ void engine_prepare(struct engine *e) {
* @brief Implements a barrier for the #runner threads.
*
* @param e The #engine.
* @param tid The thread ID
*/
void
engine_barrier
(
struct
engine
*
e
,
int
tid
)
{
void
engine_barrier
(
struct
engine
*
e
)
{
/* Wait at the wait barrier. */
pthread_barrier_wait
(
&
e
->
wait_barrier
);
/* Wait at the run barrier. */
pthread_barrier_wait
(
&
e
->
run_barrier
);
}
/**
...
...
@@ -3216,15 +3214,10 @@ void engine_launch(struct engine *e, int nr_runners) {
atomic_inc
(
&
e
->
sched
.
waiting
);
/* Cry havoc and let loose the dogs of war. */
e
->
barrier_launch
=
nr_runners
;
e
->
barrier_launchcount
=
nr_runners
;
if
(
pthread_cond_broadcast
(
&
e
->
barrier_cond
)
!=
0
)
error
(
"Failed to broadcast barrier open condition."
);
pthread_barrier_wait
(
&
e
->
run_barrier
);
/* Load the tasks. */
pthread_mutex_unlock
(
&
e
->
barrier_mutex
);
scheduler_start
(
&
e
->
sched
);
pthread_mutex_lock
(
&
e
->
barrier_mutex
);
/* Remove the safeguard. */
pthread_mutex_lock
(
&
e
->
sched
.
sleep_mutex
);
...
...
@@ -3233,9 +3226,7 @@ void engine_launch(struct engine *e, int nr_runners) {
pthread_mutex_unlock
(
&
e
->
sched
.
sleep_mutex
);
/* Sit back and wait for the runners to come home. */
while
(
e
->
barrier_launch
||
e
->
barrier_running
)
if
(
pthread_cond_wait
(
&
e
->
barrier_cond
,
&
e
->
barrier_mutex
)
!=
0
)
error
(
"Error while waiting for barrier."
);
pthread_barrier_wait
(
&
e
->
wait_barrier
);
if
(
e
->
verbose
)
message
(
"took %.3f %s."
,
clocks_from_ticks
(
getticks
()
-
tic
),
...
...
@@ -4418,15 +4409,9 @@ void engine_init(struct engine *e, struct space *s,
threadpool_init
(
&
e
->
threadpool
,
e
->
nr_threads
);
/* First of all, init the barrier and lock it. */
if
(
pthread_mutex_init
(
&
e
->
barrier_mutex
,
NULL
)
!=
0
)
error
(
"Failed to initialize barrier mutex."
);
if
(
pthread_cond_init
(
&
e
->
barrier_cond
,
NULL
)
!=
0
)
error
(
"Failed to initialize barrier condition variable."
);
if
(
pthread_mutex_lock
(
&
e
->
barrier_mutex
)
!=
0
)
error
(
"Failed to lock barrier mutex."
);
e
->
barrier_running
=
0
;
e
->
barrier_launch
=
0
;
e
->
barrier_launchcount
=
0
;
if
(
pthread_barrier_init
(
&
e
->
wait_barrier
,
NULL
,
e
->
nr_threads
+
1
)
!=
0
||
pthread_barrier_init
(
&
e
->
run_barrier
,
NULL
,
e
->
nr_threads
+
1
)
!=
0
)
error
(
"Failed to initialize barrier."
);
/* Init the scheduler with enough tasks for the initial sorting tasks. */
const
int
nr_tasks
=
2
*
s
->
tot_cells
+
2
*
e
->
nr_threads
;
...
...
@@ -4440,7 +4425,6 @@ void engine_init(struct engine *e, struct space *s,
for
(
int
k
=
0
;
k
<
e
->
nr_threads
;
k
++
)
{
e
->
runners
[
k
].
id
=
k
;
e
->
runners
[
k
].
e
=
e
;
e
->
barrier_running
+=
1
;
if
(
pthread_create
(
&
e
->
runners
[
k
].
thread
,
NULL
,
&
runner_main
,
&
e
->
runners
[
k
])
!=
0
)
error
(
"Failed to create runner thread."
);
...
...
@@ -4503,9 +4487,7 @@ void engine_init(struct engine *e, struct space *s,
#endif
/* Wait for the runner threads to be in place. */
while
(
e
->
barrier_running
||
e
->
barrier_launch
)
if
(
pthread_cond_wait
(
&
e
->
barrier_cond
,
&
e
->
barrier_mutex
)
!=
0
)
error
(
"Error while waiting for runner threads to get in place."
);
pthread_barrier_wait
(
&
e
->
wait_barrier
);
}
/**
...
...
src/engine.h
View file @
a473067b
...
...
@@ -176,9 +176,8 @@ struct engine {
int
count_step
;
/* Data for the threads' barrier. */
pthread_mutex_t
barrier_mutex
;
pthread_cond_t
barrier_cond
;
volatile
int
barrier_running
,
barrier_launch
,
barrier_launchcount
;
pthread_barrier_t
wait_barrier
;
pthread_barrier_t
run_barrier
;
/* ID of the node this engine lives on. */
int
nr_nodes
,
nodeID
;
...
...
@@ -253,7 +252,7 @@ struct engine {
};
/* Function prototypes. */
void
engine_barrier
(
struct
engine
*
e
,
int
tid
);
void
engine_barrier
(
struct
engine
*
e
);
void
engine_compute_next_snapshot_time
(
struct
engine
*
e
);
void
engine_unskip
(
struct
engine
*
e
);
void
engine_drift_all
(
struct
engine
*
e
);
...
...
src/runner.c
View file @
a473067b
...
...
@@ -1754,7 +1754,7 @@ void *runner_main(void *data) {
while
(
1
)
{
/* Wait at the barrier. */
engine_barrier
(
e
,
r
->
id
);
engine_barrier
(
e
);
/* Re-set the pointer to the previous task, as there is none. */
struct
task
*
t
=
NULL
;
...
...
Write
Preview
Supports
Markdown
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