Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SWIFTsim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SWIFT
SWIFTsim
Commits
ae3bde0a
Commit
ae3bde0a
authored
9 years ago
by
Pedro Gonnet
Browse files
Options
Downloads
Patches
Plain Diff
fixed a silly inefficiency that made scheduler_ranktasks run in o(n^2) instead of o(n).
parent
898d3ae6
No related branches found
No related tags found
1 merge request
!176
Tasks cleanup
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/scheduler.c
+24
-22
24 additions, 22 deletions
src/scheduler.c
with
24 additions
and
22 deletions
src/scheduler.c
+
24
−
22
View file @
ae3bde0a
...
@@ -768,47 +768,49 @@ void scheduler_ranktasks(struct scheduler *s) {
...
@@ -768,47 +768,49 @@ void scheduler_ranktasks(struct scheduler *s) {
/* Run through the tasks and get all the waits right. */
/* Run through the tasks and get all the waits right. */
for
(
int
k
=
0
;
k
<
nr_tasks
;
k
++
)
{
for
(
int
k
=
0
;
k
<
nr_tasks
;
k
++
)
{
tid
[
k
]
=
k
;
for
(
int
j
=
0
;
j
<
tasks
[
k
].
nr_unlock_tasks
;
j
++
)
for
(
int
j
=
0
;
j
<
tasks
[
k
].
nr_unlock_tasks
;
j
++
)
tasks
[
k
].
unlock_tasks
[
j
]
->
wait
+=
1
;
tasks
[
k
].
unlock_tasks
[
j
]
->
wait
+=
1
;
}
}
/* Load the tids of tasks with no waits. */
int
left
=
0
;
for
(
int
k
=
0
;
k
<
nr_tasks
;
k
++
)
if
(
tasks
[
k
].
wait
==
0
)
{
tid
[
left
]
=
k
;
left
+=
1
;
}
/* Main loop. */
/* Main loop. */
for
(
int
j
=
0
,
rank
=
0
,
left
=
0
;
left
<
nr_tasks
;
rank
++
)
{
for
(
int
j
=
0
,
rank
=
0
;
left
<
nr_tasks
;
rank
++
)
{
/* Load the tids of tasks with no waits. */
for
(
int
k
=
left
;
k
<
nr_tasks
;
k
++
)
if
(
tasks
[
tid
[
k
]].
wait
==
0
)
{
int
temp
=
tid
[
j
];
tid
[
j
]
=
tid
[
k
];
tid
[
k
]
=
temp
;
j
+=
1
;
}
/* Did we get anything? */
/* Did we get anything? */
if
(
j
==
left
)
error
(
"Unsatisfiable task dependencies detected."
);
if
(
j
==
left
)
error
(
"Unsatisfiable task dependencies detected."
);
const
int
left_old
=
left
;
/* Unlock the next layer of tasks. */
/* Unlock the next layer of tasks. */
for
(
int
i
=
left
;
i
<
j
;
i
++
)
{
for
(
;
j
<
left_old
;
j
++
)
{
struct
task
*
t
=
&
tasks
[
tid
[
i
]];
struct
task
*
t
=
&
tasks
[
tid
[
j
]];
t
->
rank
=
rank
;
t
->
rank
=
rank
;
tid
[
i
]
=
t
-
tasks
;
if
(
tid
[
i
]
>=
nr_tasks
)
error
(
"Task index overshoot."
);
/* message( "task %i of type %s has rank %i." , i ,
/* message( "task %i of type %s has rank %i." , i ,
(t->type == task_type_self) ? "self" : (t->type == task_type_pair) ?
(t->type == task_type_self) ? "self" : (t->type == task_type_pair) ?
"pair" : "sort" , rank ); */
"pair" : "sort" , rank ); */
for
(
int
k
=
0
;
k
<
t
->
nr_unlock_tasks
;
k
++
)
for
(
int
k
=
0
;
k
<
t
->
nr_unlock_tasks
;
k
++
)
{
t
->
unlock_tasks
[
k
]
->
wait
-=
1
;
struct
task
*
u
=
t
->
unlock_tasks
[
k
];
if
(
--
u
->
wait
==
0
)
{
tid
[
left
]
=
u
-
tasks
;
left
+=
1
;
}
}
}
}
/*
The new left (no, not tony
). */
/*
Move back to the old left (like Sanders
). */
left
=
j
;
j
=
left_old
;
}
}
/* Verify that the tasks were ranked correctly. */
/* Verify that the tasks were ranked correctly. */
/*
for ( k = 1
; k < s->nr_tasks
; k++
)
for
(
int
k
=
1
;
k
<
s
->
nr_tasks
;
k
++
)
if (
tasks[
tid[k
-
1]
].rank > tasks[
tid[k
-
1]
].rank
)
if
(
tasks
[
tid
[
k
-
1
]].
rank
>
tasks
[
tid
[
k
-
1
]].
rank
)
error(
"Task ranking failed."
);
*/
error
(
"Task ranking failed."
);
}
}
/**
/**
...
...
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