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
e3691f70
Commit
e3691f70
authored
8 years ago
by
Matthieu Schaller
Browse files
Options
Downloads
Patches
Plain Diff
task_overlap() can now deal with gravity tasks
parent
765a58c6
No related branches found
No related tags found
2 merge requests
!212
Gravity infrastructure
,
!172
[WIP] Self gravity (Barnes-Hut version)
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/task.c
+145
-22
145 additions, 22 deletions
src/task.c
src/task.h
+11
-0
11 additions, 0 deletions
src/task.h
with
156 additions
and
22 deletions
src/task.c
+
145
−
22
View file @
e3691f70
...
@@ -59,7 +59,7 @@ const char *subtaskID_names[task_type_count] = {"none", "density", "force",
...
@@ -59,7 +59,7 @@ const char *subtaskID_names[task_type_count] = {"none", "density", "force",
/**
/**
* @brief Computes the overlap between the parts array of two given cells.
* @brief Computes the overlap between the parts array of two given cells.
*/
*/
size_t
task_cell_overlap
(
const
struct
cell
*
ci
,
const
struct
cell
*
cj
)
{
size_t
task_cell_overlap
_part
(
const
struct
cell
*
ci
,
const
struct
cell
*
cj
)
{
if
(
ci
==
NULL
||
cj
==
NULL
)
return
0
;
if
(
ci
==
NULL
||
cj
==
NULL
)
return
0
;
if
(
ci
->
parts
<=
cj
->
parts
&&
if
(
ci
->
parts
<=
cj
->
parts
&&
ci
->
parts
+
ci
->
count
>=
cj
->
parts
+
cj
->
count
)
{
ci
->
parts
+
ci
->
count
>=
cj
->
parts
+
cj
->
count
)
{
...
@@ -71,6 +71,95 @@ size_t task_cell_overlap(const struct cell *ci, const struct cell *cj) {
...
@@ -71,6 +71,95 @@ size_t task_cell_overlap(const struct cell *ci, const struct cell *cj) {
return
0
;
return
0
;
}
}
/**
* @brief Computes the overlap between the gparts array of two given cells.
*/
size_t
task_cell_overlap_gpart
(
const
struct
cell
*
ci
,
const
struct
cell
*
cj
)
{
if
(
ci
==
NULL
||
cj
==
NULL
)
return
0
;
if
(
ci
->
gparts
<=
cj
->
gparts
&&
ci
->
gparts
+
ci
->
gcount
>=
cj
->
gparts
+
cj
->
gcount
)
{
return
cj
->
gcount
;
}
else
if
(
cj
->
gparts
<=
ci
->
gparts
&&
cj
->
gparts
+
cj
->
gcount
>=
ci
->
gparts
+
ci
->
gcount
)
{
return
ci
->
gcount
;
}
return
0
;
}
/**
* @brief Returns the #task_actions for a given task.
*
* @param t The #task.
*/
enum
task_actions
task_acts_on
(
const
struct
task
*
t
)
{
switch
(
t
->
type
)
{
case
task_type_none
:
return
task_action_none
;
break
;
case
task_type_sort
:
case
task_type_ghost
:
return
task_action_part
;
break
;
case
task_type_self
:
case
task_type_pair
:
case
task_type_sub_self
:
case
task_type_sub_pair
:
switch
(
t
->
subtype
)
{
case
task_subtype_density
:
case
task_subtype_force
:
return
task_action_part
;
break
;
case
task_subtype_grav
:
return
task_action_gpart
;
break
;
default:
error
(
"Unknow task_action for task"
);
return
task_action_none
;
break
;
}
break
;
case
task_type_init
:
case
task_type_drift
:
case
task_type_kick
:
case
task_type_kick_fixdt
:
case
task_type_send
:
case
task_type_recv
:
return
task_action_all
;
break
;
case
task_type_grav_gather_m
:
case
task_type_grav_fft
:
case
task_type_grav_mm
:
case
task_type_grav_up
:
return
task_action_multipole
;
break
;
case
task_type_grav_external
:
return
task_action_gpart
;
break
;
case
task_type_part_sort
:
case
task_type_gpart_sort
:
case
task_type_split_cell
:
case
task_type_rewait
:
return
task_action_none
;
break
;
default:
error
(
"Unknow task_action for task"
);
return
task_action_none
;
break
;
}
}
/**
/**
* @brief Compute the Jaccard similarity of the data used by two
* @brief Compute the Jaccard similarity of the data used by two
* different tasks.
* different tasks.
...
@@ -79,29 +168,63 @@ size_t task_cell_overlap(const struct cell *ci, const struct cell *cj) {
...
@@ -79,29 +168,63 @@ size_t task_cell_overlap(const struct cell *ci, const struct cell *cj) {
* @param tb The second #task.
* @param tb The second #task.
*/
*/
float
task_overlap
(
const
struct
task
*
ta
,
const
struct
task
*
tb
)
{
float
task_overlap
(
const
struct
task
*
ta
,
const
struct
task
*
tb
)
{
if
(
ta
==
NULL
||
tb
==
NULL
)
return
0
.
f
;
const
enum
task_actions
ta_act
=
task_acts_on
(
ta
);
const
enum
task_actions
tb_act
=
task_acts_on
(
tb
);
/* First check if any of the two tasks are of a type that don't
/* First check if any of the two tasks are of a type that don't
use cells. */
use cells. */
if
(
ta
==
NULL
||
tb
==
NULL
||
ta
->
type
==
task_type_none
||
if
(
ta_act
==
task_action_none
||
tb_act
==
task_action_none
)
return
0
.
f
;
ta
->
type
==
task_type_part_sort
||
ta
->
type
==
task_type_gpart_sort
||
ta
->
type
==
task_type_split_cell
||
ta
->
type
==
task_type_rewait
||
const
int
ta_part
=
(
ta_act
==
task_action_part
||
ta_act
==
task_action_all
);
tb
->
type
==
task_type_none
||
tb
->
type
==
task_type_part_sort
||
const
int
ta_gpart
=
tb
->
type
==
task_type_gpart_sort
||
tb
->
type
==
task_type_split_cell
||
(
ta_act
==
task_action_gpart
||
ta_act
==
task_action_all
);
tb
->
type
==
task_type_rewait
)
const
int
tb_part
=
(
tb_act
==
task_action_part
||
tb_act
==
task_action_all
);
return
0
.
0
f
;
const
int
tb_gpart
=
(
tb_act
==
task_action_gpart
||
tb_act
==
task_action_all
);
/* Compute the union of the cell data. */
size_t
size_union
=
0
;
/* In the case where both tasks act on parts */
if
(
ta
->
ci
!=
NULL
)
size_union
+=
ta
->
ci
->
count
;
if
(
ta_part
&&
tb_part
)
{
if
(
ta
->
cj
!=
NULL
)
size_union
+=
ta
->
cj
->
count
;
if
(
tb
->
ci
!=
NULL
)
size_union
+=
tb
->
ci
->
count
;
/* Compute the union of the cell data. */
if
(
tb
->
cj
!=
NULL
)
size_union
+=
tb
->
cj
->
count
;
size_t
size_union
=
0
;
if
(
ta
->
ci
!=
NULL
)
size_union
+=
ta
->
ci
->
count
;
/* Compute the intersection of the cell data. */
if
(
ta
->
cj
!=
NULL
)
size_union
+=
ta
->
cj
->
count
;
const
size_t
size_intersect
=
if
(
tb
->
ci
!=
NULL
)
size_union
+=
tb
->
ci
->
count
;
task_cell_overlap
(
ta
->
ci
,
tb
->
ci
)
+
task_cell_overlap
(
ta
->
ci
,
tb
->
cj
)
+
if
(
tb
->
cj
!=
NULL
)
size_union
+=
tb
->
cj
->
count
;
task_cell_overlap
(
ta
->
cj
,
tb
->
ci
)
+
task_cell_overlap
(
ta
->
cj
,
tb
->
cj
);
/* Compute the intersection of the cell data. */
return
((
float
)
size_intersect
)
/
(
size_union
-
size_intersect
);
const
size_t
size_intersect
=
task_cell_overlap_part
(
ta
->
ci
,
tb
->
ci
)
+
task_cell_overlap_part
(
ta
->
ci
,
tb
->
cj
)
+
task_cell_overlap_part
(
ta
->
cj
,
tb
->
ci
)
+
task_cell_overlap_part
(
ta
->
cj
,
tb
->
cj
);
return
((
float
)
size_intersect
)
/
(
size_union
-
size_intersect
);
}
/* In the case where both tasks act on gparts */
else
if
(
ta_gpart
&&
tb_gpart
)
{
/* Compute the union of the cell data. */
size_t
size_union
=
0
;
if
(
ta
->
ci
!=
NULL
)
size_union
+=
ta
->
ci
->
gcount
;
if
(
ta
->
cj
!=
NULL
)
size_union
+=
ta
->
cj
->
gcount
;
if
(
tb
->
ci
!=
NULL
)
size_union
+=
tb
->
ci
->
gcount
;
if
(
tb
->
cj
!=
NULL
)
size_union
+=
tb
->
cj
->
gcount
;
/* Compute the intersection of the cell data. */
const
size_t
size_intersect
=
task_cell_overlap_gpart
(
ta
->
ci
,
tb
->
ci
)
+
task_cell_overlap_gpart
(
ta
->
ci
,
tb
->
cj
)
+
task_cell_overlap_gpart
(
ta
->
cj
,
tb
->
ci
)
+
task_cell_overlap_gpart
(
ta
->
cj
,
tb
->
cj
);
return
((
float
)
size_intersect
)
/
(
size_union
-
size_intersect
);
}
/* Else, no overlap */
return
0
.
f
;
}
}
/**
/**
...
...
This diff is collapsed.
Click to expand it.
src/task.h
+
11
−
0
View file @
e3691f70
...
@@ -70,6 +70,16 @@ enum task_subtypes {
...
@@ -70,6 +70,16 @@ enum task_subtypes {
task_subtype_count
task_subtype_count
};
};
/* The kind of action the task perform */
enum
task_actions
{
task_action_none
,
task_action_part
,
task_action_gpart
,
task_action_all
,
task_action_multipole
,
task_action_count
};
extern
const
char
*
subtaskID_names
[];
extern
const
char
*
subtaskID_names
[];
/* Data of a task. */
/* Data of a task. */
...
@@ -102,5 +112,6 @@ int task_lock(struct task *t);
...
@@ -102,5 +112,6 @@ int task_lock(struct task *t);
void
task_print_mask
(
unsigned
int
mask
);
void
task_print_mask
(
unsigned
int
mask
);
void
task_print_submask
(
unsigned
int
submask
);
void
task_print_submask
(
unsigned
int
submask
);
void
task_do_rewait
(
struct
task
*
t
);
void
task_do_rewait
(
struct
task
*
t
);
enum
task_actions
task_acts_on
(
const
struct
task
*
t
);
#endif
/* SWIFT_TASK_H */
#endif
/* SWIFT_TASK_H */
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