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
7c8992ec
Commit
7c8992ec
authored
Jul 29, 2016
by
Matthieu Schaller
Browse files
Added functions to clean-up the allocated memory
parent
8a7a517d
Changes
11
Hide whitespace changes
Inline
Side-by-side
examples/main.c
View file @
7c8992ec
...
...
@@ -611,6 +611,10 @@ int main(int argc, char *argv[]) {
error
(
"call to MPI_Finalize failed with error %i."
,
res
);
#endif
/* Clean everything */
engine_clean
(
&
e
);
free
(
params
);
/* Say goodbye. */
if
(
myrank
==
0
)
message
(
"done. Bye."
);
...
...
src/cell.c
View file @
7c8992ec
...
...
@@ -707,3 +707,8 @@ void cell_clean_links(struct cell *c, void *data) {
c
->
force
=
NULL
;
c
->
nr_force
=
0
;
}
/**
* @brief Frees up the memory allocated for this #cell
*/
void
cell_clean
(
struct
cell
*
c
)
{
free
(
c
->
sort
);
}
src/cell.h
View file @
7c8992ec
...
...
@@ -197,5 +197,6 @@ void cell_init_parts(struct cell *c, void *data);
void
cell_init_gparts
(
struct
cell
*
c
,
void
*
data
);
void
cell_convert_hydro
(
struct
cell
*
c
,
void
*
data
);
void
cell_clean_links
(
struct
cell
*
c
,
void
*
data
);
void
cell_clean
(
struct
cell
*
c
);
#endif
/* SWIFT_CELL_H */
src/engine.c
View file @
7c8992ec
...
...
@@ -2864,20 +2864,22 @@ void engine_init(struct engine *e, struct space *s,
if
(
verbose
&&
with_aff
)
message
(
"Affinity at entry: %s"
,
buf
);
int
*
cpuid
=
malloc
(
nr_affinity_cores
*
sizeof
(
int
))
;
int
*
cpuid
=
NULL
;
cpu_set_t
cpuset
;
int
skip
=
0
;
for
(
int
k
=
0
;
k
<
nr_affinity_cores
;
k
++
)
{
int
c
;
for
(
c
=
skip
;
c
<
CPU_SETSIZE
&&
!
CPU_ISSET
(
c
,
entry_affinity
);
++
c
)
;
cpuid
[
k
]
=
c
;
skip
=
c
+
1
;
}
if
(
with_aff
)
{
cpuid
=
malloc
(
nr_affinity_cores
*
sizeof
(
int
));
int
skip
=
0
;
for
(
int
k
=
0
;
k
<
nr_affinity_cores
;
k
++
)
{
int
c
;
for
(
c
=
skip
;
c
<
CPU_SETSIZE
&&
!
CPU_ISSET
(
c
,
entry_affinity
);
++
c
)
;
cpuid
[
k
]
=
c
;
skip
=
c
+
1
;
}
#if defined(HAVE_LIBNUMA) && defined(_GNU_SOURCE)
if
((
policy
&
engine_policy_cputight
)
!=
engine_policy_cputight
)
{
...
...
@@ -3241,3 +3243,14 @@ void engine_compute_next_snapshot_time(struct engine *e) {
message
(
"Next output time set to t=%e."
,
next_snapshot_time
);
}
}
/**
* @brief Frees up the memory allocated for this #engine
*/
void
engine_clean
(
struct
engine
*
e
)
{
free
(
e
->
snapshotUnits
);
free
(
e
->
links
);
scheduler_clean
(
&
e
->
sched
);
space_clean
(
e
->
s
);
}
src/engine.h
View file @
7c8992ec
...
...
@@ -239,5 +239,6 @@ void engine_print_policy(struct engine *e);
int
engine_is_done
(
struct
engine
*
e
);
void
engine_pin
();
void
engine_unpin
();
void
engine_clean
(
struct
engine
*
e
);
#endif
/* SWIFT_ENGINE_H */
src/queue.c
View file @
7c8992ec
...
...
@@ -296,3 +296,9 @@ struct task *queue_gettask(struct queue *q, const struct task *prev,
/* Take the money and run. */
return
res
;
}
void
queue_clean
(
struct
queue
*
q
)
{
free
(
q
->
tid
);
free
(
q
->
tid_incoming
);
}
src/queue.h
View file @
7c8992ec
...
...
@@ -64,5 +64,6 @@ struct task *queue_gettask(struct queue *q, const struct task *prev,
int
blocking
);
void
queue_init
(
struct
queue
*
q
,
struct
task
*
tasks
);
void
queue_insert
(
struct
queue
*
q
,
struct
task
*
t
);
void
queue_clean
(
struct
queue
*
q
);
#endif
/* SWIFT_QUEUE_H */
src/scheduler.c
View file @
7c8992ec
...
...
@@ -1298,3 +1298,16 @@ void scheduler_do_rewait(struct task *t_begin, struct task *t_end,
}
}
}
/**
* @brief Frees up the memory allocated for this #scheduler
*/
void
scheduler_clean
(
struct
scheduler
*
s
)
{
free
(
s
->
tasks
);
free
(
s
->
tasks_ind
);
free
(
s
->
unlocks
);
free
(
s
->
unlock_ind
);
for
(
int
i
=
0
;
i
<
s
->
nr_queues
;
++
i
)
queue_clean
(
&
s
->
queues
[
i
]);
free
(
s
->
queues
);
}
src/scheduler.h
View file @
7c8992ec
...
...
@@ -124,5 +124,6 @@ void scheduler_dump_queue(struct scheduler *s);
void
scheduler_print_tasks
(
const
struct
scheduler
*
s
,
const
char
*
fileName
);
void
scheduler_do_rewait
(
struct
task
*
t_begin
,
struct
task
*
t_end
,
unsigned
int
mask
,
unsigned
int
submask
);
void
scheduler_clean
(
struct
scheduler
*
s
);
#endif
/* SWIFT_SCHEDULER_H */
src/space.c
View file @
7c8992ec
...
...
@@ -1558,3 +1558,12 @@ void space_link_cleanup(struct space *s) {
/* Recursively apply the cell link cleaning routine */
space_map_cells_pre
(
s
,
1
,
cell_clean_links
,
NULL
);
}
/**
* @brief Frees up the memory allocated for this #space
*/
void
space_clean
(
struct
space
*
s
)
{
for
(
int
i
=
0
;
i
<
s
->
nr_cells
;
++
i
)
cell_clean
(
&
s
->
cells
[
i
]);
free
(
s
->
cells
);
}
src/space.h
View file @
7c8992ec
...
...
@@ -160,5 +160,6 @@ void space_do_split(struct space *s, struct cell *c);
void
space_do_parts_sort
();
void
space_do_gparts_sort
();
void
space_link_cleanup
(
struct
space
*
s
);
void
space_clean
(
struct
space
*
s
);
#endif
/* SWIFT_SPACE_H */
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