Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F92186588
io7.py
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 18, 03:21
Size
1 KB
Mime Type
text/x-python
Expires
Wed, Nov 20, 03:21 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
22387468
Attached To
rPNBODY pNbody
io7.py
View Options
#!/usr/bin/env python
from
mpi4py
import
MPI
from
numpy
import
*
import
time
from
optparse
import
OptionParser
def
parse_options
():
usage
=
"usage: %prog [options] file"
parser
=
OptionParser
(
usage
=
usage
)
parser
.
add_option
(
"-o"
,
"--outputfile"
,
action
=
"store"
,
type
=
"string"
,
dest
=
"outputfile"
,
default
=
"pytest-io7.dat"
,
help
=
"output file name"
)
parser
.
add_option
(
"--DataSize"
,
action
=
"store"
,
type
=
"int"
,
dest
=
"DataSize"
,
default
=
10
,
help
=
"Data size in Mb"
)
(
options
,
args
)
=
parser
.
parse_args
()
files
=
args
return
files
,
options
files
,
opt
=
parse_options
()
comm
=
MPI
.
COMM_WORLD
ThisTask
=
comm
.
Get_rank
()
NTask
=
comm
.
Get_size
()
Procnm
=
MPI
.
Get_processor_name
()
Rank
=
ThisTask
print
"ThisTaks=
%d
"
%
ThisTask
# set data
print
opt
.
DataSize
DataSize
=
1024
*
1024
*
opt
.
DataSize
# 10 Mega
Nnumbers
=
int
(
DataSize
/
8
)
random
.
seed
(
ThisTask
)
data
=
random
.
random
(
Nnumbers
)
nbytes
=
data
.
nbytes
if
ThisTask
==
0
:
t1
=
time
.
time
()
filename
=
opt
.
outputfile
if
ThisTask
==
0
:
myfile
=
open
(
filename
,
'w'
)
myfile
.
write
(
data
.
tostring
())
for
Task
in
range
(
1
,
NTask
):
sdata
=
comm
.
recv
(
source
=
Task
)
myfile
.
write
(
sdata
.
tostring
())
myfile
.
close
()
else
:
comm
.
send
(
data
,
dest
=
0
)
if
ThisTask
==
0
:
t2
=
time
.
time
()
print
"elapsed time : "
,
t2
-
t1
Event Timeline
Log In to Comment