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
2d1d19b4
Commit
2d1d19b4
authored
9 years ago
by
Peter W. Draper
Browse files
Options
Downloads
Patches
Plain Diff
First attempt at integration
parent
0a66cb8a
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!136
Master
,
!76
Add new initial partition schemes and extend repartition ones.
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/Makefile.am
+2
-2
2 additions, 2 deletions
src/Makefile.am
src/engine.c
+16
-12
16 additions, 12 deletions
src/engine.c
src/poisson_disc.c
+39
-35
39 additions, 35 deletions
src/poisson_disc.c
src/poisson_disc.h
+25
-0
25 additions, 0 deletions
src/poisson_disc.h
with
82 additions
and
49 deletions
src/Makefile.am
+
2
−
2
View file @
2d1d19b4
...
@@ -35,13 +35,13 @@ endif
...
@@ -35,13 +35,13 @@ endif
# List required headers
# List required headers
include_HEADERS
=
space.h runner.h queue.h task.h lock.h cell.h part.h const.h
\
include_HEADERS
=
space.h runner.h queue.h task.h lock.h cell.h part.h const.h
\
engine.h swift.h serial_io.h timers.h debug.h scheduler.h proxy.h parallel_io.h
\
engine.h swift.h serial_io.h timers.h debug.h scheduler.h proxy.h parallel_io.h
\
common_io.h single_io.h multipole.h map.h tools.h
common_io.h single_io.h multipole.h map.h tools.h
poisson_disc.h
# Common source files
# Common source files
AM_SOURCES
=
space.c runner.c queue.c task.c cell.c engine.c
\
AM_SOURCES
=
space.c runner.c queue.c task.c cell.c engine.c
\
serial_io.c timers.c debug.c scheduler.c proxy.c parallel_io.c
\
serial_io.c timers.c debug.c scheduler.c proxy.c parallel_io.c
\
units.c common_io.c single_io.c multipole.c version.c map.c
\
units.c common_io.c single_io.c multipole.c version.c map.c
\
kernel.c tools.c
kernel.c tools.c
poisson_disc.c
# Include files for distribution, not installation.
# Include files for distribution, not installation.
noinst_HEADERS
=
atomic.h cycle.h error.h inline.h kernel.h vector.h
\
noinst_HEADERS
=
atomic.h cycle.h error.h inline.h kernel.h vector.h
\
...
...
This diff is collapsed.
Click to expand it.
src/engine.c
+
16
−
12
View file @
2d1d19b4
...
@@ -48,6 +48,7 @@
...
@@ -48,6 +48,7 @@
#include
"debug.h"
#include
"debug.h"
#include
"error.h"
#include
"error.h"
#include
"timers.h"
#include
"timers.h"
#include
"poisson_disc.h"
#ifdef LEGACY_GADGET2_SPH
#ifdef LEGACY_GADGET2_SPH
#include
"runner_iact_legacy.h"
#include
"runner_iact_legacy.h"
...
@@ -2071,24 +2072,27 @@ void engine_makeproxies(struct engine *e) {
...
@@ -2071,24 +2072,27 @@ void engine_makeproxies(struct engine *e) {
void
engine_split
(
struct
engine
*
e
,
int
*
grid
)
{
void
engine_split
(
struct
engine
*
e
,
int
*
grid
)
{
int
j
,
k
;
//
int j, k;
int
ind
[
3
];
//
int ind[3];
struct
space
*
s
=
e
->
s
;
struct
space
*
s
=
e
->
s
;
struct
cell
*
c
;
//
struct cell *c;
/* If we've got the wrong number of nodes, fail. */
/* If we've got the wrong number of nodes, fail. */
if
(
e
->
nr_nodes
!=
grid
[
0
]
*
grid
[
1
]
*
grid
[
2
])
//
if (e->nr_nodes != grid[0] * grid[1] * grid[2])
error
(
"Grid size does not match number of nodes."
);
//
error("Grid size does not match number of nodes.");
/* Run through the cells and set their nodeID. */
/* Run through the cells and set their nodeID. */
// message("s->dim = [%e,%e,%e]", s->dim[0], s->dim[1], s->dim[2]);
// message("s->dim = [%e,%e,%e]", s->dim[0], s->dim[1], s->dim[2]);
for
(
k
=
0
;
k
<
s
->
nr_cells
;
k
++
)
{
//for (k = 0; k < s->nr_cells; k++) {
c
=
&
s
->
cells
[
k
];
// c = &s->cells[k];
for
(
j
=
0
;
j
<
3
;
j
++
)
ind
[
j
]
=
c
->
loc
[
j
]
/
s
->
dim
[
j
]
*
grid
[
j
];
// for (j = 0; j < 3; j++) ind[j] = c->loc[j] / s->dim[j] * grid[j];
c
->
nodeID
=
ind
[
0
]
+
grid
[
0
]
*
(
ind
[
1
]
+
grid
[
1
]
*
ind
[
2
]);
// c->nodeID = ind[0] + grid[0] * (ind[1] + grid[1] * ind[2]);
// message("cell at [%e,%e,%e]: ind = [%i,%i,%i], nodeID = %i", c->loc[0],
// // message("cell at [%e,%e,%e]: ind = [%i,%i,%i], nodeID = %i", c->loc[0],
// c->loc[1], c->loc[2], ind[0], ind[1], ind[2], c->nodeID);
// // c->loc[1], c->loc[2], ind[0], ind[1], ind[2], c->nodeID);
}
//}
if
(
!
poisson_split
(
s
,
e
->
nr_nodes
)
)
error
(
"Failed to partition cells"
);
/* Make the proxies. */
/* Make the proxies. */
engine_makeproxies
(
e
);
engine_makeproxies
(
e
);
...
...
This diff is collapsed.
Click to expand it.
src/poisson_disc.c
+
39
−
35
View file @
2d1d19b4
...
@@ -42,6 +42,7 @@
...
@@ -42,6 +42,7 @@
/* Local headers. */
/* Local headers. */
#include
"error.h"
#include
"error.h"
#include
"poisson_disc.h"
/* Useful defines. */
/* Useful defines. */
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
...
@@ -211,7 +212,8 @@ void poisson_free(struct grid_data *grid) {
...
@@ -211,7 +212,8 @@ void poisson_free(struct grid_data *grid) {
* @param k number of attempts to pick an unmarked position (30 is a good
* @param k number of attempts to pick an unmarked position (30 is a good
* choice).
* choice).
*/
*/
void
poisson_disc
(
struct
grid_data
*
grid
,
int
dims
[
3
],
float
radius
,
int
k
)
{
static
void
poisson_disc
(
struct
grid_data
*
grid
,
int
dims
[
3
],
float
radius
,
int
k
)
{
grid
->
radius
=
radius
;
grid
->
radius
=
radius
;
grid
->
cell_size
=
radius
/
sqrtf
(
3
.
0
f
);
grid
->
cell_size
=
radius
/
sqrtf
(
3
.
0
f
);
...
@@ -293,53 +295,54 @@ void poisson_disc(struct grid_data *grid, int dims[3], float radius, int k) {
...
@@ -293,53 +295,54 @@ void poisson_disc(struct grid_data *grid, int dims[3], float radius, int k) {
}
}
}
}
int
main
(
int
argc
,
char
*
argv
[])
{
/**
int
dims
[
3
];
* @brief Apply poisson disc partitioning to a cell structure.
float
radius
=
0
.
0
f
;
*
int
k
=
30
;
* Generates a poisson disc sample for the 3D space of the cells and assigns
struct
grid_data
grid
;
* each cells nodeID to the nearest sample point index, thus partitioning
* the space into contiguous regions.
/* Expected sample size. */
*
int
N
=
90
;
* @param s the space containing the cells to split into partitions.
* @param nparts number of parititions to generate.
/* Dimensions. */
* @result true if the partitioning succeeded.
dims
[
0
]
=
300
;
*/
dims
[
1
]
=
300
;
int
poisson_split
(
struct
space
*
s
,
int
nparts
)
{
dims
[
2
]
=
300
;
/* Randomize randoms. */
srand
(
time
(
NULL
));
srand
(
time
(
NULL
));
/* Pick radius for expected sample size. */
/* Pick radius for expected sample size. */
radius
=
pow
((
dim
s
[
0
]
*
dim
s
[
1
]
*
dim
s
[
2
])
/
(
N
),
0
.
3333
);
float
radius
=
pow
((
s
->
c
dim
[
0
]
*
s
->
c
dim
[
1
]
*
s
->
c
dim
[
2
])
/
(
1
.
5
*
nparts
),
0
.
3333
);
printf
(
"# Radius = %f
\n
"
,
radius
);
message
(
"# Radius = %f
\n
"
,
radius
);
/* Sample is stocastic, so we may need to ask more than one to get the
/* Sample is stocastic, so we may need to ask more than on
c
e to get the
* number of samples we require as a minimum. */
* number of samples we require as a minimum. */
struct
grid_data
grid
;
grid
.
samplelen
=
0
;
grid
.
samplelen
=
0
;
while
(
grid
.
samplelen
<
N
)
{
while
(
grid
.
samplelen
<
nparts
)
{
printf
(
"# Sampling...
\n
"
);
message
(
"# Sampling...
\n
"
);
poisson_disc
(
&
grid
,
dim
s
,
radius
,
k
);
poisson_disc
(
&
grid
,
s
->
c
dim
,
radius
,
30
);
printf
(
"# Samples = %d
\n
"
,
grid
.
samplelen
);
message
(
"# Samples = %d
\n
"
,
grid
.
samplelen
);
}
}
for
(
int
i
=
0
;
i
<
grid
.
samplelen
;
i
++
)
{
for
(
int
i
=
0
;
i
<
grid
.
samplelen
;
i
++
)
{
printf
(
"# %f %f %f
\n
"
,
grid
.
samplelist
[
i
].
x
[
0
],
grid
.
samplelist
[
i
].
x
[
1
],
message
(
"# %f %f %f
\n
"
,
grid
.
samplelist
[
i
].
x
[
0
],
grid
.
samplelist
[
i
].
x
[
1
],
grid
.
samplelist
[
i
].
x
[
2
]);
grid
.
samplelist
[
i
].
x
[
2
]);
}
}
/* Partition the space. Slow .... */
/* Partition the space. Slow .... */
unsigned
long
int
counts
[
nparts
];
unsigned
long
int
counts
[
N
];
for
(
int
i
=
0
;
i
<
nparts
;
i
++
)
{
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
counts
[
i
]
=
0
;
counts
[
i
]
=
0
;
}
}
for
(
int
i
=
0
;
i
<
dims
[
0
];
i
++
)
{
int
n
=
0
;
for
(
int
j
=
0
;
j
<
dims
[
1
];
j
++
)
{
for
(
int
i
=
0
;
i
<
s
->
cdim
[
0
];
i
++
)
{
for
(
int
k
=
0
;
k
<
dims
[
2
];
k
++
)
{
for
(
int
j
=
0
;
j
<
s
->
cdim
[
1
];
j
++
)
{
for
(
int
k
=
0
;
k
<
s
->
cdim
[
2
];
k
++
)
{
int
select
=
-
1
;
int
select
=
-
1
;
float
rsqmax
=
FLT_MAX
;
float
rsqmax
=
FLT_MAX
;
for
(
int
l
=
0
;
l
<
N
;
l
++
)
{
for
(
int
l
=
0
;
l
<
nparts
;
l
++
)
{
float
dx
=
grid
.
samplelist
[
l
].
x
[
0
]
-
(
i
+
0
.
5
);
float
dx
=
grid
.
samplelist
[
l
].
x
[
0
]
-
(
i
+
0
.
5
);
float
dy
=
grid
.
samplelist
[
l
].
x
[
1
]
-
(
j
+
0
.
5
);
float
dy
=
grid
.
samplelist
[
l
].
x
[
1
]
-
(
j
+
0
.
5
);
float
dz
=
grid
.
samplelist
[
l
].
x
[
2
]
-
(
k
+
0
.
5
);
float
dz
=
grid
.
samplelist
[
l
].
x
[
2
]
-
(
k
+
0
.
5
);
...
@@ -349,21 +352,22 @@ int main(int argc, char *argv[]) {
...
@@ -349,21 +352,22 @@ int main(int argc, char *argv[]) {
select
=
l
;
select
=
l
;
}
}
}
}
s
->
cells
[
n
].
nodeID
=
select
;
counts
[
select
]
++
;
counts
[
select
]
++
;
printf
(
"%f %f %f %d
\n
"
,
i
+
0
.
5
,
j
+
0
.
5
,
k
+
0
.
5
,
select
);
message
(
"%f %f %f %d
\n
"
,
i
+
0
.
5
,
j
+
0
.
5
,
k
+
0
.
5
,
select
);
}
}
}
}
}
}
printf
(
"# Counts:
\n
"
);
message
(
"# Counts:
\n
"
);
unsigned
long
int
total
=
0
;
unsigned
long
int
total
=
0
;
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
for
(
int
i
=
0
;
i
<
nparts
;
i
++
)
{
printf
(
"# %d %ld
\n
"
,
i
,
counts
[
i
]);
message
(
"# %d %ld
\n
"
,
i
,
counts
[
i
]);
total
+=
counts
[
i
];
total
+=
counts
[
i
];
}
}
printf
(
"# total = %ld
\n
"
,
total
);
message
(
"# total = %ld
\n
"
,
total
);
poisson_free
(
&
grid
);
poisson_free
(
&
grid
);
return
0
;
return
1
;
}
}
This diff is collapsed.
Click to expand it.
src/poisson_disc.h
0 → 100644
+
25
−
0
View file @
2d1d19b4
/*******************************************************************************
* This file is part of SWIFT.
* Copyright (c) 2015 Peter W. Draper (p.w.draper@durham.ac.uk)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
******************************************************************************/
#ifndef SWIFT_POISSON_DISC_H
#define SWIFT_POISSON_DISC_H
#include
"space.h"
int
poisson_split
(
struct
space
*
s
,
int
nparts
);
#endif
/* SWIFT_POISSON_DISC_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