Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F90752194
game-of-life.cc
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Nov 4, 10:50
Size
1 KB
Mime Type
text/x-c
Expires
Wed, Nov 6, 10:50 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
22129513
Attached To
rSCMINICLUSTER SCITAS Mini Cluster
game-of-life.cc
View Options
#include "simu_gol.hh"
#include "cppargparse/cppargparse.hh"
#include <iostream>
#include <mpi.h>
int
main
(
int
argc
,
char
**
argv
)
{
cppargparse
::
ArgumentParser
parser
;
parser
.
addArgument
(
"-s;--server"
,
"Server to connect to for visualization"
,
1
,
cppargparse
::
_string
,
"127.0.0.1"
);
parser
.
addArgument
(
"-p;--port"
,
"Port"
,
1
,
cppargparse
::
_integer
,
4321
);
parser
.
addArgument
(
"--no_visu"
,
"Do not connect to a visualization server"
,
0
,
cppargparse
::
_boolean
,
false
,
true
);
parser
.
addArgument
(
"-r;--random"
,
"Init at random"
,
0
,
cppargparse
::
_boolean
,
false
,
true
);
parser
.
addArgument
(
"-g;--grid"
,
"Grid height width"
,
2
,
cppargparse
::
_integer
);
parser
.
parse
(
argc
,
argv
);
int
provided
;
MPI_Init_thread
(
&
argc
,
&
argv
,
MPI_THREAD_MULTIPLE
,
&
provided
);
long
int
dims
[
2
]
=
{
216
,
384
};
if
(
parser
.
has
(
"grid"
))
{
std
::
vector
<
int
>
grid_dims
=
parser
[
"grid"
];
dims
[
0
]
=
grid_dims
[
0
];
dims
[
1
]
=
grid_dims
[
1
];
}
//long int dims[2] = {21, 21};
GOL
*
simu
;
if
(
bool
(
parser
[
"no_visu"
]))
simu
=
new
GOL
(
dims
,
1
,
true
,
MPI_COMM_WORLD
);
else
simu
=
new
GOL
(
dims
,
1
,
true
,
MPI_COMM_WORLD
,
parser
[
"server"
],
parser
[
"port"
]);
simu
->
initialState
(
parser
[
"random"
]);
while
(
true
)
{
#pragma omp parallel default(shared)
{
#pragma omp single
{
simu
->
send
();
}
int
tid
=
omp_get_thread_num
();
simu
->
determineCells
(
tid
);
#pragma omp single
{
simu
->
swap
();
simu
->
recv
();
}
}
}
simu
->
send
();
simu
->
getSender
().
wait
();
delete
simu
;
MPI_Finalize
();
return
0
;
}
Event Timeline
Log In to Comment