In [1]:
import sys
import time
import subprocess
In [2]:
%%time
Ps = [1, 2, 4, 8]
cmd = ['mpiexec', '-n', None, sys.executable, 'n-body-mpi.py']
runtimes = []
for P in Ps:
print("running", P, end=" ")
cmd[2] = str(P+1)
start = time.time()
subprocess.call(cmd)
stop = time.time()
runtimes.append(stop - start)
print(runtimes[-1])
print(runtimes)
In [15]:
rts = runtimes[0] / np.array(runtimes)
plt.plot(Ps, rts, 'ko-')
plt.xlabel('Number of MPI Worker Ranks, $P$')
plt.ylabel('speedup, $t_1/t_P$')
plt.savefig('n-body-mpi-speedup.svg')
In [10]:
plt.plot(Ps, rts / Ps, 'ko-')
Out[10]:
In [11]:
rts
Out[11]:
In [12]:
rts[1:] / rts[:-1]
Out[12]:
In [16]:
plt.plot(Ps[1:], rts[1:] / rts[:-1], 'ko-')
plt.xlabel('Number of MPI Worker Ranks, $P$')
plt.ylabel('Relative Double Speedup, $t_P/t_{\\frac{P}{2}}$')
#plt.savefig('n-body-mpi-double-speedup.svg')
Out[16]:
In [17]:
runtimes[0]/4.288378953933716
Out[17]:
In [8]: