Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
La programmation parallèle pour les gens
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
baptiste.coudray
La programmation parallèle pour les gens
Commits
1a26d56c
Verified
Commit
1a26d56c
authored
3 years ago
by
baptiste.coudray
Browse files
Options
Downloads
Patches
Plain Diff
Added benchmark version
parent
58e89c99
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
game_of_life/CMakeLists.txt
+11
-0
11 additions, 0 deletions
game_of_life/CMakeLists.txt
game_of_life/benchmark/main.c
+328
-0
328 additions, 0 deletions
game_of_life/benchmark/main.c
game_of_life/main.c
+23
-22
23 additions, 22 deletions
game_of_life/main.c
with
362 additions
and
22 deletions
game_of_life/CMakeLists.txt
+
11
−
0
View file @
1a26d56c
...
...
@@ -40,3 +40,14 @@ endif ()
if
(
CMAKE_SYSTEM_NAME MATCHES
"Linux"
)
target_link_libraries
(
game_of_life_opencl OpenCL SDL2 m
${
MPI_C_LIBRARIES
}
)
endif
()
add_executable
(
game_of_life_opencl_bench benchmark/main.c gol.h gol.c
)
add_dependencies
(
game_of_life_opencl_bench futhark_opencl
)
if
(
CMAKE_SYSTEM_NAME MATCHES
"Darwin"
)
target_link_libraries
(
game_of_life_opencl_bench
"-framework OpenCL"
${
MPI_C_LIBRARIES
}
)
endif
()
if
(
CMAKE_SYSTEM_NAME MATCHES
"Linux"
)
target_link_libraries
(
game_of_life_opencl_bench OpenCL m
${
MPI_C_LIBRARIES
}
)
endif
()
This diff is collapsed.
Click to expand it.
game_of_life/benchmark/main.c
0 → 100644
+
328
−
0
View file @
1a26d56c
/**
* Author: Baptiste Coudray
* School: HEPIA
* Class: ITI-3
* Year 2020-2021
*/
#include
<stdio.h>
#include
<stdint.h>
#include
<mpi.h>
#include
<math.h>
#include
<stdbool.h>
#include
"../gol.h"
#define INDEX_2D_TO_1D(y, x, nb_columns) ((y) * nb_columns + (x))
#define NORTH_INDEX 0
#define EAST_INDEX 1
#define SOUTH_INDEX 2
#define WEST_INDEX 3
#define NORTH_ROW_TAG 0
#define EAST_COLUMN_TAG 1
#define SOUTH_ROW_TAG 2
#define WEST_COLUMN_TAG 3
#define NORTH_EAST_CELL_TAG 4
#define SOUTH_EAST_CELL_TAG 5
#define SOUTH_WEST_CELL_TAG 6
#define NORTH_WEST_CELL_TAG 7
#define CHUNK_BOARD_TAG 8
#define ROOT_RANK 0
#define FPS 60
int
createGridCommunicators
(
MPI_Comm
*
cartComm
,
MPI_Comm
*
rowComm
,
MPI_Comm
*
colComm
,
int
nProc
)
{
int
gridN
=
(
int
)
sqrt
(
nProc
);
int
dimensions
[
2
]
=
{
gridN
,
gridN
};
int
periods
[
2
]
=
{
true
,
true
};
// Cyclic on row-column
MPI_Cart_create
(
MPI_COMM_WORLD
,
2
,
dimensions
,
periods
,
1
,
cartComm
);
/* Create row communicator */
int
remainDims
[
2
]
=
{
false
,
true
};
MPI_Cart_sub
(
*
cartComm
,
remainDims
,
rowComm
);
/* Create column communicator */
remainDims
[
0
]
=
true
;
// rows
remainDims
[
1
]
=
false
;
// columns
MPI_Cart_sub
(
*
cartComm
,
remainDims
,
colComm
);
return
gridN
;
}
int
*
divideBoard
(
int
n
,
int
chunkN
,
int
nProc
)
{
int
*
indexes
=
calloc
((
size_t
)
nProc
*
2
,
sizeof
(
int
));
for
(
int
i
=
0
,
y
=
0
,
x
=
0
;
i
<
nProc
;
++
i
)
{
indexes
[
i
*
2
]
=
y
;
indexes
[
i
*
2
+
1
]
=
x
;
x
+=
chunkN
;
if
(
x
>=
n
)
{
x
=
0
;
y
+=
chunkN
;
}
}
return
indexes
;
}
void
initChunkBoard
(
int8_t
*
chunkBoard
,
int
chunkN
)
{
for
(
int
i
=
0
;
i
<
chunkN
;
++
i
)
{
for
(
int
j
=
0
;
j
<
chunkN
;
++
j
)
{
chunkBoard
[
INDEX_2D_TO_1D
(
i
,
j
,
chunkN
)]
=
rand
()
%
2
;
}
}
}
void
shareAndBuildEnvelope
(
int8_t
*
chunkBoardMyEnvelope
,
int8_t
*
chunkBoardEnvelope
,
MPI_Comm
rowComm
,
MPI_Comm
colComm
,
int
gridN
,
int
coordinates
[
2
],
int
chunkN
,
int
chunkM
)
{
int
coordinateY
=
coordinates
[
0
];
int
coordinateX
=
coordinates
[
1
];
MPI_Request
requests
[
16
]
=
{
0
};
int
iRequest
=
0
;
// North
{
int8_t
*
chunkBoardMyEnvelopeNorth
=
&
chunkBoardMyEnvelope
[
INDEX_2D_TO_1D
(
NORTH_INDEX
,
0
,
chunkN
)];
int8_t
*
chunkBoardEnvelopeNorth
=
&
chunkBoardEnvelope
[
INDEX_2D_TO_1D
(
NORTH_INDEX
,
1
,
chunkM
)];
int
destSource
=
(
coordinateY
-
1
)
<
0
?
(
gridN
-
1
)
:
(
coordinateY
-
1
);
MPI_Isend
(
chunkBoardMyEnvelopeNorth
,
chunkN
,
MPI_INT8_T
,
destSource
,
NORTH_ROW_TAG
,
colComm
,
&
requests
[
iRequest
++
]);
/* Neighbour send south row, which correspond to north envelope */
MPI_Irecv
(
chunkBoardEnvelopeNorth
,
chunkN
,
MPI_INT8_T
,
destSource
,
SOUTH_ROW_TAG
,
colComm
,
&
requests
[
iRequest
++
]);
}
// East
{
int8_t
*
chunkBoardMyEnvelopeEast
=
&
chunkBoardMyEnvelope
[
INDEX_2D_TO_1D
(
EAST_INDEX
,
0
,
chunkN
)];
int8_t
*
chunkBoardEnvelopeEast
=
&
chunkBoardEnvelope
[
INDEX_2D_TO_1D
(
EAST_INDEX
,
1
,
chunkM
)];
int
destSource
=
(
coordinateX
+
1
)
%
gridN
;
MPI_Isend
(
chunkBoardMyEnvelopeEast
,
chunkN
,
MPI_INT8_T
,
destSource
,
EAST_COLUMN_TAG
,
rowComm
,
&
requests
[
iRequest
++
]);
/* Neighbour send west column, which correspond to east envelope */
MPI_Irecv
(
chunkBoardEnvelopeEast
,
chunkN
,
MPI_INT8_T
,
destSource
,
WEST_COLUMN_TAG
,
rowComm
,
&
requests
[
iRequest
++
]);
}
// South
{
int8_t
*
chunkBoardMyEnvelopeSouth
=
&
chunkBoardMyEnvelope
[
INDEX_2D_TO_1D
(
SOUTH_INDEX
,
0
,
chunkN
)];
int8_t
*
chunkBoardEnvelopeSouth
=
&
chunkBoardEnvelope
[
INDEX_2D_TO_1D
(
SOUTH_INDEX
,
1
,
chunkM
)];
int
destSource
=
(
coordinateY
+
1
)
%
gridN
;
MPI_Isend
(
chunkBoardMyEnvelopeSouth
,
chunkN
,
MPI_INT8_T
,
destSource
,
SOUTH_ROW_TAG
,
colComm
,
&
requests
[
iRequest
++
]);
/* Neighbour send north row, which correspond to south envelope */
MPI_Irecv
(
chunkBoardEnvelopeSouth
,
chunkN
,
MPI_INT8_T
,
destSource
,
NORTH_ROW_TAG
,
colComm
,
&
requests
[
iRequest
++
]);
}
// West
{
int8_t
*
chunkBoardMyEnvelopeWest
=
&
chunkBoardMyEnvelope
[
INDEX_2D_TO_1D
(
WEST_INDEX
,
0
,
chunkN
)];
int8_t
*
chunkBoardEnvelopeWest
=
&
chunkBoardEnvelope
[
INDEX_2D_TO_1D
(
WEST_INDEX
,
1
,
chunkM
)];
int
destSource
=
(
coordinateX
-
1
)
<
0
?
(
gridN
-
1
)
:
(
coordinateX
-
1
);
MPI_Isend
(
chunkBoardMyEnvelopeWest
,
chunkN
,
MPI_INT8_T
,
destSource
,
WEST_COLUMN_TAG
,
rowComm
,
&
requests
[
iRequest
++
]);
/* Neighbour send east column, which correspond to west envelope */
MPI_Irecv
(
chunkBoardEnvelopeWest
,
chunkN
,
MPI_INT8_T
,
destSource
,
EAST_COLUMN_TAG
,
rowComm
,
&
requests
[
iRequest
++
]);
}
int8_t
missingCells
[
4
]
=
{
0
};
// North-East
{
int8_t
*
chunkBoardMyEnvelopeNorthEast
=
&
chunkBoardMyEnvelope
[
INDEX_2D_TO_1D
(
NORTH_INDEX
,
chunkN
-
1
,
chunkN
)];
int
destSrcY
=
(
coordinateY
-
1
)
<
0
?
gridN
-
1
:
coordinateY
-
1
;
int
destSrcX
=
(
coordinateX
+
1
)
%
gridN
;
int
destSource
=
INDEX_2D_TO_1D
(
destSrcY
,
destSrcX
,
gridN
);
MPI_Isend
(
chunkBoardMyEnvelopeNorthEast
,
1
,
MPI_INT8_T
,
destSource
,
NORTH_EAST_CELL_TAG
,
MPI_COMM_WORLD
,
&
requests
[
iRequest
++
]);
/* Neighbour send south-west cell, which correspond to north-east cell */
MPI_Irecv
(
&
missingCells
[
1
],
1
,
MPI_INT8_T
,
destSource
,
SOUTH_WEST_CELL_TAG
,
MPI_COMM_WORLD
,
&
requests
[
iRequest
++
]);
}
// South-East
{
int8_t
*
chunkBoardMyEnvelopeSouthEast
=
&
chunkBoardMyEnvelope
[
INDEX_2D_TO_1D
(
SOUTH_INDEX
,
chunkN
-
1
,
chunkN
)];
int
destSrcY
=
(
coordinateY
+
1
)
%
gridN
;
int
destSrcX
=
(
coordinateX
+
1
)
%
gridN
;
int
destSource
=
INDEX_2D_TO_1D
(
destSrcY
,
destSrcX
,
gridN
);
MPI_Isend
(
chunkBoardMyEnvelopeSouthEast
,
1
,
MPI_INT8_T
,
destSource
,
SOUTH_EAST_CELL_TAG
,
MPI_COMM_WORLD
,
&
requests
[
iRequest
++
]);
/* Neighbour send north-west cell, which correspond to south-east cell */
MPI_Irecv
(
&
missingCells
[
2
],
1
,
MPI_INT8_T
,
destSource
,
NORTH_WEST_CELL_TAG
,
MPI_COMM_WORLD
,
&
requests
[
iRequest
++
]);
}
// South-West
{
int8_t
*
chunkBoardMyEnvelopeSouthWest
=
&
chunkBoardMyEnvelope
[
INDEX_2D_TO_1D
(
SOUTH_INDEX
,
0
,
chunkN
)];
int
destSrcY
=
(
coordinateY
+
1
)
%
gridN
;
int
destSrcX
=
(
coordinateX
-
1
)
<
0
?
gridN
-
1
:
coordinateX
-
1
;
int
destSource
=
INDEX_2D_TO_1D
(
destSrcY
,
destSrcX
,
gridN
);
MPI_Isend
(
chunkBoardMyEnvelopeSouthWest
,
1
,
MPI_INT8_T
,
destSource
,
SOUTH_WEST_CELL_TAG
,
MPI_COMM_WORLD
,
&
requests
[
iRequest
++
]);
/* Neighbour send north-east cell, which correspond to south-west cell */
MPI_Irecv
(
&
missingCells
[
3
],
1
,
MPI_INT8_T
,
destSource
,
NORTH_EAST_CELL_TAG
,
MPI_COMM_WORLD
,
&
requests
[
iRequest
++
]);
}
// North-West
{
int8_t
*
chunkBoardMyEnvelopeNorthWest
=
&
chunkBoardMyEnvelope
[
INDEX_2D_TO_1D
(
NORTH_INDEX
,
0
,
chunkN
)];
int
destSrcY
=
(
coordinateY
-
1
)
<
0
?
gridN
-
1
:
coordinateY
-
1
;
int
destSrcX
=
(
coordinateX
-
1
)
<
0
?
gridN
-
1
:
coordinateX
-
1
;
int
destSource
=
INDEX_2D_TO_1D
(
destSrcY
,
destSrcX
,
gridN
);
MPI_Isend
(
chunkBoardMyEnvelopeNorthWest
,
1
,
MPI_INT8_T
,
destSource
,
NORTH_WEST_CELL_TAG
,
MPI_COMM_WORLD
,
&
requests
[
iRequest
++
]);
/* Neighbour send south-east cell, which correspond to north-west cell */
MPI_Irecv
(
&
missingCells
[
0
],
1
,
MPI_INT8_T
,
destSource
,
SOUTH_EAST_CELL_TAG
,
MPI_COMM_WORLD
,
&
requests
[
iRequest
]);
}
MPI_Waitall
(
16
,
requests
,
MPI_STATUSES_IGNORE
);
/* Copy missing cells into the envelope */
chunkBoardEnvelope
[
INDEX_2D_TO_1D
(
NORTH_INDEX
,
chunkN
,
chunkM
)]
=
chunkBoardEnvelope
[
INDEX_2D_TO_1D
(
EAST_INDEX
,
0
,
chunkM
)]
=
missingCells
[
1
];
chunkBoardEnvelope
[
INDEX_2D_TO_1D
(
SOUTH_INDEX
,
chunkN
,
chunkM
)]
=
chunkBoardEnvelope
[
INDEX_2D_TO_1D
(
EAST_INDEX
,
chunkN
,
chunkM
)]
=
missingCells
[
2
];
chunkBoardEnvelope
[
INDEX_2D_TO_1D
(
SOUTH_INDEX
,
0
,
chunkM
)]
=
chunkBoardEnvelope
[
INDEX_2D_TO_1D
(
WEST_INDEX
,
chunkN
,
chunkM
)]
=
missingCells
[
3
];
chunkBoardEnvelope
[
INDEX_2D_TO_1D
(
NORTH_INDEX
,
0
,
chunkM
)]
=
chunkBoardEnvelope
[
INDEX_2D_TO_1D
(
WEST_INDEX
,
0
,
chunkM
)]
=
missingCells
[
0
];
}
void
chunkBoardToBoard
(
int8_t
*
board
,
int
n
,
const
int8_t
*
chunkBoard
,
int
chunkN
,
const
int
*
indexes
,
int
rank
)
{
int
y
=
indexes
[
rank
*
2
];
int
x
=
indexes
[
rank
*
2
+
1
];
for
(
int
i
=
0
;
i
<
chunkN
;
++
i
)
{
for
(
int
j
=
0
;
j
<
chunkN
;
++
j
)
{
board
[
INDEX_2D_TO_1D
(
y
+
i
,
x
+
j
,
n
)]
=
chunkBoard
[
INDEX_2D_TO_1D
(
i
,
j
,
chunkN
)];
}
}
}
int
main
(
int
argc
,
char
*
argv
[])
{
if
(
argc
<
3
)
{
printf
(
"%s <deviceName> <boardN>
\n
"
,
argv
[
0
]);
exit
(
0
);
}
int
myRank
;
int
nProc
;
double
start
=
MPI_Wtime
();
/* MPI Initialization */
MPI_Init
(
&
argc
,
&
argv
);
MPI_Comm_rank
(
MPI_COMM_WORLD
,
&
myRank
);
MPI_Comm_size
(
MPI_COMM_WORLD
,
&
nProc
);
srand
((
unsigned
int
)
myRank
);
MPI_Comm
cartComm
,
rowComm
,
colComm
;
int
gridN
=
createGridCommunicators
(
&
cartComm
,
&
rowComm
,
&
colComm
,
nProc
);
int
myCartRank
;
MPI_Comm_rank
(
cartComm
,
&
myCartRank
);
int
coordinates
[
2
]
=
{
0
};
MPI_Cart_coords
(
cartComm
,
myCartRank
,
2
,
coordinates
);
/* Futhark Initialization */
struct
futhark_context_config
*
contextConfig
=
futhark_context_config_new
();
futhark_context_config_set_device
(
contextConfig
,
argv
[
1
]);
struct
futhark_context
*
futharkContext
=
futhark_context_new
(
contextConfig
);
/* GoL Initialization */
int
boardN
=
atoi
(
argv
[
2
]);
int
boardNN
=
boardN
*
boardN
;
int
chunkN
=
(
int
)
(
boardN
/
sqrt
(
nProc
));
int
chunkNN
=
chunkN
*
chunkN
;
int
chunkM
=
chunkN
+
2
;
int
*
indexes
=
divideBoard
(
boardN
,
chunkN
,
nProc
);
int8_t
*
board
=
myRank
==
ROOT_RANK
?
calloc
((
size_t
)
boardNN
,
sizeof
(
int8_t
))
:
NULL
;
int8_t
*
chunkBoard
=
calloc
((
size_t
)
chunkNN
,
sizeof
(
int8_t
));
int8_t
*
chunkBoardMyEnvelope
=
calloc
(((
size_t
)
(
4
*
chunkN
)),
sizeof
(
int8_t
));
int8_t
*
chunkBoardEnvelope
=
calloc
(((
size_t
)
(
4
*
chunkM
)),
sizeof
(
int8_t
));
initChunkBoard
(
chunkBoard
,
chunkN
);
struct
futhark_i8_2d
*
futChunkBoard
=
futhark_new_i8_2d
(
futharkContext
,
chunkBoard
,
chunkN
,
chunkN
);
futhark_context_sync
(
futharkContext
);
struct
futhark_i8_2d
*
futChunkBoardMyEnvelope
;
futhark_entry_get_envelope
(
futharkContext
,
&
futChunkBoardMyEnvelope
,
futChunkBoard
);
futhark_context_sync
(
futharkContext
);
futhark_values_i8_2d
(
futharkContext
,
futChunkBoardMyEnvelope
,
chunkBoardMyEnvelope
);
futhark_context_sync
(
futharkContext
);
shareAndBuildEnvelope
(
chunkBoardMyEnvelope
,
chunkBoardEnvelope
,
rowComm
,
colComm
,
gridN
,
coordinates
,
chunkN
,
chunkM
);
struct
futhark_i8_2d
*
futChunkBoardEnvelope
=
futhark_new_i8_2d
(
futharkContext
,
chunkBoardEnvelope
,
4
,
chunkM
);
futhark_context_sync
(
futharkContext
);
struct
futhark_i8_2d
*
futNextChunkBoard
;
futhark_entry_next_chunk_board
(
futharkContext
,
&
futNextChunkBoard
,
futChunkBoard
,
futChunkBoardEnvelope
);
futhark_context_sync
(
futharkContext
);
futhark_values_i8_2d
(
futharkContext
,
futNextChunkBoard
,
chunkBoard
);
futhark_context_sync
(
futharkContext
);
if
(
myRank
==
ROOT_RANK
)
{
chunkBoardToBoard
(
board
,
boardN
,
chunkBoard
,
chunkN
,
indexes
,
myRank
);
int8_t
*
tmpChunkBoard
=
calloc
((
size_t
)
chunkNN
,
sizeof
(
int8_t
));
MPI_Status
status
=
{
0
};
for
(
int
i
=
0
;
i
<
nProc
-
1
;
++
i
)
{
MPI_Recv
(
tmpChunkBoard
,
chunkNN
,
MPI_INT8_T
,
MPI_ANY_SOURCE
,
CHUNK_BOARD_TAG
,
MPI_COMM_WORLD
,
&
status
);
chunkBoardToBoard
(
board
,
boardN
,
tmpChunkBoard
,
chunkN
,
indexes
,
status
.
MPI_SOURCE
);
}
free
(
tmpChunkBoard
);
}
else
{
MPI_Send
(
chunkBoard
,
chunkNN
,
MPI_INT8_T
,
ROOT_RANK
,
CHUNK_BOARD_TAG
,
MPI_COMM_WORLD
);
}
futhark_context_sync
(
futharkContext
);
futhark_free_i8_2d
(
futharkContext
,
futChunkBoard
);
futhark_free_i8_2d
(
futharkContext
,
futChunkBoardMyEnvelope
);
futhark_free_i8_2d
(
futharkContext
,
futChunkBoardEnvelope
);
futhark_free_i8_2d
(
futharkContext
,
futNextChunkBoard
);
free
(
indexes
);
free
(
chunkBoard
);
free
(
chunkBoardEnvelope
);
free
(
chunkBoardMyEnvelope
);
if
(
myRank
==
ROOT_RANK
)
{
free
(
board
);
}
futhark_context_free
(
futharkContext
);
futhark_context_config_free
(
contextConfig
);
MPI_Comm_free
(
&
cartComm
);
MPI_Comm_free
(
&
rowComm
);
MPI_Comm_free
(
&
colComm
);
double
finish
=
MPI_Wtime
();
if
(
myRank
==
ROOT_RANK
)
{
printf
(
"%d;%f
\n
"
,
nProc
,
finish
-
start
);
}
MPI_Finalize
();
return
0
;
}
This diff is collapsed.
Click to expand it.
game_of_life/main.c
+
23
−
22
View file @
1a26d56c
...
...
@@ -14,8 +14,6 @@
#include
"gol.h"
#include
"gfx.h"
#define BOARD_N 800
#define INDEX_2D_TO_1D(y, x, nb_columns) ((y) * nb_columns + (x))
#define NORTH_INDEX 0
...
...
@@ -224,8 +222,8 @@ void chunkBoardToBoard(int8_t *board, int n, const int8_t *chunkBoard, int chunk
}
int
main
(
int
argc
,
char
*
argv
[])
{
if
(
argc
<
2
)
{
printf
(
"
You need to specify an OpenCL device.
\n
"
);
if
(
argc
<
3
)
{
printf
(
"
%s <deviceName> <boardN>
\n
"
,
argv
[
0
]
);
exit
(
0
);
}
int
myRank
;
...
...
@@ -251,29 +249,32 @@ int main(int argc, char *argv[]) {
futhark_context_config_set_device
(
contextConfig
,
argv
[
1
]);
struct
futhark_context
*
futharkContext
=
futhark_context_new
(
contextConfig
);
/* GFX Initialization */
struct
gfx_context_t
*
gfxContext
=
myRank
==
ROOT_RANK
?
gfx_create
(
"Game of Life"
,
BOARD_N
,
BOARD_N
)
:
NULL
;
if
(
myRank
==
ROOT_RANK
&&
!
gfxContext
)
{
fprintf
(
stderr
,
"Graphic mode initialization failed!
\n
"
);
return
EXIT_FAILURE
;
}
if
(
myRank
==
ROOT_RANK
)
{
SDL_ShowCursor
(
SDL_ENABLE
);
}
/* GoL Initialization */
int
chunkN
=
(
int
)
(
BOARD_N
/
sqrt
(
nProc
));
int
boardN
=
atoi
(
argv
[
2
]);
int
boardNN
=
boardN
*
boardN
;
int
chunkN
=
(
int
)
(
boardN
/
sqrt
(
nProc
));
int
chunkNN
=
chunkN
*
chunkN
;
int
chunkM
=
chunkN
+
2
;
int
*
indexes
=
divideBoard
(
BOARD_
N
,
chunkN
,
nProc
);
int
*
indexes
=
divideBoard
(
board
N
,
chunkN
,
nProc
);
int8_t
*
board
=
myRank
==
ROOT_RANK
?
calloc
(
BOARD_N
*
BOARD_
N
,
sizeof
(
int8_t
))
:
NULL
;
int8_t
*
board
=
myRank
==
ROOT_RANK
?
calloc
(
(
size_t
)
boardN
N
,
sizeof
(
int8_t
))
:
NULL
;
int8_t
*
chunkBoard
=
calloc
((
size_t
)
chunkNN
,
sizeof
(
int8_t
));
int8_t
*
chunkBoardMyEnvelope
=
calloc
(((
size_t
)
(
4
*
chunkN
)),
sizeof
(
int8_t
));
int8_t
*
chunkBoardEnvelope
=
calloc
(((
size_t
)
(
4
*
chunkM
)),
sizeof
(
int8_t
));
initChunkBoard
(
chunkBoard
,
chunkN
);
/* GFX Initialization */
struct
gfx_context_t
*
gfxContext
=
myRank
==
ROOT_RANK
?
gfx_create
(
"Game of Life"
,
(
uint
)
boardN
,
(
uint
)
boardN
)
:
NULL
;
if
(
myRank
==
ROOT_RANK
&&
!
gfxContext
)
{
fprintf
(
stderr
,
"Graphic mode initialization failed!
\n
"
);
return
EXIT_FAILURE
;
}
if
(
myRank
==
ROOT_RANK
)
{
SDL_ShowCursor
(
SDL_ENABLE
);
}
bool
exit
=
false
;
while
(
!
exit
)
{
struct
futhark_i8_2d
*
futChunkBoard
=
futhark_new_i8_2d
(
futharkContext
,
chunkBoard
,
chunkN
,
chunkN
);
...
...
@@ -296,12 +297,12 @@ int main(int argc, char *argv[]) {
futhark_context_sync
(
futharkContext
);
if
(
myRank
==
ROOT_RANK
)
{
chunkBoardToBoard
(
board
,
BOARD_
N
,
chunkBoard
,
chunkN
,
indexes
,
myRank
);
chunkBoardToBoard
(
board
,
board
N
,
chunkBoard
,
chunkN
,
indexes
,
myRank
);
int8_t
*
tmpChunkBoard
=
calloc
((
size_t
)
chunkNN
,
sizeof
(
int8_t
));
MPI_Status
status
=
{
0
};
for
(
int
i
=
0
;
i
<
nProc
-
1
;
++
i
)
{
MPI_Recv
(
tmpChunkBoard
,
chunkNN
,
MPI_INT8_T
,
MPI_ANY_SOURCE
,
CHUNK_BOARD_TAG
,
MPI_COMM_WORLD
,
&
status
);
chunkBoardToBoard
(
board
,
BOARD_
N
,
tmpChunkBoard
,
chunkN
,
indexes
,
status
.
MPI_SOURCE
);
chunkBoardToBoard
(
board
,
board
N
,
tmpChunkBoard
,
chunkN
,
indexes
,
status
.
MPI_SOURCE
);
}
free
(
tmpChunkBoard
);
}
else
{
...
...
@@ -317,9 +318,9 @@ int main(int argc, char *argv[]) {
(
event
.
type
==
SDL_WINDOWEVENT
&&
event
.
window
.
event
==
SDL_WINDOWEVENT_CLOSE
);
gfx_clear
(
gfxContext
,
COLOR_BLACK
);
for
(
int
y
=
0
;
y
<
BOARD_
N
;
++
y
)
{
for
(
int
x
=
0
;
x
<
BOARD_
N
;
++
x
)
{
int
cell
=
(
int
)
board
[
INDEX_2D_TO_1D
(
y
,
x
,
BOARD_
N
)];
for
(
int
y
=
0
;
y
<
board
N
;
++
y
)
{
for
(
int
x
=
0
;
x
<
board
N
;
++
x
)
{
int
cell
=
(
int
)
board
[
INDEX_2D_TO_1D
(
y
,
x
,
board
N
)];
gfx_putpixel
(
gfxContext
,
x
,
y
,
MAKE_COLOR
(
cell
*
255
,
cell
*
255
,
cell
*
255
));
}
}
...
...
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