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
1917780b
Commit
1917780b
authored
Dec 14, 2016
by
Thomas Steinreiter
Browse files
* added clang warnings
* fixed most clang warnings * removed dead code
parent
110c8f90
Changes
17
Hide whitespace changes
Inline
Side-by-side
cellular_automaton/wireworld_c++/CMakeLists.txt
View file @
1917780b
...
@@ -20,9 +20,11 @@ if (MPI_FOUND AND Boost_FOUND)
...
@@ -20,9 +20,11 @@ if (MPI_FOUND AND Boost_FOUND)
add_executable
(
${
NAME
}
main.cpp Configuration.cpp Communicator.cpp FileIO.cpp MpiEnvironment.cpp MpiSubarray.cpp MpiWireworld.cpp Tile.cpp Util.cpp
)
add_executable
(
${
NAME
}
main.cpp Configuration.cpp Communicator.cpp FileIO.cpp MpiEnvironment.cpp MpiSubarray.cpp MpiWireworld.cpp Tile.cpp Util.cpp
)
set
(
CMAKE_BUILD_TYPE RelWithDebInfo
)
set
(
CMAKE_BUILD_TYPE RelWithDebInfo
)
if
(
"
${
CMAKE_CXX_COMPILER_ID
}
"
STREQUAL
"GNU"
)
if
(
"
${
CMAKE_CXX_COMPILER_ID
}
"
STREQUAL
"GNU"
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-march=native -ftree-vectorize -flto -Wall -Wextra"
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-march=native -Wall -Wextra"
)
elseif
(
"
${
CMAKE_CXX_COMPILER_ID
}
"
STREQUAL
"Clang"
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-march=native -Weverything -Wno-missing-prototypes -Wno-padded -Wno-c++98-compat -Wno-c++98-compat-pedantic"
)
elseif
(
"
${
CMAKE_CXX_COMPILER_ID
}
"
STREQUAL
"Intel"
)
elseif
(
"
${
CMAKE_CXX_COMPILER_ID
}
"
STREQUAL
"Intel"
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-xHost -std=c++14"
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-xHost -std=c++14
-Wall
"
)
endif
()
endif
()
set_target_properties
(
${
NAME
}
PROPERTIES CXX_STANDARD 14 CXX_STANDARD_REQUIRED YES
)
set_target_properties
(
${
NAME
}
PROPERTIES CXX_STANDARD 14 CXX_STANDARD_REQUIRED YES
)
target_link_libraries
(
${
NAME
}
${
MPI_LIBRARIES
}
${
Boost_LIBRARIES
}
)
target_link_libraries
(
${
NAME
}
${
MPI_LIBRARIES
}
${
Boost_LIBRARIES
}
)
...
...
cellular_automaton/wireworld_c++/Communicator.cpp
View file @
1917780b
...
@@ -8,7 +8,9 @@ Communicator::MpiRequest::MpiRequest(DoubleVector<MPI_Request> reqs)
...
@@ -8,7 +8,9 @@ Communicator::MpiRequest::MpiRequest(DoubleVector<MPI_Request> reqs)
:
_reqs
(
reqs
)
{}
:
_reqs
(
reqs
)
{}
void
Communicator
::
MpiRequest
::
Wait
()
{
void
Communicator
::
MpiRequest
::
Wait
()
{
MPI_Waitall
(
_reqs
.
size
(),
_reqs
.
data
(),
MPI_STATUSES_IGNORE
);
MPI_Waitall
(
static_cast
<
int
>
(
_reqs
.
size
()),
//
_reqs
.
data
(),
//
MPI_STATUSES_IGNORE
);
//
finished
=
true
;
finished
=
true
;
}
}
Communicator
::
MpiRequest
::~
MpiRequest
()
{
Communicator
::
MpiRequest
::~
MpiRequest
()
{
...
@@ -21,10 +23,11 @@ Communicator::Communicator(const MpiEnvironment& env,
...
@@ -21,10 +23,11 @@ Communicator::Communicator(const MpiEnvironment& env,
const
Size
&
tileSize
)
const
Size
&
tileSize
)
:
_commMode
(
commMode
)
{
:
_commMode
(
commMode
)
{
// Begin definition of basic types
// Begin definition of basic types
MPI_Type_contiguous
(
tileSize
.
Cols
,
MPI_CHAR
,
&
_haloRowType
);
MPI_Type_contiguous
(
static_cast
<
int
>
(
tileSize
.
Cols
),
MPI_CHAR
,
&
_haloRowType
);
MPI_Type_commit
(
&
_haloRowType
);
MPI_Type_commit
(
&
_haloRowType
);
MPI_Type_vector
(
tileSize
.
Rows
,
1
,
tileSize
.
Cols
+
2
,
MPI_CHAR
,
MPI_Type_vector
(
static_cast
<
int
>
(
tileSize
.
Rows
)
,
1
,
static_cast
<
int
>
(
tileSize
.
Cols
+
2
)
,
MPI_CHAR
,
&
_haloColumnType
);
&
_haloColumnType
);
MPI_Type_commit
(
&
_haloColumnType
);
MPI_Type_commit
(
&
_haloColumnType
);
...
@@ -32,11 +35,11 @@ Communicator::Communicator(const MpiEnvironment& env,
...
@@ -32,11 +35,11 @@ Communicator::Communicator(const MpiEnvironment& env,
// Begin definition of types/displacements for a general cell somewhere in
// Begin definition of types/displacements for a general cell somewhere in
// the middle of the procs grid
// the middle of the procs grid
const
std
::
array
<
MPI_Datatype
,
NoNeighbors
>
generalSendTypes
{
const
std
::
array
<
MPI_Datatype
,
NoNeighbors
>
generalSendTypes
{
{
_haloCornerType
,
_haloRowType
,
_haloCornerType
,
//
_haloCornerType
,
_haloRowType
,
_haloCornerType
,
//
_haloColumnType
,
_haloColumnType
,
//
_haloColumnType
,
_haloColumnType
,
//
_haloCornerType
,
_haloRowType
,
_haloCornerType
//
_haloCornerType
,
_haloRowType
,
_haloCornerType
//
};
}
};
const
auto
tCols
=
tileSize
.
Cols
;
const
auto
tCols
=
tileSize
.
Cols
;
const
auto
tRows
=
tileSize
.
Rows
;
const
auto
tRows
=
tileSize
.
Rows
;
...
@@ -45,23 +48,23 @@ Communicator::Communicator(const MpiEnvironment& env,
...
@@ -45,23 +48,23 @@ Communicator::Communicator(const MpiEnvironment& env,
return
static_cast
<
MPI_Aint
>
(
y
*
(
tCols
+
2
)
+
x
);
return
static_cast
<
MPI_Aint
>
(
y
*
(
tCols
+
2
)
+
x
);
};
};
const
std
::
array
<
MPI_Aint
,
NoNeighbors
>
generalSendDisplacements
{
const
std
::
array
<
MPI_Aint
,
NoNeighbors
>
generalSendDisplacements
{
{
dp
(
1
,
1
),
dp
(
1
,
1
),
dp
(
tCols
,
1
),
//
dp
(
1
,
1
),
dp
(
1
,
1
),
dp
(
tCols
,
1
),
//
dp
(
1
,
1
),
dp
(
tCols
,
1
),
//
dp
(
1
,
1
),
dp
(
tCols
,
1
),
//
dp
(
1
,
tRows
),
dp
(
1
,
tRows
),
dp
(
tCols
,
tRows
)
//
dp
(
1
,
tRows
),
dp
(
1
,
tRows
),
dp
(
tCols
,
tRows
)
//
};
}
};
const
std
::
array
<
MPI_Aint
,
NoNeighbors
>
generalRecvDisplacements
{
const
std
::
array
<
MPI_Aint
,
NoNeighbors
>
generalRecvDisplacements
{
{
dp
(
0
,
0
),
dp
(
1
,
0
),
dp
(
tCols
+
1
,
0
),
//
dp
(
0
,
0
),
dp
(
1
,
0
),
dp
(
tCols
+
1
,
0
),
//
dp
(
0
,
1
),
dp
(
tCols
+
1
,
1
),
//
dp
(
0
,
1
),
dp
(
tCols
+
1
,
1
),
//
dp
(
0
,
tRows
+
1
),
dp
(
1
,
tRows
+
1
),
dp
(
tCols
+
1
,
tRows
+
1
)
//
dp
(
0
,
tRows
+
1
),
dp
(
1
,
tRows
+
1
),
dp
(
tCols
+
1
,
tRows
+
1
)
//
};
}
};
const
std
::
array
<
int
,
NoNeighbors
>
generalSizes
{
const
std
::
array
<
int
,
NoNeighbors
>
generalSizes
{
{
1
,
1
,
1
,
//
1
,
1
,
1
,
//
1
,
1
,
//
1
,
1
,
//
1
,
1
,
1
//
1
,
1
,
1
//
};
}
};
// End definition of datastructures for a general cell
// End definition of datastructures for a general cell
// Begin definition of datastructures for this particular cell (handle the
// Begin definition of datastructures for this particular cell (handle the
...
@@ -73,7 +76,7 @@ Communicator::Communicator(const MpiEnvironment& env,
...
@@ -73,7 +76,7 @@ Communicator::Communicator(const MpiEnvironment& env,
};
};
};
};
const
auto
coord2rank
=
[
&
](
Coord
c
)
{
return
procsSize
.
Cols
*
c
.
Y
+
c
.
X
;
};
const
auto
coord2rank
=
[
&
](
Coord
c
)
{
return
static_cast
<
int
>
(
procsSize
.
Cols
*
c
.
Y
+
c
.
X
)
;
};
const
auto
isInsideProcsGrid
=
[
&
](
Coord
c
)
{
const
auto
isInsideProcsGrid
=
[
&
](
Coord
c
)
{
return
c
.
X
<
procsSize
.
Cols
&&
c
.
Y
<
procsSize
.
Rows
;
return
c
.
X
<
procsSize
.
Cols
&&
c
.
Y
<
procsSize
.
Rows
;
...
@@ -104,10 +107,10 @@ Communicator::Communicator(const MpiEnvironment& env,
...
@@ -104,10 +107,10 @@ Communicator::Communicator(const MpiEnvironment& env,
MPI_Dist_graph_create_adjacent
(
MPI_Dist_graph_create_adjacent
(
MPI_COMM_WORLD
,
// comm_old
MPI_COMM_WORLD
,
// comm_old
_neighbors
.
size
(),
// indegree
static_cast
<
int
>
(
_neighbors
.
size
()
)
,
// indegree
_neighbors
.
data
(),
// sources
_neighbors
.
data
(),
// sources
reinterpret_cast
<
int
*>
(
MPI_UNWEIGHTED
),
// sourceweights
reinterpret_cast
<
int
*>
(
MPI_UNWEIGHTED
),
// sourceweights
_neighbors
.
size
(),
// outdegree
static_cast
<
int
>
(
_neighbors
.
size
()
)
,
// outdegree
_neighbors
.
data
(),
// destinations
_neighbors
.
data
(),
// destinations
reinterpret_cast
<
int
*>
(
MPI_UNWEIGHTED
),
// destweights
reinterpret_cast
<
int
*>
(
MPI_UNWEIGHTED
),
// destweights
MPI_INFO_NULL
,
// info
MPI_INFO_NULL
,
// info
...
@@ -127,6 +130,7 @@ Communicator::~Communicator() {
...
@@ -127,6 +130,7 @@ Communicator::~Communicator() {
void
Communicator
::
swap
(
Communicator
&
first
,
Communicator
&
second
)
{
void
Communicator
::
swap
(
Communicator
&
first
,
Communicator
&
second
)
{
using
std
::
swap
;
using
std
::
swap
;
swap
(
first
.
_commMode
,
second
.
_commMode
);
swap
(
first
.
_neighbors
,
second
.
_neighbors
);
swap
(
first
.
_neighbors
,
second
.
_neighbors
);
swap
(
first
.
_sizes
,
second
.
_sizes
);
swap
(
first
.
_sizes
,
second
.
_sizes
);
swap
(
first
.
_sendTypes
,
second
.
_sendTypes
);
swap
(
first
.
_sendTypes
,
second
.
_sendTypes
);
...
@@ -167,9 +171,6 @@ void Communicator::Communicate(State* model) {
...
@@ -167,9 +171,6 @@ void Communicator::Communicate(State* model) {
case
CommunicationMode
::
P2P
:
{
case
CommunicationMode
::
P2P
:
{
AsyncCommunicate
(
model
).
Wait
();
AsyncCommunicate
(
model
).
Wait
();
}
break
;
}
break
;
default:
MpiReportErrorAbort
(
"Invalid Communication mode"
);
break
;
}
}
}
}
...
@@ -191,7 +192,7 @@ Communicator::MpiRequest Communicator::AsyncCommunicate(State* model) {
...
@@ -191,7 +192,7 @@ Communicator::MpiRequest Communicator::AsyncCommunicate(State* model) {
_commDistGraph
,
// comm
_commDistGraph
,
// comm
&
req
);
// request
&
req
);
// request
return
MpiRequest
{{
req
}};
return
MpiRequest
{{
req
}};
}
break
;
};
case
CommunicationMode
::
P2P
:
{
case
CommunicationMode
::
P2P
:
{
Communicator
::
MpiRequest
::
DoubleVector
<
MPI_Request
>
reqs
;
Communicator
::
MpiRequest
::
DoubleVector
<
MPI_Request
>
reqs
;
for
(
std
::
size_t
i
{
0
};
i
<
_neighbors
.
size
();
++
i
)
{
for
(
std
::
size_t
i
{
0
};
i
<
_neighbors
.
size
();
++
i
)
{
...
@@ -220,9 +221,6 @@ Communicator::MpiRequest Communicator::AsyncCommunicate(State* model) {
...
@@ -220,9 +221,6 @@ Communicator::MpiRequest Communicator::AsyncCommunicate(State* model) {
}
}
}
}
return
MpiRequest
{
reqs
};
return
MpiRequest
{
reqs
};
}
break
;
};
default:
MpiReportErrorAbort
(
"Invalid Communication mode"
);
break
;
}
}
}
}
\ No newline at end of file
cellular_automaton/wireworld_c++/Communicator.hpp
View file @
1917780b
...
@@ -31,6 +31,10 @@ class Communicator {
...
@@ -31,6 +31,10 @@ class Communicator {
public:
public:
MpiRequest
(
DoubleVector
<
MPI_Request
>
reqs
);
MpiRequest
(
DoubleVector
<
MPI_Request
>
reqs
);
MpiRequest
(
const
MpiRequest
&
)
=
default
;
MpiRequest
(
MpiRequest
&&
)
=
default
;
MpiRequest
&
operator
=
(
const
MpiRequest
&
)
=
default
;
MpiRequest
&
operator
=
(
MpiRequest
&&
)
=
default
;
void
Wait
();
void
Wait
();
~
MpiRequest
();
~
MpiRequest
();
};
};
...
@@ -65,4 +69,4 @@ class Communicator {
...
@@ -65,4 +69,4 @@ class Communicator {
void
Communicate
(
State
*
model
);
void
Communicate
(
State
*
model
);
MpiRequest
AsyncCommunicate
(
State
*
model
);
MpiRequest
AsyncCommunicate
(
State
*
model
);
};
};
\ No newline at end of file
cellular_automaton/wireworld_c++/Configuration.cpp
View file @
1917780b
...
@@ -11,12 +11,14 @@
...
@@ -11,12 +11,14 @@
#include
<boost/program_options.hpp>
#include
<boost/program_options.hpp>
// BEGIN helper functions to parse Communication Mode cmd args
// BEGIN helper functions to parse Communication Mode cmd args
namespace
{
using
namespace
std
::
string_literals
;
using
namespace
std
::
string_literals
;
std
::
array
<
std
::
pair
<
std
::
string
,
CommunicationMode
>
,
2
>
std
::
array
<
std
::
pair
<
std
::
string
,
CommunicationMode
>
,
2
>
StringToCommunicationMode
{
StringToCommunicationMode
{
{
std
::
make_pair
(
"Collective"
s
,
CommunicationMode
::
Collective
),
//
std
::
make_pair
(
"Collective"
s
,
CommunicationMode
::
Collective
),
//
std
::
make_pair
(
"P2P"
s
,
CommunicationMode
::
P2P
)
//
std
::
make_pair
(
"P2P"
s
,
CommunicationMode
::
P2P
)
//
};
}};
}
std
::
istream
&
operator
>>
(
std
::
istream
&
in
,
CommunicationMode
&
comm
)
{
std
::
istream
&
operator
>>
(
std
::
istream
&
in
,
CommunicationMode
&
comm
)
{
std
::
string
buf
;
std
::
string
buf
;
...
@@ -70,14 +72,14 @@ auto Configuration::parseArgs(int argc, char* argv[], const MpiEnvironment& env)
...
@@ -70,14 +72,14 @@ auto Configuration::parseArgs(int argc, char* argv[], const MpiEnvironment& env)
// if no dimensions given, use MPI_Dims_create
// if no dimensions given, use MPI_Dims_create
if
(
cfg
.
Procs
.
Cols
<
1
||
cfg
.
Procs
.
Rows
<
1
)
{
if
(
cfg
.
Procs
.
Cols
<
1
||
cfg
.
Procs
.
Rows
<
1
)
{
std
::
array
<
int
,
2
>
dims
{
static_cast
<
int
>
(
cfg
.
Procs
.
Cols
),
std
::
array
<
int
,
2
>
dims
{
{
static_cast
<
int
>
(
cfg
.
Procs
.
Cols
),
static_cast
<
int
>
(
cfg
.
Procs
.
Rows
)};
static_cast
<
int
>
(
cfg
.
Procs
.
Rows
)}
}
;
MPI_Dims_create
(
env
.
worldSize
(),
// nnodes
MPI_Dims_create
(
static_cast
<
int
>
(
env
.
worldSize
()
)
,
// nnodes
2
,
// ndims
2
,
// ndims
dims
.
data
());
// dims
dims
.
data
());
// dims
cfg
.
Procs
.
Cols
=
dims
[
0
];
cfg
.
Procs
.
Cols
=
static_cast
<
std
::
size_t
>
(
dims
[
0
]
)
;
cfg
.
Procs
.
Rows
=
dims
[
1
];
cfg
.
Procs
.
Rows
=
static_cast
<
std
::
size_t
>
(
dims
[
1
]
)
;
}
}
// validate
// validate
...
...
cellular_automaton/wireworld_c++/FileIO.cpp
View file @
1917780b
...
@@ -55,7 +55,8 @@ void FileIO::WriteHeader(const HeaderInfo& header, const std::string& path,
...
@@ -55,7 +55,8 @@ void FileIO::WriteHeader(const HeaderInfo& header, const std::string& path,
MPI_File
fh
;
MPI_File
fh
;
MPI_File_open
(
MPI_COMM_SELF
,
path
.
c_str
(),
MPI_File_open
(
MPI_COMM_SELF
,
path
.
c_str
(),
MPI_MODE_WRONLY
|
MPI_MODE_CREATE
,
MPI_INFO_NULL
,
&
fh
);
MPI_MODE_WRONLY
|
MPI_MODE_CREATE
,
MPI_INFO_NULL
,
&
fh
);
MPI_File_write
(
fh
,
buf
.
data
(),
buf
.
size
(),
MPI_CHAR
,
MPI_STATUS_IGNORE
);
MPI_File_write
(
fh
,
buf
.
data
(),
static_cast
<
int
>
(
buf
.
size
()),
MPI_CHAR
,
MPI_STATUS_IGNORE
);
MPI_File_close
(
&
fh
);
MPI_File_close
(
&
fh
);
}
}
...
@@ -78,8 +79,7 @@ TileInfo FileIO::GetTileInfo(Size globalSize, Size procsSize,
...
@@ -78,8 +79,7 @@ TileInfo FileIO::GetTileInfo(Size globalSize, Size procsSize,
FileIO
::
Tile
::
Tile
(
const
std
::
string
&
path
,
HeaderInfo
header
,
Size
procsSize
,
FileIO
::
Tile
::
Tile
(
const
std
::
string
&
path
,
HeaderInfo
header
,
Size
procsSize
,
std
::
size_t
rank
,
State
*
buf
)
std
::
size_t
rank
,
State
*
buf
)
:
_path
(
path
),
_headerLength
(
header
.
HeaderLength
),
:
_path
(
path
),
_headerLength
(
header
.
HeaderLength
),
_srcSize
(
header
.
GlobalSize
),
_procsSize
(
procsSize
),
_rank
(
rank
),
_srcSize
(
header
.
GlobalSize
),
_procsSize
(
procsSize
),
_buf
(
buf
),
_buf
(
buf
),
_tileInfo
(
FileIO
::
GetTileInfo
(
header
.
GlobalSize
,
procsSize
,
rank
)),
_tileInfo
(
FileIO
::
GetTileInfo
(
header
.
GlobalSize
,
procsSize
,
rank
)),
_tileSize
(
_tileInfo
.
Size
),
_tileCoord
(
_tileInfo
.
GlobalCoord
),
_tileSize
(
_tileInfo
.
Size
),
_tileCoord
(
_tileInfo
.
GlobalCoord
),
_tileType
(
_tileType
(
...
@@ -95,8 +95,8 @@ void FileIO::Tile::Read() {
...
@@ -95,8 +95,8 @@ void FileIO::Tile::Read() {
MPI_File
file
;
MPI_File
file
;
MPI_File_open
(
MPI_COMM_WORLD
,
_path
.
c_str
(),
MPI_File_open
(
MPI_COMM_WORLD
,
_path
.
c_str
(),
MPI_MODE_RDONLY
|
MPI_MODE_UNIQUE_OPEN
,
MPI_INFO_NULL
,
&
file
);
MPI_MODE_RDONLY
|
MPI_MODE_UNIQUE_OPEN
,
MPI_INFO_NULL
,
&
file
);
MPI_File_set_view
(
file
,
_displ
,
MPI_CHAR
,
_tileType
.
type
(),
"native"
,
MPI_File_set_view
(
file
,
static_cast
<
MPI_Offset
>
(
_displ
)
,
MPI_CHAR
,
MPI_INFO_NULL
);
_tileType
.
type
(),
"native"
,
MPI_INFO_NULL
);
MPI_File_read_all
(
file
,
_buf
,
1
,
_bufType
.
type
(),
MPI_STATUS_IGNORE
);
MPI_File_read_all
(
file
,
_buf
,
1
,
_bufType
.
type
(),
MPI_STATUS_IGNORE
);
MPI_File_close
(
&
file
);
MPI_File_close
(
&
file
);
...
@@ -106,8 +106,8 @@ void FileIO::Tile::Write() const {
...
@@ -106,8 +106,8 @@ void FileIO::Tile::Write() const {
MPI_File
file
;
MPI_File
file
;
MPI_File_open
(
MPI_COMM_WORLD
,
_path
.
c_str
(),
MPI_File_open
(
MPI_COMM_WORLD
,
_path
.
c_str
(),
MPI_MODE_CREATE
|
MPI_MODE_WRONLY
,
MPI_INFO_NULL
,
&
file
);
MPI_MODE_CREATE
|
MPI_MODE_WRONLY
,
MPI_INFO_NULL
,
&
file
);
MPI_File_set_view
(
file
,
_displ
,
MPI_CHAR
,
_tileType
.
type
(),
"native"
,
MPI_File_set_view
(
file
,
static_cast
<
MPI_Offset
>
(
_displ
)
,
MPI_CHAR
,
MPI_INFO_NULL
);
_tileType
.
type
(),
"native"
,
MPI_INFO_NULL
);
MPI_File_write_all
(
file
,
_buf
,
1
,
_bufType
.
type
(),
MPI_STATUS_IGNORE
);
MPI_File_write_all
(
file
,
_buf
,
1
,
_bufType
.
type
(),
MPI_STATUS_IGNORE
);
...
@@ -127,11 +127,11 @@ void FileIO::Tile::Write() const {
...
@@ -127,11 +127,11 @@ void FileIO::Tile::Write() const {
_tileInfo
.
GlobalCoord
.
Y
*
(
_srcSize
.
Cols
+
LF
)
+
_tileInfo
.
GlobalCoord
.
Y
*
(
_srcSize
.
Cols
+
LF
)
+
_srcSize
.
Cols
;
_srcSize
.
Cols
;
MPI_File_set_view
(
file
,
lfDisp
,
MPI_CHAR
,
lfType
.
type
(),
"native"
,
MPI_File_set_view
(
file
,
static_cast
<
MPI_Offset
>
(
lfDisp
)
,
MPI_CHAR
,
MPI_INFO_NULL
);
lfType
.
type
(),
"native"
,
MPI_INFO_NULL
);
// lfs is empty for non-rightmost ranks
// lfs is empty for non-rightmost ranks
MPI_File_write_all
(
file
,
lfs
.
data
(),
lfs
.
size
(),
MPI_CHAR
,
MPI_File_write_all
(
file
,
lfs
.
data
(),
static_cast
<
int
>
(
lfs
.
size
()
)
,
MPI_CHAR
,
MPI_STATUS_IGNORE
);
MPI_STATUS_IGNORE
);
MPI_File_close
(
&
file
);
MPI_File_close
(
&
file
);
...
...
cellular_automaton/wireworld_c++/FileIO.hpp
View file @
1917780b
...
@@ -30,7 +30,6 @@ struct FileIO {
...
@@ -30,7 +30,6 @@ struct FileIO {
const
std
::
size_t
_headerLength
;
const
std
::
size_t
_headerLength
;
const
Size
_srcSize
;
const
Size
_srcSize
;
const
Size
_procsSize
;
const
Size
_procsSize
;
const
std
::
size_t
_rank
;
State
*
_buf
;
State
*
_buf
;
const
TileInfo
_tileInfo
;
const
TileInfo
_tileInfo
;
...
...
cellular_automaton/wireworld_c++/MpiEnvironment.cpp
View file @
1917780b
...
@@ -12,14 +12,14 @@ void MpiEnvironment::swap(MpiEnvironment& first,
...
@@ -12,14 +12,14 @@ void MpiEnvironment::swap(MpiEnvironment& first,
MpiEnvironment
::
MpiEnvironment
(
int
&
argc
,
char
*
argv
[])
{
MpiEnvironment
::
MpiEnvironment
(
int
&
argc
,
char
*
argv
[])
{
MPI_Init
(
&
argc
,
&
argv
);
MPI_Init
(
&
argc
,
&
argv
);
MPI_Comm_rank
(
MPI_COMM_WORLD
,
&
_worldRank
);
_worldRank
=
[]
{
int
r
;
MPI_Comm_rank
(
MPI_COMM_WORLD
,
&
r
);
return
static_cast
<
std
::
size_t
>
(
r
);
}(
);
MPI_Comm_size
(
MPI_COMM_WORLD
,
&
_worldSize
);
_worldSize
=
[]
{
int
s
;
MPI_Comm_size
(
MPI_COMM_WORLD
,
&
s
);
return
static_cast
<
std
::
size_t
>
(
s
);
}(
);
_isMaster
=
{
_worldRank
==
0
};
_isMaster
=
{
_worldRank
==
0
};
// We want the program to stop on I/O errors
// We want the program to stop on I/O errors
MPI_File_set_errhandler
(
MPI_FILE_NULL
,
MPI_ERRORS_ARE_FATAL
);
MPI_File_set_errhandler
(
MPI_FILE_NULL
,
MPI_ERRORS_ARE_FATAL
);
}
}
MpiEnvironment
::~
MpiEnvironment
()
{
MpiEnvironment
::~
MpiEnvironment
()
{
if
(
_worldRank
!=
-
1
)
{
MPI_Finalize
();
}
if
(
_worldRank
!=
std
::
numeric_limits
<
std
::
size_t
>::
max
()
)
{
MPI_Finalize
();
}
}
}
MpiEnvironment
::
MpiEnvironment
(
MpiEnvironment
&&
other
)
noexcept
{
MpiEnvironment
::
MpiEnvironment
(
MpiEnvironment
&&
other
)
noexcept
{
...
...
cellular_automaton/wireworld_c++/MpiEnvironment.hpp
View file @
1917780b
#pragma once
#pragma once
#include
<limits>
#include
<mpi.h>
#include
<mpi.h>
class
MpiEnvironment
{
// wrapper for creating and destroying the environment
class
MpiEnvironment
{
// wrapper for creating and destroying the environment
in
t
_worldRank
{
-
1
};
std
::
size_
t
_worldRank
{
std
::
numeric_limits
<
std
::
size_t
>::
max
()
};
in
t
_worldSize
{
-
1
};
std
::
size_
t
_worldSize
{
0
};
bool
_isMaster
{
false
};
bool
_isMaster
{
false
};
public:
public:
in
t
worldRank
()
const
{
return
_worldRank
;
}
std
::
size_
t
worldRank
()
const
{
return
_worldRank
;
}
in
t
worldSize
()
const
{
return
_worldSize
;
}
std
::
size_
t
worldSize
()
const
{
return
_worldSize
;
}
bool
isMaster
()
const
{
return
_isMaster
;
}
bool
isMaster
()
const
{
return
_isMaster
;
}
void
swap
(
MpiEnvironment
&
first
,
MpiEnvironment
&
second
)
noexcept
;
void
swap
(
MpiEnvironment
&
first
,
MpiEnvironment
&
second
)
noexcept
;
...
...
cellular_automaton/wireworld_c++/MpiSubarray.cpp
View file @
1917780b
...
@@ -15,13 +15,13 @@ void MpiSubarray::swap(MpiSubarray& first, MpiSubarray& second) noexcept {
...
@@ -15,13 +15,13 @@ void MpiSubarray::swap(MpiSubarray& first, MpiSubarray& second) noexcept {
}
}
MpiSubarray
::
MpiSubarray
(
SubarrayDefinition
sd
)
{
MpiSubarray
::
MpiSubarray
(
SubarrayDefinition
sd
)
{
MPI_Type_create_subarray
(
sd
.
dims
(),
// ndims
MPI_Type_create_subarray
(
static_cast
<
int
>
(
sd
.
dims
()
)
,
// ndims
sd
.
sizes
(),
// array_of_sizes
sd
.
sizes
(),
// array_of_sizes
sd
.
subSizes
(),
// array_of_subsizes
sd
.
subSizes
(),
// array_of_subsizes
sd
.
starts
(),
// array_of_starts
sd
.
starts
(),
// array_of_starts
MPI_ORDER_C
,
// order
MPI_ORDER_C
,
// order
MPI_CHAR
,
// oldtype
MPI_CHAR
,
// oldtype
&
_type
// newtype
&
_type
// newtype
);
);
MPI_Type_commit
(
&
_type
);
MPI_Type_commit
(
&
_type
);
}
}
...
@@ -32,4 +32,4 @@ MpiSubarray::MpiSubarray(MpiSubarray&& other) noexcept { swap(*this, other); }
...
@@ -32,4 +32,4 @@ MpiSubarray::MpiSubarray(MpiSubarray&& other) noexcept { swap(*this, other); }
MpiSubarray
&
MpiSubarray
::
operator
=
(
MpiSubarray
&&
other
)
noexcept
{
MpiSubarray
&
MpiSubarray
::
operator
=
(
MpiSubarray
&&
other
)
noexcept
{
swap
(
*
this
,
other
);
swap
(
*
this
,
other
);
return
*
this
;
return
*
this
;
}
}
\ No newline at end of file
cellular_automaton/wireworld_c++/MpiSubarray.hpp
View file @
1917780b
...
@@ -16,10 +16,10 @@ class SubarrayDefinition { // helper container for MPI Datatype creation
...
@@ -16,10 +16,10 @@ class SubarrayDefinition { // helper container for MPI Datatype creation
std
::
vector
<
int
>
_starts
;
std
::
vector
<
int
>
_starts
;
public:
public:
int
dims
()
const
{
return
_sizes
.
size
();
}
auto
dims
()
const
{
return
_sizes
.
size
();
}
int
*
sizes
()
{
return
_sizes
.
data
();
}
auto
sizes
()
{
return
_sizes
.
data
();
}
int
*
subSizes
()
{
return
_subSizes
.
data
();
}
auto
subSizes
()
{
return
_subSizes
.
data
();
}
int
*
starts
()
{
return
_starts
.
data
();
}
auto
starts
()
{
return
_starts
.
data
();
}
SubarrayDefinition
(
SubarrayDefinition
(
std
::
initializer_list
<
SubarrayDimensionDefinition
>
saDimDefs
);
std
::
initializer_list
<
SubarrayDimensionDefinition
>
saDimDefs
);
...
...
cellular_automaton/wireworld_c++/MpiWireworld.cpp
View file @
1917780b
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
#include
<iostream>
#include
<iostream>
#include
<mpi.h>
#include
<mpi.h>
#include
<string>
#include
<string>
#include
<limits>
#include
<vector>
#include
<vector>
#include
"FileIO.hpp"
#include
"FileIO.hpp"
...
@@ -19,7 +20,7 @@ void MpiWireworld::processArea(Coord start, Size size) {
...
@@ -19,7 +20,7 @@ void MpiWireworld::processArea(Coord start, Size size) {
// std::size_t is unsigned. modulo arithmetics is used for calculating the
// std::size_t is unsigned. modulo arithmetics is used for calculating the
// index
// index
const
std
::
size_t
leftOffset
=
-
1
;
const
std
::
size_t
leftOffset
=
std
::
numeric_limits
<
std
::
size_t
>::
max
();
//
-1;
const
std
::
size_t
rightOffset
=
1
;
const
std
::
size_t
rightOffset
=
1
;
const
std
::
size_t
downOffset
=
modelWidth
;
const
std
::
size_t
downOffset
=
modelWidth
;
const
std
::
size_t
upOffset
=
-
downOffset
;
const
std
::
size_t
upOffset
=
-
downOffset
;
...
@@ -33,13 +34,11 @@ void MpiWireworld::processArea(Coord start, Size size) {
...
@@ -33,13 +34,11 @@ void MpiWireworld::processArea(Coord start, Size size) {
switch
(
currentState
)
{
switch
(
currentState
)
{
case
State
::
ElectronHead
:
case
State
::
ElectronHead
:
return
State
::
ElectronTail
;
return
State
::
ElectronTail
;
break
;
case
State
::
ElectronTail
:
case
State
::
ElectronTail
:
return
State
::
Conductor
;
return
State
::
Conductor
;
break
;
case
State
::
Conductor
:
{
case
State
::
Conductor
:
{
const
auto
isHead
=
[
&
](
std
::
size_t
i
dx
)
{
const
auto
isHead
=
[
&
](
std
::
size_t
i
)
{
return
_model
[
i
dx
]
==
State
::
ElectronHead
?
1
:
0
;
return
_model
[
i
]
==
State
::
ElectronHead
?
1
:
0
;
};
};
const
auto
headCount
=
const
auto
headCount
=
isHead
(
idx
+
leftOffset
+
upOffset
)
+
//
isHead
(
idx
+
leftOffset
+
upOffset
)
+
//
...
@@ -54,10 +53,9 @@ void MpiWireworld::processArea(Coord start, Size size) {
...
@@ -54,10 +53,9 @@ void MpiWireworld::processArea(Coord start, Size size) {
return
(
1
==
headCount
||
headCount
==
2
)
return
(
1
==
headCount
||
headCount
==
2
)
?
State
::
ElectronHead
?
State
::
ElectronHead
:
State
::
Conductor
;
:
State
::
Conductor
;
}
break
;
};
default
:
case
State
::
Empty
:
return
currentState
;
return
currentState
;
break
;
}
}
}();
}();
}
}
...
@@ -65,7 +63,7 @@ void MpiWireworld::processArea(Coord start, Size size) {
...
@@ -65,7 +63,7 @@ void MpiWireworld::processArea(Coord start, Size size) {
}
}
MpiWireworld
::
MpiWireworld
(
const
MpiEnvironment
&
env
,
const
Configuration
&
cfg
)
MpiWireworld
::
MpiWireworld
(
const
MpiEnvironment
&
env
,
const
Configuration
&
cfg
)
:
_env
(
env
),
_cfg
(
cfg
),
_tile
(
Tile
::
Read
(
cfg
,
env
)),
:
_tile
(
Tile
::
Read
(
cfg
,
env
)),
_comm
(
env
,
cfg
.
CommMode
,
cfg
.
Procs
,
_tile
.
tileSize
())
{
_comm
(
env
,
cfg
.
CommMode
,
cfg
.
Procs
,
_tile
.
tileSize
())
{
_comm
.
Communicate
(
_tile
.
model
());
_comm
.
Communicate
(
_tile
.
model
());
}
}
...
...
cellular_automaton/wireworld_c++/MpiWireworld.hpp
View file @
1917780b
...
@@ -8,8 +8,6 @@
...
@@ -8,8 +8,6 @@
#include
"Tile.hpp"
#include
"Tile.hpp"