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
55c09cb9
"prog_seq_c_tp/shortest_path/test.pdf" did not exist on "b103362dc8dc9100d7b680ded4eaf552487212d6"
Verified
Commit
55c09cb9
authored
3 years ago
by
baptiste.coudray
Browse files
Options
Downloads
Patches
Plain Diff
Added comment and moved magic value to constant
parent
12b23d9a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
game_of_life/main.c
+24
-18
24 additions, 18 deletions
game_of_life/main.c
with
24 additions
and
18 deletions
game_of_life/main.c
+
24
−
18
View file @
55c09cb9
/**
* Author: Baptiste Coudray
* School: HEPIA
* Class: ITI-3
* Year 2020-2021
*/
#include
<stdio.h>
#include
<stdio.h>
#include
<stdint.h>
#include
<stdint.h>
#include
<mpi.h>
#include
<mpi.h>
...
@@ -28,14 +35,8 @@
...
@@ -28,14 +35,8 @@
#define CHUNK_BOARD_TAG 8
#define CHUNK_BOARD_TAG 8
//void printChunkBoard(int8_t *chunkBoard, int n1, int n2) {
#define ROOT_RANK 0
// for (int i = 0; i < n1; ++i) {
#define FPS 60
// for (int j = 0; j < n2; ++j) {
// printf("%d ", chunkBoard[INDEX_2D_TO_1D(i, j, n2)]);
// }
// printf("\n");
// }
//}
int
createGridCommunicators
(
MPI_Comm
*
cartComm
,
MPI_Comm
*
rowComm
,
MPI_Comm
*
colComm
,
int
nProc
)
{
int
createGridCommunicators
(
MPI_Comm
*
cartComm
,
MPI_Comm
*
rowComm
,
MPI_Comm
*
colComm
,
int
nProc
)
{
int
gridN
=
(
int
)
sqrt
(
nProc
);
int
gridN
=
(
int
)
sqrt
(
nProc
);
...
@@ -148,6 +149,7 @@ void shareAndBuildEnvelope(int8_t *chunkBoardMyEnvelope, int8_t *chunkBoardEnvel
...
@@ -148,6 +149,7 @@ void shareAndBuildEnvelope(int8_t *chunkBoardMyEnvelope, int8_t *chunkBoardEnvel
MPI_Isend
(
chunkBoardMyEnvelopeNorthEast
,
1
,
MPI_INT8_T
,
destSource
,
NORTH_EAST_CELL_TAG
,
MPI_COMM_WORLD
,
MPI_Isend
(
chunkBoardMyEnvelopeNorthEast
,
1
,
MPI_INT8_T
,
destSource
,
NORTH_EAST_CELL_TAG
,
MPI_COMM_WORLD
,
&
requests
[
iRequest
++
]);
&
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
,
MPI_Irecv
(
&
missingCells
[
1
],
1
,
MPI_INT8_T
,
destSource
,
SOUTH_WEST_CELL_TAG
,
MPI_COMM_WORLD
,
&
requests
[
iRequest
++
]);
&
requests
[
iRequest
++
]);
}
}
...
@@ -161,6 +163,7 @@ void shareAndBuildEnvelope(int8_t *chunkBoardMyEnvelope, int8_t *chunkBoardEnvel
...
@@ -161,6 +163,7 @@ void shareAndBuildEnvelope(int8_t *chunkBoardMyEnvelope, int8_t *chunkBoardEnvel
MPI_Isend
(
chunkBoardMyEnvelopeSouthEast
,
1
,
MPI_INT8_T
,
destSource
,
SOUTH_EAST_CELL_TAG
,
MPI_COMM_WORLD
,
MPI_Isend
(
chunkBoardMyEnvelopeSouthEast
,
1
,
MPI_INT8_T
,
destSource
,
SOUTH_EAST_CELL_TAG
,
MPI_COMM_WORLD
,
&
requests
[
iRequest
++
]);
&
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
,
MPI_Irecv
(
&
missingCells
[
2
],
1
,
MPI_INT8_T
,
destSource
,
NORTH_WEST_CELL_TAG
,
MPI_COMM_WORLD
,
&
requests
[
iRequest
++
]);
&
requests
[
iRequest
++
]);
}
}
...
@@ -174,6 +177,7 @@ void shareAndBuildEnvelope(int8_t *chunkBoardMyEnvelope, int8_t *chunkBoardEnvel
...
@@ -174,6 +177,7 @@ void shareAndBuildEnvelope(int8_t *chunkBoardMyEnvelope, int8_t *chunkBoardEnvel
MPI_Isend
(
chunkBoardMyEnvelopeSouthWest
,
1
,
MPI_INT8_T
,
destSource
,
SOUTH_WEST_CELL_TAG
,
MPI_COMM_WORLD
,
MPI_Isend
(
chunkBoardMyEnvelopeSouthWest
,
1
,
MPI_INT8_T
,
destSource
,
SOUTH_WEST_CELL_TAG
,
MPI_COMM_WORLD
,
&
requests
[
iRequest
++
]);
&
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
,
MPI_Irecv
(
&
missingCells
[
3
],
1
,
MPI_INT8_T
,
destSource
,
NORTH_EAST_CELL_TAG
,
MPI_COMM_WORLD
,
&
requests
[
iRequest
++
]);
&
requests
[
iRequest
++
]);
}
}
...
@@ -187,12 +191,14 @@ void shareAndBuildEnvelope(int8_t *chunkBoardMyEnvelope, int8_t *chunkBoardEnvel
...
@@ -187,12 +191,14 @@ void shareAndBuildEnvelope(int8_t *chunkBoardMyEnvelope, int8_t *chunkBoardEnvel
MPI_Isend
(
chunkBoardMyEnvelopeNorthWest
,
1
,
MPI_INT8_T
,
destSource
,
NORTH_WEST_CELL_TAG
,
MPI_COMM_WORLD
,
MPI_Isend
(
chunkBoardMyEnvelopeNorthWest
,
1
,
MPI_INT8_T
,
destSource
,
NORTH_WEST_CELL_TAG
,
MPI_COMM_WORLD
,
&
requests
[
iRequest
++
]);
&
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
,
MPI_Irecv
(
&
missingCells
[
0
],
1
,
MPI_INT8_T
,
destSource
,
SOUTH_EAST_CELL_TAG
,
MPI_COMM_WORLD
,
&
requests
[
iRequest
]);
&
requests
[
iRequest
]);
}
}
MPI_Waitall
(
16
,
requests
,
MPI_STATUSES_IGNORE
);
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
(
chunkBoardEnvelope
[
INDEX_2D_TO_1D
(
NORTH_INDEX
,
chunkN
,
chunkM
)]
=
chunkBoardEnvelope
[
INDEX_2D_TO_1D
(
EAST_INDEX
,
0
,
chunkM
)]
=
missingCells
[
1
];
EAST_INDEX
,
0
,
chunkM
)]
=
missingCells
[
1
];
chunkBoardEnvelope
[
INDEX_2D_TO_1D
(
SOUTH_INDEX
,
chunkN
,
chunkM
)]
=
chunkBoardEnvelope
[
INDEX_2D_TO_1D
(
EAST_INDEX
,
chunkBoardEnvelope
[
INDEX_2D_TO_1D
(
SOUTH_INDEX
,
chunkN
,
chunkM
)]
=
chunkBoardEnvelope
[
INDEX_2D_TO_1D
(
EAST_INDEX
,
...
@@ -246,12 +252,12 @@ int main(int argc, char *argv[]) {
...
@@ -246,12 +252,12 @@ int main(int argc, char *argv[]) {
struct
futhark_context
*
futharkContext
=
futhark_context_new
(
contextConfig
);
struct
futhark_context
*
futharkContext
=
futhark_context_new
(
contextConfig
);
/* GFX Initialization */
/* GFX Initialization */
struct
gfx_context_t
*
gfxContext
=
myRank
==
0
?
gfx_create
(
"Game of Life"
,
BOARD_N
,
BOARD_N
)
:
NULL
;
struct
gfx_context_t
*
gfxContext
=
myRank
==
ROOT_RANK
?
gfx_create
(
"Game of Life"
,
BOARD_N
,
BOARD_N
)
:
NULL
;
if
(
myRank
==
0
&&
!
gfxContext
)
{
if
(
myRank
==
ROOT_RANK
&&
!
gfxContext
)
{
fprintf
(
stderr
,
"Graphic mode initialization failed!
\n
"
);
fprintf
(
stderr
,
"Graphic mode initialization failed!
\n
"
);
return
EXIT_FAILURE
;
return
EXIT_FAILURE
;
}
}
if
(
myRank
==
0
)
{
if
(
myRank
==
ROOT_RANK
)
{
SDL_ShowCursor
(
SDL_ENABLE
);
SDL_ShowCursor
(
SDL_ENABLE
);
}
}
...
@@ -261,7 +267,7 @@ int main(int argc, char *argv[]) {
...
@@ -261,7 +267,7 @@ int main(int argc, char *argv[]) {
int
chunkM
=
chunkN
+
2
;
int
chunkM
=
chunkN
+
2
;
int
*
indexes
=
divideBoard
(
BOARD_N
,
chunkN
,
nProc
);
int
*
indexes
=
divideBoard
(
BOARD_N
,
chunkN
,
nProc
);
int8_t
*
board
=
myRank
==
0
?
calloc
(
BOARD_N
*
BOARD_N
,
sizeof
(
int8_t
))
:
NULL
;
int8_t
*
board
=
myRank
==
ROOT_RANK
?
calloc
(
BOARD_N
*
BOARD_N
,
sizeof
(
int8_t
))
:
NULL
;
int8_t
*
chunkBoard
=
calloc
((
size_t
)
chunkNN
,
sizeof
(
int8_t
));
int8_t
*
chunkBoard
=
calloc
((
size_t
)
chunkNN
,
sizeof
(
int8_t
));
int8_t
*
chunkBoardMyEnvelope
=
calloc
(((
size_t
)
(
4
*
chunkN
)),
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
));
int8_t
*
chunkBoardEnvelope
=
calloc
(((
size_t
)
(
4
*
chunkM
)),
sizeof
(
int8_t
));
...
@@ -289,7 +295,7 @@ int main(int argc, char *argv[]) {
...
@@ -289,7 +295,7 @@ int main(int argc, char *argv[]) {
futhark_values_i8_2d
(
futharkContext
,
futNextChunkBoard
,
chunkBoard
);
futhark_values_i8_2d
(
futharkContext
,
futNextChunkBoard
,
chunkBoard
);
futhark_context_sync
(
futharkContext
);
futhark_context_sync
(
futharkContext
);
if
(
myRank
==
0
)
{
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
));
int8_t
*
tmpChunkBoard
=
calloc
((
size_t
)
chunkNN
,
sizeof
(
int8_t
));
MPI_Status
status
=
{
0
};
MPI_Status
status
=
{
0
};
...
@@ -299,10 +305,10 @@ int main(int argc, char *argv[]) {
...
@@ -299,10 +305,10 @@ int main(int argc, char *argv[]) {
}
}
free
(
tmpChunkBoard
);
free
(
tmpChunkBoard
);
}
else
{
}
else
{
MPI_Send
(
chunkBoard
,
chunkNN
,
MPI_INT8_T
,
0
,
CHUNK_BOARD_TAG
,
MPI_COMM_WORLD
);
MPI_Send
(
chunkBoard
,
chunkNN
,
MPI_INT8_T
,
ROOT_RANK
,
CHUNK_BOARD_TAG
,
MPI_COMM_WORLD
);
}
}
if
(
myRank
==
0
)
{
if
(
myRank
==
ROOT_RANK
)
{
SDL_PumpEvents
();
SDL_PumpEvents
();
SDL_Event
event
;
SDL_Event
event
;
SDL_PollEvent
(
&
event
);
SDL_PollEvent
(
&
event
);
...
@@ -326,8 +332,8 @@ int main(int argc, char *argv[]) {
...
@@ -326,8 +332,8 @@ int main(int argc, char *argv[]) {
futhark_free_i8_2d
(
futharkContext
,
futChunkBoardEnvelope
);
futhark_free_i8_2d
(
futharkContext
,
futChunkBoardEnvelope
);
futhark_free_i8_2d
(
futharkContext
,
futNextChunkBoard
);
futhark_free_i8_2d
(
futharkContext
,
futNextChunkBoard
);
MPI_Bcast
(
&
exit
,
1
,
MPI_C_BOOL
,
0
,
MPI_COMM_WORLD
);
MPI_Bcast
(
&
exit
,
1
,
MPI_C_BOOL
,
ROOT_RANK
,
MPI_COMM_WORLD
);
usleep
(
1
6666
);
usleep
(
1
000000
/
FPS
);
}
}
free
(
indexes
);
free
(
indexes
);
...
@@ -335,7 +341,7 @@ int main(int argc, char *argv[]) {
...
@@ -335,7 +341,7 @@ int main(int argc, char *argv[]) {
free
(
chunkBoardEnvelope
);
free
(
chunkBoardEnvelope
);
free
(
chunkBoardMyEnvelope
);
free
(
chunkBoardMyEnvelope
);
if
(
myRank
==
0
)
{
if
(
myRank
==
ROOT_RANK
)
{
free
(
board
);
free
(
board
);
gfx_destroy
(
gfxContext
);
gfx_destroy
(
gfxContext
);
}
}
...
...
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