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
aa7f301f
Commit
aa7f301f
authored
9 years ago
by
Matthieu Schaller
Browse files
Options
Downloads
Patches
Plain Diff
No more dogsort
parent
a6992860
No related branches found
No related tags found
2 merge requests
!212
Gravity infrastructure
,
!172
[WIP] Self gravity (Barnes-Hut version)
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/runner.c
+143
-143
143 additions, 143 deletions
src/runner.c
with
143 additions
and
143 deletions
src/runner.c
+
143
−
143
View file @
aa7f301f
...
...
@@ -423,150 +423,150 @@ void runner_dosort(struct runner *r, struct cell *c, int flags, int clock) {
if
(
clock
)
TIMER_TOC
(
timer_dosort
);
}
void
runner_dogsort
(
struct
runner
*
r
,
struct
cell
*
c
,
int
flags
,
int
clock
)
{
struct
entry
*
finger
;
struct
entry
*
fingers
[
8
];
struct
gpart
*
gparts
=
c
->
gparts
;
struct
entry
*
gsort
;
int
j
,
k
,
count
=
c
->
gcount
;
int
i
,
ind
,
off
[
8
],
inds
[
8
],
temp_i
,
missing
;
// float shift[3];
float
buff
[
8
],
px
[
3
];
TIMER_TIC
/* Clean-up the flags, i.e. filter out what's already been sorted. */
flags
&=
~
c
->
gsorted
;
if
(
flags
==
0
)
return
;
/* start by allocating the entry arrays. */
if
(
c
->
gsort
==
NULL
||
c
->
gsortsize
<
count
)
{
if
(
c
->
gsort
!=
NULL
)
free
(
c
->
gsort
);
c
->
gsortsize
=
count
*
1
.
1
;
if
((
c
->
gsort
=
(
struct
entry
*
)
malloc
(
sizeof
(
struct
entry
)
*
(
c
->
gsortsize
+
1
)
*
13
))
==
NULL
)
error
(
"Failed to allocate sort memory."
);
}
gsort
=
c
->
gsort
;
/* Does this cell have any progeny? */
if
(
c
->
split
)
{
/* Fill in the gaps within the progeny. */
for
(
k
=
0
;
k
<
8
;
k
++
)
{
if
(
c
->
progeny
[
k
]
==
NULL
)
continue
;
missing
=
flags
&
~
c
->
progeny
[
k
]
->
gsorted
;
if
(
missing
)
runner_dogsort
(
r
,
c
->
progeny
[
k
],
missing
,
0
);
}
/* Loop over the 13 different sort arrays. */
for
(
j
=
0
;
j
<
13
;
j
++
)
{
/* Has this sort array been flagged? */
if
(
!
(
flags
&
(
1
<<
j
)))
continue
;
/* Init the particle index offsets. */
for
(
off
[
0
]
=
0
,
k
=
1
;
k
<
8
;
k
++
)
if
(
c
->
progeny
[
k
-
1
]
!=
NULL
)
off
[
k
]
=
off
[
k
-
1
]
+
c
->
progeny
[
k
-
1
]
->
gcount
;
else
off
[
k
]
=
off
[
k
-
1
];
/* Init the entries and indices. */
for
(
k
=
0
;
k
<
8
;
k
++
)
{
inds
[
k
]
=
k
;
if
(
c
->
progeny
[
k
]
!=
NULL
&&
c
->
progeny
[
k
]
->
gcount
>
0
)
{
fingers
[
k
]
=
&
c
->
progeny
[
k
]
->
gsort
[
j
*
(
c
->
progeny
[
k
]
->
gcount
+
1
)];
buff
[
k
]
=
fingers
[
k
]
->
d
;
off
[
k
]
=
off
[
k
];
}
else
buff
[
k
]
=
FLT_MAX
;
}
/* Sort the buffer. */
for
(
i
=
0
;
i
<
7
;
i
++
)
for
(
k
=
i
+
1
;
k
<
8
;
k
++
)
if
(
buff
[
inds
[
k
]]
<
buff
[
inds
[
i
]])
{
temp_i
=
inds
[
i
];
inds
[
i
]
=
inds
[
k
];
inds
[
k
]
=
temp_i
;
}
/* For each entry in the new sort list. */
finger
=
&
gsort
[
j
*
(
count
+
1
)];
for
(
ind
=
0
;
ind
<
count
;
ind
++
)
{
/* Copy the minimum into the new sort array. */
finger
[
ind
].
d
=
buff
[
inds
[
0
]];
finger
[
ind
].
i
=
fingers
[
inds
[
0
]]
->
i
+
off
[
inds
[
0
]];
/* Update the buffer. */
fingers
[
inds
[
0
]]
+=
1
;
buff
[
inds
[
0
]]
=
fingers
[
inds
[
0
]]
->
d
;
/* Find the smallest entry. */
for
(
k
=
1
;
k
<
8
&&
buff
[
inds
[
k
]]
<
buff
[
inds
[
k
-
1
]];
k
++
)
{
temp_i
=
inds
[
k
-
1
];
inds
[
k
-
1
]
=
inds
[
k
];
inds
[
k
]
=
temp_i
;
}
}
/* Merge. */
/* Add a sentinel. */
gsort
[
j
*
(
count
+
1
)
+
count
].
d
=
FLT_MAX
;
gsort
[
j
*
(
count
+
1
)
+
count
].
i
=
0
;
/* Mark as sorted. */
c
->
gsorted
|=
(
1
<<
j
);
}
/* loop over sort arrays. */
}
/* progeny? */
/* Otherwise, just sort. */
else
{
/* Fill the sort array. */
for
(
k
=
0
;
k
<
count
;
k
++
)
{
px
[
0
]
=
gparts
[
k
].
x
[
0
];
px
[
1
]
=
gparts
[
k
].
x
[
1
];
px
[
2
]
=
gparts
[
k
].
x
[
2
];
for
(
j
=
0
;
j
<
13
;
j
++
)
if
(
flags
&
(
1
<<
j
))
{
gsort
[
j
*
(
count
+
1
)
+
k
].
i
=
k
;
gsort
[
j
*
(
count
+
1
)
+
k
].
d
=
px
[
0
]
*
runner_shift
[
3
*
j
+
0
]
+
px
[
1
]
*
runner_shift
[
3
*
j
+
1
]
+
px
[
2
]
*
runner_shift
[
3
*
j
+
2
];
}
}
/* Add the sentinel and sort. */
for
(
j
=
0
;
j
<
13
;
j
++
)
if
(
flags
&
(
1
<<
j
))
{
gsort
[
j
*
(
count
+
1
)
+
count
].
d
=
FLT_MAX
;
gsort
[
j
*
(
count
+
1
)
+
count
].
i
=
0
;
runner_dosort_ascending
(
&
gsort
[
j
*
(
count
+
1
)],
count
);
c
->
gsorted
|=
(
1
<<
j
);
}
}
/* Verify the sorting. */
/* for ( j = 0 ; j < 13 ; j++ ) {
if ( !( flags & (1 << j) ) )
continue;
finger = &c->gsort[ j*(count + 1) ];
for ( k = 1 ; k < count ; k++ ) {
if ( finger[k].d < finger[k-1].d )
error( "Sorting failed, ascending array." );
if ( finger[k].i < 0 || finger[k].i >= count )
error( "Sorting failed, indices borked." );
}
} */
/* void runner_dogsort(struct runner *r, struct cell *c, int flags, int clock) { */
/* struct entry *finger; */
/* struct entry *fingers[8]; */
/* struct gpart *gparts = c->gparts; */
/* struct entry *gsort; */
/* int j, k, count = c->gcount; */
/* int i, ind, off[8], inds[8], temp_i, missing; */
/* // float shift[3]; */
/* float buff[8], px[3]; */
/* TIMER_TIC */
/* /\* Clean-up the flags, i.e. filter out what's already been sorted. *\/ */
/* flags &= ~c->gsorted; */
/* if (flags == 0) return; */
/* /\* start by allocating the entry arrays. *\/ */
/* if (c->gsort == NULL || c->gsortsize < count) { */
/* if (c->gsort != NULL) free(c->gsort); */
/* c->gsortsize = count * 1.1; */
/* if ((c->gsort = (struct entry *)malloc(sizeof(struct entry) * */
/* (c->gsortsize + 1) * 13)) == NULL) */
/* error("Failed to allocate sort memory."); */
/* } */
/* gsort = c->gsort; */
/* /\* Does this cell have any progeny? *\/ */
/* if (c->split) { */
/* /\* Fill in the gaps within the progeny. *\/ */
/* for (k = 0; k < 8; k++) { */
/* if (c->progeny[k] == NULL) continue; */
/* missing = flags & ~c->progeny[k]->gsorted; */
/* if (missing) runner_dogsort(r, c->progeny[k], missing, 0); */
/* } */
/* /\* Loop over the 13 different sort arrays. *\/ */
/* for (j = 0; j < 13; j++) { */
/* /\* Has this sort array been flagged? *\/ */
/* if (!(flags & (1 << j))) continue; */
/* /\* Init the particle index offsets. *\/ */
/* for (off[0] = 0, k = 1; k < 8; k++) */
/* if (c->progeny[k - 1] != NULL) */
/* off[k] = off[k - 1] + c->progeny[k - 1]->gcount; */
/* else */
/* off[k] = off[k - 1]; */
/* /\* Init the entries and indices. *\/ */
/* for (k = 0; k < 8; k++) { */
/* inds[k] = k; */
/* if (c->progeny[k] != NULL && c->progeny[k]->gcount > 0) { */
/* fingers[k] = &c->progeny[k]->gsort[j * (c->progeny[k]->gcount + 1)]; */
/* buff[k] = fingers[k]->d; */
/* off[k] = off[k]; */
/* } else */
/* buff[k] = FLT_MAX; */
/* } */
/* /\* Sort the buffer. *\/ */
/* for (i = 0; i < 7; i++) */
/* for (k = i + 1; k < 8; k++) */
/* if (buff[inds[k]] < buff[inds[i]]) { */
/* temp_i = inds[i]; */
/* inds[i] = inds[k]; */
/* inds[k] = temp_i; */
/* } */
/* /\* For each entry in the new sort list. *\/ */
/* finger = &gsort[j * (count + 1)]; */
/* for (ind = 0; ind < count; ind++) { */
/* /\* Copy the minimum into the new sort array. *\/ */
/* finger[ind].d = buff[inds[0]]; */
/* finger[ind].i = fingers[inds[0]]->i + off[inds[0]]; */
/* /\* Update the buffer. *\/ */
/* fingers[inds[0]] += 1; */
/* buff[inds[0]] = fingers[inds[0]]->d; */
/* /\* Find the smallest entry. *\/ */
/* for (k = 1; k < 8 && buff[inds[k]] < buff[inds[k - 1]]; k++) { */
/* temp_i = inds[k - 1]; */
/* inds[k - 1] = inds[k]; */
/* inds[k] = temp_i; */
/* } */
/* } /\* Merge. *\/ */
/* /\* Add a sentinel. *\/ */
/* gsort[j * (count + 1) + count].d = FLT_MAX; */
/* gsort[j * (count + 1) + count].i = 0; */
/* /\* Mark as sorted. *\/ */
/* c->gsorted |= (1 << j); */
/* } /\* loop over sort arrays. *\/ */
/* } /\* progeny? *\/ */
/* /\* Otherwise, just sort. *\/ */
/* else { */
/* /\* Fill the sort array. *\/ */
/* for (k = 0; k < count; k++) { */
/* px[0] = gparts[k].x[0]; */
/* px[1] = gparts[k].x[1]; */
/* px[2] = gparts[k].x[2]; */
/* for (j = 0; j < 13; j++) */
/* if (flags & (1 << j)) { */
/* gsort[j * (count + 1) + k].i = k; */
/* gsort[j * (count + 1) + k].d = px[0] * runner_shift[3 * j + 0] + */
/* px[1] * runner_shift[3 * j + 1] + */
/* px[2] * runner_shift[3 * j + 2]; */
/* } */
/* } */
/* /\* Add the sentinel and sort. *\/ */
/* for (j = 0; j < 13; j++) */
/* if (flags & (1 << j)) { */
/* gsort[j * (count + 1) + count].d = FLT_MAX; */
/* gsort[j * (count + 1) + count].i = 0; */
/* runner_dosort_ascending(&gsort[j * (count + 1)], count); */
/* c->gsorted |= (1 << j); */
/* } */
/* } */
if
(
clock
)
TIMER_TOC
(
timer_dosort
);
}
/* /\* Verify the sorting. *\/ */
/* /\* for ( j = 0 ; j < 13 ; j++ ) { */
/* if ( !( flags & (1 << j) ) ) */
/* continue; */
/* finger = &c->gsort[ j*(count + 1) ]; */
/* for ( k = 1 ; k < count ; k++ ) { */
/* if ( finger[k].d < finger[k-1].d ) */
/* error( "Sorting failed, ascending array." ); */
/* if ( finger[k].i < 0 || finger[k].i >= count ) */
/* error( "Sorting failed, indices borked." ); */
/* } */
/* } *\/ */
/* if (clock) TIMER_TOC(timer_dosort); */
/* } */
/**
* @brief Initialize the particles before the density calculation
...
...
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