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
b44cd18a
Commit
b44cd18a
authored
8 years ago
by
James Willis
Browse files
Options
Downloads
Patches
Plain Diff
Implements a particle cache with an initialisation and read function.
parent
2474a3c2
No related branches found
No related tags found
1 merge request
!287
Particle caching
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/cache.h
+115
-0
115 additions, 0 deletions
src/cache.h
with
115 additions
and
0 deletions
src/cache.h
0 → 100644
+
115
−
0
View file @
b44cd18a
/*******************************************************************************
* This file is part of SWIFT.
* Copyright (c) 2016 James Willis (jame.s.willis@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_CACHE_H
#define SWIFT_CACHE_H
/* Config parameters. */
#include
"../config.h"
/* Local headers */
#include
"vector.h"
#include
"part.h"
#include
"cell.h"
/* Cache struct to hold a local copy of a cells' particle
* properties required for density/force calculations.*/
struct
cache
{
/* Particle x position. */
float
*
restrict
x
__attribute__
((
aligned
(
sizeof
(
float
)
*
VEC_SIZE
)));
/* Particle y position. */
float
*
restrict
y
__attribute__
((
aligned
(
sizeof
(
float
)
*
VEC_SIZE
)));
/* Particle z position. */
float
*
restrict
z
__attribute__
((
aligned
(
sizeof
(
float
)
*
VEC_SIZE
)));
/* Particle smoothing length. */
float
*
restrict
h
__attribute__
((
aligned
(
sizeof
(
float
)
*
VEC_SIZE
)));
/* Particle mass. */
float
*
restrict
m
__attribute__
((
aligned
(
sizeof
(
float
)
*
VEC_SIZE
)));
/* Particle x velocity. */
float
*
restrict
vx
__attribute__
((
aligned
(
sizeof
(
float
)
*
VEC_SIZE
)));
/* Particle y velocity. */
float
*
restrict
vy
__attribute__
((
aligned
(
sizeof
(
float
)
*
VEC_SIZE
)));
/* Particle z velocity. */
float
*
restrict
vz
__attribute__
((
aligned
(
sizeof
(
float
)
*
VEC_SIZE
)));
/* Cache size. */
int
count
;
};
struct
cache
cell_cache
;
/**
* @brief Allocate memory and initialise cache.
*
* @param c The cache.
* @param count Number of particles to allocate space for.
*/
__attribute__
((
always_inline
))
INLINE
void
cache_init
(
struct
cache
*
c
,
size_t
count
)
{
/* Align cache on correct byte boundary and pad cache size to include 2 vector lengths for remainder operations. */
unsigned
long
alignment
=
sizeof
(
float
)
*
VEC_SIZE
;
unsigned
int
sizeBytes
=
(
count
+
(
2
*
VEC_SIZE
))
*
sizeof
(
float
);
int
error
=
0
;
error
+=
posix_memalign
((
void
**
)
&
c
->
x
,
alignment
,
sizeBytes
);
error
+=
posix_memalign
((
void
**
)
&
c
->
y
,
alignment
,
sizeBytes
);
error
+=
posix_memalign
((
void
**
)
&
c
->
z
,
alignment
,
sizeBytes
);
error
+=
posix_memalign
((
void
**
)
&
c
->
m
,
alignment
,
sizeBytes
);
error
+=
posix_memalign
((
void
**
)
&
c
->
vx
,
alignment
,
sizeBytes
);
error
+=
posix_memalign
((
void
**
)
&
c
->
vy
,
alignment
,
sizeBytes
);
error
+=
posix_memalign
((
void
**
)
&
c
->
vz
,
alignment
,
sizeBytes
);
error
+=
posix_memalign
((
void
**
)
&
c
->
h
,
alignment
,
sizeBytes
);
if
(
error
!=
0
)
error
(
"Couldn't allocate cache, no. of particles: %d"
,
(
int
)
count
);
c
->
count
=
count
;
}
/**
* @brief Populate cache by reading in the particles in unsorted order.
*
* @param ci The #cell.
* @param ci_cache The cache.
*/
__attribute__
((
always_inline
))
INLINE
void
cache_read_particles
(
const
struct
cell
*
const
ci
,
struct
cache
*
const
ci_cache
)
{
/* Shift the particles positions to a local frame so single precision can be used instead of double precision. */
for
(
int
i
=
0
;
i
<
ci
->
count
;
i
++
)
{
ci_cache
->
x
[
i
]
=
ci
->
parts
[
i
].
x
[
0
]
-
ci
->
loc
[
0
];
ci_cache
->
y
[
i
]
=
ci
->
parts
[
i
].
x
[
1
]
-
ci
->
loc
[
1
];
ci_cache
->
z
[
i
]
=
ci
->
parts
[
i
].
x
[
2
]
-
ci
->
loc
[
2
];
ci_cache
->
h
[
i
]
=
ci
->
parts
[
i
].
h
;
ci_cache
->
m
[
i
]
=
ci
->
parts
[
i
].
mass
;
ci_cache
->
vx
[
i
]
=
ci
->
parts
[
i
].
v
[
0
];
ci_cache
->
vy
[
i
]
=
ci
->
parts
[
i
].
v
[
1
];
ci_cache
->
vz
[
i
]
=
ci
->
parts
[
i
].
v
[
2
];
}
}
#endif
/* SWIFT_CACHE_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