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
CodeVault
hpc-kernels
structured_grids
Commits
3b77dee3
Commit
3b77dee3
authored
Oct 12, 2016
by
Thomas Steinreiter
Browse files
removed restriction that the world dimensions must be even divisible by the grid dimensions
parent
49b735c2
Changes
5
Expand all
Show whitespace changes
Inline
Side-by-side
cellular_automaton/wireworld_c++/FileIO.cpp
View file @
3b77dee3
...
...
@@ -59,27 +59,37 @@ void FileIO::WriteHeader(const HeaderInfo& header, const std::string& path,
MPI_File_close
(
&
fh
);
}
Size
FileIO
::
GetTileSize
(
Size
globalSize
,
Size
gridSize
)
{
const
auto
tileSizeCols
=
globalSize
.
Cols
/
gridSize
.
Cols
;
const
auto
tileSizeRows
=
globalSize
.
Rows
/
gridSize
.
Rows
;
return
{
tileSizeCols
,
tileSizeRows
};
SizeCoord
FileIO
::
GetTileSizeCoord
(
Size
globalSize
,
Size
gridSize
,
std
::
size_t
rank
)
{
const
auto
tileX
=
rank
%
gridSize
.
Cols
;
const
auto
tileY
=
rank
/
gridSize
.
Cols
;
const
auto
xBeg
=
(
tileX
+
0
)
*
globalSize
.
Cols
/
gridSize
.
Cols
;
const
auto
xEnd
=
(
tileX
+
1
)
*
globalSize
.
Cols
/
gridSize
.
Cols
;
const
auto
yBeg
=
(
tileY
+
0
)
*
globalSize
.
Rows
/
gridSize
.
Rows
;
const
auto
yEnd
=
(
tileY
+
1
)
*
globalSize
.
Rows
/
gridSize
.
Rows
;
const
auto
tileSizeCols
=
xEnd
-
xBeg
;
const
auto
tileSizeRows
=
yEnd
-
yBeg
;
return
{{
tileSizeCols
,
tileSizeRows
},
{
xBeg
,
yBeg
}};
}
FileIO
::
Tile
::
Tile
(
const
std
::
string
&
path
,
HeaderInfo
header
,
Size
gridSize
,
std
::
size_t
rank
,
State
*
buf
)
:
_path
(
path
),
_headerLength
(
header
.
HeaderLength
),
_srcSize
(
header
.
GlobalSize
),
_gridSize
(
gridSize
),
_rank
(
rank
),
_buf
(
buf
),
_tileSize
(
FileIO
::
GetTileSize
(
header
.
GlobalSize
,
gridSize
)),
//
_tileX
(
rank
%
gridSize
.
Cols
),
//
_tile
Y
(
rank
/
gridSize
.
Cols
),
//
_tileSize
Coord
(
FileIO
::
GetTileSizeCoord
(
header
.
GlobalSize
,
gridSize
,
rank
)),
_tile
Size
(
_tileSizeCoord
.
Size
),
_tileCoord
(
_tileSizeCoord
.
Coord
),
_tileType
(
MpiSubarray
({{
header
.
GlobalSize
.
Rows
,
_tileSize
.
Rows
,
0
},
{
header
.
GlobalSize
.
Cols
+
LF
,
_tileSize
.
Cols
,
0
}})),
_bufType
(
MpiSubarray
({{
_tileSize
.
Rows
+
2
,
_tileSize
.
Rows
,
1
},
{
_tileSize
.
Cols
+
2
,
_tileSize
.
Cols
,
1
}})),
_displ
(
header
.
HeaderLength
+
(
header
.
GlobalSize
.
Cols
+
LF
)
*
_tileSize
.
Rows
*
_tileY
+
_tile
Size
.
Cols
*
_tileX
)
{}
(
header
.
Global
Size
.
Cols
+
LF
)
*
_tile
Coord
.
Y
+
_tileCoord
.
X
)
{}
void
FileIO
::
Tile
::
Read
()
{
MPI_File
file
;
...
...
@@ -106,21 +116,15 @@ void FileIO::Tile::Write() const {
// ranks actually write line feeds
// are we a rightMost tile?
const
auto
rightMost
=
_tileX
==
_gridSize
.
Cols
-
1
;
const
auto
bottomMost
=
_tileY
==
_gridSize
.
Rows
-
1
;
const
auto
noLfNeeded
=
rightMost
?
//
(
bottomMost
?
//
_tileSize
.
Rows
-
1
//
:
_tileSize
.
Rows
)
//
:
0
;
//
const
auto
rightMost
=
_tileCoord
.
X
==
_gridSize
.
Cols
-
1
;
const
auto
noLfNeeded
=
rightMost
?
_tileSize
.
Rows
:
0
;
const
auto
lfType
=
MpiSubarray
(
// subsize must be > 0
{{
_srcSize
.
Rows
,
std
::
max
<
std
::
size_t
>
(
noLfNeeded
,
1
),
0
},
{
_srcSize
.
Cols
+
LF
,
1
,
0
}});
const
std
::
vector
<
char
>
lfs
(
noLfNeeded
,
'\n'
);
const
auto
lfDisp
=
_headerLength
+
(
_srcSize
.
Cols
+
LF
)
*
_tileSize
.
Rows
*
_tileY
+
_srcSize
.
Cols
;
const
auto
lfDisp
=
_headerLength
+
(
_srcSize
.
Cols
+
LF
)
*
_tileCoord
.
Y
+
_tileCoord
.
X
+
_tileSize
.
Cols
;
MPI_File_set_view
(
file
,
lfDisp
,
MPI_CHAR
,
lfType
.
type
(),
"native"
,
MPI_INFO_NULL
);
...
...
cellular_automaton/wireworld_c++/FileIO.hpp
View file @
3b77dee3
...
...
@@ -2,6 +2,7 @@
#include
<cstddef>
#include
<string>
#include
<tuple>
#include
"MpiEnvironment.hpp"
#include
"MpiSubarray.hpp"
...
...
@@ -19,7 +20,7 @@ struct FileIO {
static
void
WriteHeader
(
const
HeaderInfo
&
header
,
const
std
::
string
&
path
,
const
MpiEnvironment
&
env
);
static
Size
GetTileSize
(
Size
globalSize
,
Size
gridSize
);
static
Size
Coord
GetTileSize
Coord
(
Size
globalSize
,
Size
gridSize
,
std
::
size_t
rank
);
// helper class to share commonly used data for reading and writing
class
Tile
{
...
...
@@ -31,9 +32,9 @@ struct FileIO {
const
std
::
size_t
_rank
;
State
*
_buf
;
const
SizeCoord
_tileSizeCoord
;
const
Size
_tileSize
;
const
std
::
size_t
_tileX
;
const
std
::
size_t
_tileY
;
const
Coord
_tileCoord
;
const
MpiSubarray
_tileType
;
const
MpiSubarray
_bufType
;
const
std
::
size_t
_displ
;
...
...
cellular_automaton/wireworld_c++/Tile.cpp
View file @
3b77dee3
...
...
@@ -11,13 +11,8 @@
Tile
::
Tile
(
const
Configuration
&
cfg
,
const
MpiEnvironment
&
env
)
:
_env
(
env
),
_cfg
(
cfg
),
_header
(
FileIO
::
ReadHeader
(
cfg
.
InputFilePath
)),
//
_tileSize
(
FileIO
::
GetTileSize
(
_header
.
GlobalSize
,
cfg
.
Grid
)
),
_tileSize
(
FileIO
::
GetTileSize
Coord
(
_header
.
GlobalSize
,
cfg
.
Grid
,
env
.
worldRank
()).
Size
),
_modelWidth
(
_tileSize
.
Cols
+
2
)
{
if
((
_header
.
GlobalSize
.
Cols
%
_tileSize
.
Cols
)
!=
0
||
(
_header
.
GlobalSize
.
Rows
%
_tileSize
.
Rows
)
!=
0
)
{
MpiReportErrorAbort
(
"Wireworld size is not even divisible by the grid size."
);
}
const
auto
bufsize
=
(
_tileSize
.
Cols
+
2
)
*
(
_tileSize
.
Rows
+
2
);
_memoryA
.
resize
(
bufsize
);
_memoryB
.
resize
(
bufsize
);
...
...
cellular_automaton/wireworld_c++/Util.hpp
View file @
3b77dee3
...
...
@@ -2,6 +2,7 @@
#include
<cstddef>
#include
<string>
struct
Size
{
std
::
size_t
Cols
{};
std
::
size_t
Rows
{};
...
...
@@ -10,6 +11,12 @@ struct Size {
struct
Coord
{
std
::
size_t
X
{};
std
::
size_t
Y
{};
Coord
(
std
::
size_t
x
,
std
::
size_t
y
)
:
X
(
x
),
Y
(
y
)
{}
};
struct
SizeCoord
{
::
Size
Size
;
::
Coord
Coord
;
};
[[
noreturn
]]
void
MpiReportErrorAbort
(
const
std
::
string
&
err
);
\ No newline at end of file
cellular_automaton/wireworld_c++/worlds/primes.wi
100644 → 100755
View file @
3b77dee3
This diff is collapsed.
Click to expand it.
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