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
6418b3dc
Commit
6418b3dc
authored
Dec 14, 2017
by
Matthieu Schaller
Browse files
Also make the part and spart duplication use the threadpool.
parent
a3f65931
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/common_io.c
View file @
6418b3dc
...
...
@@ -645,23 +645,26 @@ void io_prepare_dm_gparts(struct threadpool* tp, struct gpart* const gparts,
sizeof
(
struct
gpart
),
0
,
NULL
);
}
/**
* @brief Copy every #part into the corresponding #gpart and link them.
*
* This function assumes that the DM particles are all at the start of the
* gparts array and adds the hydro particles afterwards
*
* @param parts The array of #part freshly read in.
* @param gparts The array of #gpart freshly read in with all the DM particles
* at the start
* @param Ngas The number of gas particles read in.
* @param Ndm The number of DM particles read in.
*/
void
io_duplicate_hydro_gparts
(
struct
part
*
const
parts
,
struct
gpart
*
const
gparts
,
size_t
Ngas
,
size_t
Ndm
)
{
struct
duplication_data
{
struct
part
*
parts
;
struct
gpart
*
gparts
;
struct
spart
*
sparts
;
int
Ndm
;
int
Ngas
;
int
Nstars
;
};
for
(
size_t
i
=
0
;
i
<
Ngas
;
++
i
)
{
void
io_duplicate_hydro_gparts_mapper
(
void
*
restrict
data
,
int
Ngas
,
void
*
restrict
extra_data
)
{
struct
duplication_data
*
temp
=
(
struct
duplication_data
*
)
extra_data
;
const
int
Ndm
=
temp
->
Ndm
;
struct
part
*
parts
=
(
struct
part
*
)
data
;
const
ptrdiff_t
offset
=
parts
-
temp
->
parts
;
struct
gpart
*
gparts
=
temp
->
gparts
+
offset
;
for
(
int
i
=
0
;
i
<
Ngas
;
++
i
)
{
/* Duplicate the crucial information */
gparts
[
i
+
Ndm
].
x
[
0
]
=
parts
[
i
].
x
[
0
];
...
...
@@ -684,22 +687,39 @@ void io_duplicate_hydro_gparts(struct part* const parts,
}
/**
* @brief Copy every #
s
part into the corresponding #gpart and link them.
* @brief Copy every #part into the corresponding #gpart and link them.
*
* This function assumes that the DM particles a
nd gas particles are all at
*
the start of the
gparts array and adds the
star
particles afterwards
* This function assumes that the DM particles a
re all at the start of the
* gparts array and adds the
hydro
particles afterwards
*
* @param
s
parts The array of #
s
part freshly read in.
* @param gparts The array of #gpart freshly read in with all the DM
and ga
s
*
particles
at the start
.
* @param N
star
s The number of
star
s particles read in.
* @param Ndm The number of DM
and gas
particles read in.
* @param parts The array of #part freshly read in.
* @param gparts The array of #gpart freshly read in with all the DM
particle
s
* at the start
* @param N
ga
s The number of
ga
s particles read in.
* @param Ndm The number of DM particles read in.
*/
void
io_duplicate_star_gparts
(
struct
spart
*
const
sparts
,
struct
gpart
*
const
gparts
,
size_t
Nstars
,
size_t
Ndm
)
{
void
io_duplicate_hydro_gparts
(
struct
threadpool
*
tp
,
struct
part
*
const
parts
,
struct
gpart
*
const
gparts
,
size_t
Ngas
,
size_t
Ndm
)
{
struct
duplication_data
data
;
data
.
parts
=
parts
;
data
.
gparts
=
gparts
;
data
.
Ndm
=
Ndm
;
for
(
size_t
i
=
0
;
i
<
Nstars
;
++
i
)
{
threadpool_map
(
tp
,
io_duplicate_hydro_gparts_mapper
,
parts
,
Ngas
,
sizeof
(
struct
part
),
0
,
&
data
);
}
void
io_duplicate_hydro_sparts_mapper
(
void
*
restrict
data
,
int
Nstars
,
void
*
restrict
extra_data
)
{
struct
duplication_data
*
temp
=
(
struct
duplication_data
*
)
extra_data
;
const
int
Ndm
=
temp
->
Ndm
;
struct
spart
*
sparts
=
(
struct
spart
*
)
data
;
const
ptrdiff_t
offset
=
sparts
-
temp
->
sparts
;
struct
gpart
*
gparts
=
temp
->
gparts
+
offset
;
for
(
int
i
=
0
;
i
<
Nstars
;
++
i
)
{
/* Duplicate the crucial information */
gparts
[
i
+
Ndm
].
x
[
0
]
=
sparts
[
i
].
x
[
0
];
...
...
@@ -721,6 +741,31 @@ void io_duplicate_star_gparts(struct spart* const sparts,
}
}
/**
* @brief Copy every #spart into the corresponding #gpart and link them.
*
* This function assumes that the DM particles and gas particles are all at
* the start of the gparts array and adds the star particles afterwards
*
* @param sparts The array of #spart freshly read in.
* @param gparts The array of #gpart freshly read in with all the DM and gas
* particles at the start.
* @param Nstars The number of stars particles read in.
* @param Ndm The number of DM and gas particles read in.
*/
void
io_duplicate_star_gparts
(
struct
threadpool
*
tp
,
struct
spart
*
const
sparts
,
struct
gpart
*
const
gparts
,
size_t
Nstars
,
size_t
Ndm
)
{
struct
duplication_data
data
;
data
.
gparts
=
gparts
;
data
.
sparts
=
sparts
;
data
.
Ndm
=
Ndm
;
threadpool_map
(
tp
,
io_duplicate_hydro_sparts_mapper
,
sparts
,
Nstars
,
sizeof
(
struct
spart
),
0
,
&
data
);
}
/**
* @brief Copy every DM #gpart into the dmparts array.
*
...
...
src/common_io.h
View file @
6418b3dc
...
...
@@ -89,10 +89,10 @@ void io_collect_dm_gparts(const struct gpart* const gparts, size_t Ntot,
struct
gpart
*
const
dmparts
,
size_t
Ndm
);
void
io_prepare_dm_gparts
(
struct
threadpool
*
tp
,
struct
gpart
*
const
gparts
,
size_t
Ndm
);
void
io_duplicate_hydro_gparts
(
struct
part
*
const
parts
,
void
io_duplicate_hydro_gparts
(
struct
threadpool
*
tp
,
struct
part
*
const
parts
,
struct
gpart
*
const
gparts
,
size_t
Ngas
,
size_t
Ndm
);
void
io_duplicate_star_gparts
(
struct
spart
*
const
sparts
,
void
io_duplicate_star_gparts
(
struct
threadpool
*
tp
,
struct
spart
*
const
sparts
,
struct
gpart
*
const
gparts
,
size_t
Nstars
,
size_t
Ndm
);
...
...
src/parallel_io.c
View file @
6418b3dc
...
...
@@ -763,17 +763,17 @@ void read_ic_parallel(char* fileName, const struct unit_system* internal_units,
/* Let's initialise a bit of thread parallelism here */
struct
threadpool
tp
;
threadpool_init
(
&
tp
,
4
);
threadpool_init
(
&
tp
,
n_threads
);
/* Prepare the DM particles */
io_prepare_dm_gparts
(
*
gparts
,
Ndm
);
io_prepare_dm_gparts
(
&
tp
,
*
gparts
,
Ndm
);
/* Duplicate the hydro particles into gparts */
if
(
with_hydro
)
io_duplicate_hydro_gparts
(
*
parts
,
*
gparts
,
*
Ngas
,
Ndm
);
if
(
with_hydro
)
io_duplicate_hydro_gparts
(
&
tp
,
*
parts
,
*
gparts
,
*
Ngas
,
Ndm
);
/* Duplicate the star particles into gparts */
if
(
with_stars
)
io_duplicate_star_gparts
(
*
sparts
,
*
gparts
,
*
Nstars
,
Ndm
+
*
Ngas
);
io_duplicate_star_gparts
(
&
tp
,
*
sparts
,
*
gparts
,
*
Nstars
,
Ndm
+
*
Ngas
);
threadpool_clean
(
&
tp
);
}
...
...
src/serial_io.c
View file @
6418b3dc
...
...
@@ -658,11 +658,11 @@ void read_ic_serial(char* fileName, const struct unit_system* internal_units,
io_prepare_dm_gparts
(
&
tp
,
*
gparts
,
Ndm
);
/* Duplicate the hydro particles into gparts */
if
(
with_hydro
)
io_duplicate_hydro_gparts
(
*
parts
,
*
gparts
,
*
Ngas
,
Ndm
);
if
(
with_hydro
)
io_duplicate_hydro_gparts
(
&
tp
,
*
parts
,
*
gparts
,
*
Ngas
,
Ndm
);
/* Duplicate the star particles into gparts */
if
(
with_stars
)
io_duplicate_star_gparts
(
*
sparts
,
*
gparts
,
*
Nstars
,
Ndm
+
*
Ngas
);
io_duplicate_star_gparts
(
&
tp
,
*
sparts
,
*
gparts
,
*
Nstars
,
Ndm
+
*
Ngas
);
threadpool_clean
(
&
tp
);
}
...
...
src/single_io.c
View file @
6418b3dc
...
...
@@ -526,11 +526,11 @@ void read_ic_single(char* fileName, const struct unit_system* internal_units,
io_prepare_dm_gparts
(
&
tp
,
*
gparts
,
Ndm
);
/* Duplicate the hydro particles into gparts */
if
(
with_hydro
)
io_duplicate_hydro_gparts
(
*
parts
,
*
gparts
,
*
Ngas
,
Ndm
);
if
(
with_hydro
)
io_duplicate_hydro_gparts
(
&
tp
,
*
parts
,
*
gparts
,
*
Ngas
,
Ndm
);
/* Duplicate the star particles into gparts */
if
(
with_stars
)
io_duplicate_star_gparts
(
*
sparts
,
*
gparts
,
*
Nstars
,
Ndm
+
*
Ngas
);
io_duplicate_star_gparts
(
&
tp
,
*
sparts
,
*
gparts
,
*
Nstars
,
Ndm
+
*
Ngas
);
threadpool_clean
(
&
tp
);
}
...
...
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