Last active
August 29, 2015 14:17
-
-
Save mliszcz/0dfcab499d62c0eee556 to your computer and use it in GitHub Desktop.
tpr lab01
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import subprocess | |
comm_type = 0 # synchronous (SSend) | |
# comm_type = 1 # buffered (BSend) | |
payload = 1 # just one byte for latency tests | |
pings = 20000 # each node sends 10k messages | |
test_program = './zad1_ping_pong.py' | |
# test_program = './ping_pong.o' | |
def run_test(): | |
## sometimes fails on vnode-01 with error: | |
## mpiexec_vnode-01 (mpiexec 392): no msg recvd from mpd when expecting ack of request | |
try: | |
process = subprocess.Popen([ | |
'mpiexec', | |
'-machinefile', './mpihosts', | |
'-n', '2', | |
test_program, | |
str(comm_type), | |
str(pings), | |
str(payload) | |
], stdout=subprocess.PIPE) | |
return map( float, process.communicate()[0].split() ) | |
except: | |
return None | |
for __ in xrange(4): | |
result = run_test() | |
if result is not None: | |
result = map( lambda r: r / (pings/2), result ) | |
print ' '.join( map(str, result) ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import subprocess | |
comm_type = 0 # synchronous (SSend) | |
# comm_type = 1 # buffered (BSend) | |
nodes = 5 # N nodes in the cluster | |
cycles = 1 # repeat N times | |
test_program = './zad2_token_ring.py' | |
# test_program = './token_ring.o' | |
def run_test(payload): | |
## sometimes fails on vnode-01 with error: | |
## mpiexec_vnode-01 (mpiexec 392): no msg recvd from mpd when expecting ack of request | |
try: | |
process = subprocess.Popen([ | |
'mpiexec', | |
'-machinefile', './mpihosts', | |
'-n', str(nodes), | |
test_program, | |
str(comm_type), | |
str(cycles), | |
str(payload) | |
], stdout=subprocess.PIPE) | |
return map( float, process.communicate()[0].split() ) | |
except: | |
return None | |
# test_data = [10**n for n in xrange(9)] # 1B to 100MB | |
# test_data = [100000 * x for x in xrange(100)] | |
# 1B to 1MB, 5MB, 10MB, 15MB, ..., 200MB | |
# test_data = [10**n for n in xrange(7)] + [n * 5 * 10**6 for n in xrange(1,41) ] | |
test_data = [mbyte*10**6 for mbyte in [1] + [n*10 for n in xrange(1,21)] ] | |
for __ in xrange(4): | |
for data_size in test_data: | |
result = run_test(data_size) | |
if result is not None: | |
result = map( lambda r: r / cycles, result ) | |
print ' '.join( map(str, [data_size] + result) ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
## example: send 1MB 10 times using SSend | |
## mpiexec -n 2 ./zad1_ping_pong.py 0 10 1000000 | |
from mpi4py import MPI | |
import numpy as np | |
import sys | |
get_arg = lambda n, default: int(sys.argv[n]) if n < len(sys.argv) else default | |
type = get_arg(1, 0) # 0: SSend, 1: BSend | |
pings = get_arg(2, 10) # ping N times | |
payload = get_arg(3, 1) # send M bytes | |
comm = MPI.COMM_WORLD | |
rank = comm.Get_rank() | |
send_fun = comm.Bsend if type == 1 else comm.Ssend | |
recv_fun = comm.Recv | |
if rank not in [0, 1]: | |
print("Expected only two nodes") | |
else: | |
count = 0 | |
LIMIT = pings | |
partner = abs(rank-1) | |
if type == 1: | |
_buffer = np.zeros(pings * payload, dtype=np.dtype('i1')) | |
MPI.Attach_buffer(_buffer) | |
data = np.zeros(payload, dtype=np.dtype('i1')) | |
start = MPI.Wtime() | |
while(count < LIMIT): | |
count += 1 | |
if (rank == count % 2): | |
# print("proc {0} sends".format(rank)) | |
send_fun([data, MPI.BYTE], dest=partner) | |
else: | |
recv_fun([data, MPI.BYTE], source=partner) | |
# print("proc {0} got {1}".format(rank, data.nbytes)) | |
delta = 10**6 * (MPI.Wtime() - start) # elapsed time (microseconds) | |
acc = 10**6 * MPI.Wtick() # timer accuracy | |
if type == 1: | |
MPI.Detach_buffer() | |
if rank == 0: | |
print delta, 2*acc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
## example: send 1MB 10 times using SSend | |
## mpiexec -n 5 ./zad2_token_ring.py 0 10 1000000 | |
from mpi4py import MPI | |
import numpy as np | |
import sys | |
get_arg = lambda n, default: int(sys.argv[n]) if n < len(sys.argv) else default | |
type = get_arg(1, 0) # 0: SSend, 1: BSend | |
cycles = get_arg(2, 10) # travel whole ring N times | |
payload = get_arg(3, 1) # send M bytes token | |
comm = MPI.COMM_WORLD | |
rank = comm.Get_rank() | |
world = comm.Get_size() | |
send_fun = comm.Bsend if type == 1 else comm.Ssend | |
recv_fun = comm.Recv | |
count = 0 | |
LIMIT = cycles | |
next_proc = (rank + 1) % world | |
prev_proc = (rank - 1) % world | |
if type == 1: | |
_buffer = np.zeros(world * cycles * payload, dtype=np.dtype('i1')) | |
MPI.Attach_buffer(_buffer) | |
data = np.zeros(payload, dtype=np.dtype('i1')) | |
start = MPI.Wtime() | |
if rank != 0: | |
while(count < LIMIT): | |
count += 1 | |
recv_fun([data, MPI.BYTE], source=prev_proc) | |
# print("rank {0} passes token".format(rank)) | |
send_fun([data, MPI.BYTE], dest=next_proc) | |
else: | |
while(count < LIMIT): | |
count += 1 | |
# print("rank {0} initializes cycle".format(rank)) | |
send_fun([data, MPI.BYTE], dest=next_proc) | |
recv_fun([data, MPI.BYTE], source=prev_proc) | |
delta = MPI.Wtime() - start # elapsed time (seconds) | |
acc = MPI.Wtick() # timer accuracy | |
if type == 1: | |
MPI.Detach_buffer() | |
if rank == 0: | |
print delta, 2*acc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment