Skip to content
GitLab
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
80f9ed1c
Commit
80f9ed1c
authored
Jan 19, 2017
by
Matthieu Schaller
Browse files
Correctly sort the star particles
parent
6e3da355
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/cell.c
View file @
80f9ed1c
...
...
@@ -214,6 +214,7 @@ int cell_pack(struct cell *c, struct pcell *pc) {
pc
->
h_max
=
c
->
h_max
;
pc
->
ti_end_min
=
c
->
ti_end_min
;
pc
->
ti_end_max
=
c
->
ti_end_max
;
pc
->
ti_old
=
c
->
ti_old
;
pc
->
count
=
c
->
count
;
pc
->
gcount
=
c
->
gcount
;
c
->
tag
=
pc
->
tag
=
atomic_inc
(
&
cell_next_tag
)
%
cell_max_tag
;
...
...
@@ -595,8 +596,8 @@ void cell_split(struct cell *c, ptrdiff_t parts_offset, ptrdiff_t sparts_offset,
/* Fill the buffer with the indices. */
for
(
int
k
=
0
;
k
<
count
;
k
++
)
{
const
int
bid
=
(
parts
[
k
].
x
[
0
]
>
pivot
[
0
])
*
4
+
(
parts
[
k
].
x
[
1
]
>
pivot
[
1
])
*
2
+
(
parts
[
k
].
x
[
2
]
>
pivot
[
2
]);
const
int
bid
=
(
buff
[
k
].
x
[
0
]
>
pivot
[
0
])
*
4
+
(
buff
[
k
].
x
[
1
]
>
pivot
[
1
])
*
2
+
(
buff
[
k
].
x
[
2
]
>
pivot
[
2
]);
bucket_count
[
bid
]
++
;
buff
[
k
].
ind
=
bid
;
}
...
...
@@ -616,6 +617,7 @@ void cell_split(struct cell *c, ptrdiff_t parts_offset, ptrdiff_t sparts_offset,
if
(
bid
!=
bucket
)
{
struct
part
part
=
parts
[
k
];
struct
xpart
xpart
=
xparts
[
k
];
struct
cell_buff
temp_buff
=
buff
[
k
];
while
(
bid
!=
bucket
)
{
int
j
=
bucket_offset
[
bid
]
+
bucket_count
[
bid
]
++
;
while
(
buff
[
j
].
ind
==
bid
)
{
...
...
@@ -624,11 +626,12 @@ void cell_split(struct cell *c, ptrdiff_t parts_offset, ptrdiff_t sparts_offset,
}
memswap
(
&
parts
[
j
],
&
part
,
sizeof
(
struct
part
));
memswap
(
&
xparts
[
j
],
&
xpart
,
sizeof
(
struct
xpart
));
memswap
(
&
buff
[
j
],
&
bid
,
sizeof
(
int
));
memswap
(
&
buff
[
j
],
&
temp_buff
,
sizeof
(
struct
cell_buff
));
bid
=
temp_buff
.
ind
;
}
parts
[
k
]
=
part
;
xparts
[
k
]
=
xpart
;
buff
[
k
]
.
ind
=
bid
;
buff
[
k
]
=
temp_buff
;
}
bucket_count
[
bid
]
++
;
}
...
...
@@ -646,6 +649,14 @@ void cell_split(struct cell *c, ptrdiff_t parts_offset, ptrdiff_t sparts_offset,
part_relink_gparts_to_parts
(
parts
,
count
,
parts_offset
);
#ifdef SWIFT_DEBUG_CHECKS
/* Check that the buffs are OK. */
for
(
int
k
=
1
;
k
<
count
;
k
++
)
{
if
(
buff
[
k
].
ind
<
buff
[
k
-
1
].
ind
)
error
(
"Buff not sorted."
);
if
(
buff
[
k
].
x
[
0
]
!=
parts
[
k
].
x
[
0
]
||
buff
[
k
].
x
[
1
]
!=
parts
[
k
].
x
[
1
]
||
buff
[
k
].
x
[
2
]
!=
parts
[
k
].
x
[
2
])
error
(
"Inconsistent buff contents (k=%i)."
,
k
);
}
/* Verify that _all_ the parts have been assigned to a cell. */
for
(
int
k
=
1
;
k
<
8
;
k
++
)
if
(
&
c
->
progeny
[
k
-
1
]
->
parts
[
c
->
progeny
[
k
-
1
]
->
count
]
!=
...
...
@@ -672,6 +683,31 @@ void cell_split(struct cell *c, ptrdiff_t parts_offset, ptrdiff_t sparts_offset,
c
->
progeny
[
2
]
->
parts
[
k
].
x
[
1
]
<=
pivot
[
1
]
||
c
->
progeny
[
2
]
->
parts
[
k
].
x
[
2
]
>
pivot
[
2
])
error
(
"Sorting failed (progeny=2)."
);
for
(
int
k
=
0
;
k
<
c
->
progeny
[
3
]
->
count
;
k
++
)
if
(
c
->
progeny
[
3
]
->
parts
[
k
].
x
[
0
]
>
pivot
[
0
]
||
c
->
progeny
[
3
]
->
parts
[
k
].
x
[
1
]
<=
pivot
[
1
]
||
c
->
progeny
[
3
]
->
parts
[
k
].
x
[
2
]
<=
pivot
[
2
])
error
(
"Sorting failed (progeny=3)."
);
for
(
int
k
=
0
;
k
<
c
->
progeny
[
4
]
->
count
;
k
++
)
if
(
c
->
progeny
[
4
]
->
parts
[
k
].
x
[
0
]
<=
pivot
[
0
]
||
c
->
progeny
[
4
]
->
parts
[
k
].
x
[
1
]
>
pivot
[
1
]
||
c
->
progeny
[
4
]
->
parts
[
k
].
x
[
2
]
>
pivot
[
2
])
error
(
"Sorting failed (progeny=4)."
);
for
(
int
k
=
0
;
k
<
c
->
progeny
[
5
]
->
count
;
k
++
)
if
(
c
->
progeny
[
5
]
->
parts
[
k
].
x
[
0
]
<=
pivot
[
0
]
||
c
->
progeny
[
5
]
->
parts
[
k
].
x
[
1
]
>
pivot
[
1
]
||
c
->
progeny
[
5
]
->
parts
[
k
].
x
[
2
]
<=
pivot
[
2
])
error
(
"Sorting failed (progeny=5)."
);
for
(
int
k
=
0
;
k
<
c
->
progeny
[
6
]
->
count
;
k
++
)
if
(
c
->
progeny
[
6
]
->
parts
[
k
].
x
[
0
]
<=
pivot
[
0
]
||
c
->
progeny
[
6
]
->
parts
[
k
].
x
[
1
]
<=
pivot
[
1
]
||
c
->
progeny
[
6
]
->
parts
[
k
].
x
[
2
]
>
pivot
[
2
])
error
(
"Sorting failed (progeny=6)."
);
for
(
int
k
=
0
;
k
<
c
->
progeny
[
7
]
->
count
;
k
++
)
if
(
c
->
progeny
[
7
]
->
parts
[
k
].
x
[
0
]
<=
pivot
[
0
]
||
c
->
progeny
[
7
]
->
parts
[
k
].
x
[
1
]
<=
pivot
[
1
]
||
c
->
progeny
[
7
]
->
parts
[
k
].
x
[
2
]
<=
pivot
[
2
])
error
(
"Sorting failed (progeny=7)."
);
#endif
/* Now do the same song and dance for the sparts. */
...
...
@@ -725,18 +761,17 @@ void cell_split(struct cell *c, ptrdiff_t parts_offset, ptrdiff_t sparts_offset,
/* Re-link the gparts. */
if
(
scount
>
0
&&
gcount
>
0
)
part_relink_gparts_to_sparts
(
sparts
,
count
,
sparts_offset
);
part_relink_gparts_to_sparts
(
sparts
,
s
count
,
sparts_offset
);
/* Finally, do the same song and dance for the gparts. */
for
(
int
k
=
0
;
k
<
8
;
k
++
)
bucket_count
[
k
]
=
0
;
/* Fill the buffer with the indices. */
for
(
int
k
=
0
;
k
<
gcount
;
k
++
)
{
const
int
bid
=
(
gparts
[
k
].
x
[
0
]
>
pivot
[
0
])
*
4
+
(
gparts
[
k
].
x
[
1
]
>
pivot
[
1
])
*
2
+
(
gparts
[
k
].
x
[
2
]
>
pivot
[
2
]);
const
int
bid
=
(
gbuff
[
k
].
x
[
0
]
>
pivot
[
0
])
*
4
+
(
gbuff
[
k
].
x
[
1
]
>
pivot
[
1
])
*
2
+
(
gbuff
[
k
].
x
[
2
]
>
pivot
[
2
]);
bucket_count
[
bid
]
++
;
buff
[
k
].
ind
=
bid
;
g
buff
[
k
].
ind
=
bid
;
}
/* Set the buffer offsets. */
...
...
@@ -750,20 +785,22 @@ void cell_split(struct cell *c, ptrdiff_t parts_offset, ptrdiff_t sparts_offset,
for
(
int
bucket
=
0
;
bucket
<
8
;
bucket
++
)
{
for
(
int
k
=
bucket_offset
[
bucket
]
+
bucket_count
[
bucket
];
k
<
bucket_offset
[
bucket
+
1
];
k
++
)
{
int
bid
=
buff
[
k
].
ind
;
int
bid
=
g
buff
[
k
].
ind
;
if
(
bid
!=
bucket
)
{
struct
gpart
gpart
=
gparts
[
k
];
struct
cell_buff
temp_buff
=
gbuff
[
k
];
while
(
bid
!=
bucket
)
{
int
j
=
bucket_offset
[
bid
]
+
bucket_count
[
bid
]
++
;
while
(
buff
[
j
].
ind
==
bid
)
{
while
(
g
buff
[
j
].
ind
==
bid
)
{
j
++
;
bucket_count
[
bid
]
++
;
}
memswap
(
&
gparts
[
j
],
&
gpart
,
sizeof
(
struct
gpart
));
memswap
(
&
buff
[
j
],
&
bid
,
sizeof
(
int
));
memswap
(
&
gbuff
[
j
],
&
temp_buff
,
sizeof
(
struct
cell_buff
));
bid
=
temp_buff
.
ind
;
}
gparts
[
k
]
=
gpart
;
buff
[
k
]
.
ind
=
bid
;
g
buff
[
k
]
=
temp_buff
;
}
bucket_count
[
bid
]
++
;
}
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment