| 1 |
#!/usr/bin/env python |
| 2 |
|
| 3 |
# Copyright (C) 2010 Anders Logg |
| 4 |
# |
| 5 |
# This file is part of DOLFIN. |
| 6 |
# |
| 7 |
# DOLFIN is free software: you can redistribute it and/or modify |
| 8 |
# it under the terms of the GNU Lesser General Public License as published by |
| 9 |
# the Free Software Foundation, either version 3 of the License, or |
| 10 |
# (at your option) any later version. |
| 11 |
# |
| 12 |
# DOLFIN is distributed in the hope that it will be useful, |
| 13 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
# GNU Lesser General Public License for more details. |
| 16 |
# |
| 17 |
# You should have received a copy of the GNU Lesser General Public License |
| 18 |
# along with DOLFIN. If not, see <http://www.gnu.org/licenses/>. |
| 19 |
# |
| 20 |
# Modified by Garth N. Wells, 2011. |
| 21 |
# Modified by Johannes Ring, 2011. |
| 22 |
# |
| 23 |
# First added: 2010-05-03 |
| 24 |
# Last changed: 2011-04-05 |
| 25 |
|
| 26 |
import commands |
| 27 |
|
| 28 |
# Parameters for benchmark |
| 29 |
SIZE = 64 |
| 30 |
NUM_PROCS = 4 |
| 31 |
|
| 32 |
print "Assembly/solve speedup running on %s processors" % NUM_PROCS |
| 33 |
|
| 34 |
# Function for extracting test name and time from benchmark |
| 35 |
def get_time(output): |
| 36 |
lines = [line for line in output.split("\n") if "TIME" in line] |
| 37 |
timing = [] |
| 38 |
for line in lines: |
| 39 |
time = float(line.split(":")[-1]) |
| 40 |
name = line.split(":")[-2].strip("Process 0: ").strip("TIME").strip(None).replace("(", "").replace(")", "") |
| 41 |
timing.append( (name, time) ) |
| 42 |
return timing |
| 43 |
|
| 44 |
# Serial assembly |
| 45 |
output = commands.getoutput("./bench_assemble-poisson %d" % SIZE) |
| 46 |
assembly_t1 = get_time(output) |
| 47 |
print "Serial assembly:", assembly_t1 |
| 48 |
|
| 49 |
# Parallel assembly |
| 50 |
output = commands.getoutput("mpirun -n %d ./bench_assemble-poisson %d" % (NUM_PROCS, SIZE)) |
| 51 |
assembly_t2 = get_time(output) |
| 52 |
print "Parallel assembly:", assembly_t2 |
| 53 |
|
| 54 |
# Serial solve |
| 55 |
output = commands.getoutput("./bench_solve-poisson %d" % SIZE) |
| 56 |
solve_t1 = get_time(output) |
| 57 |
print "Serial solve:", solve_t1 |
| 58 |
|
| 59 |
# Parallel solve |
| 60 |
output = commands.getoutput("mpirun -n %d ./bench_solve-poisson %d" % (NUM_PROCS, SIZE)) |
| 61 |
solve_t2 = get_time(output) |
| 62 |
print "Parallel solve:", solve_t2 |
| 63 |
|
| 64 |
print "assembly" |
| 65 |
for test1, test2 in zip(assembly_t1, assembly_t2): |
| 66 |
print " ", test1[0] + ":", test1[1]/test2[1] |
| 67 |
|
| 68 |
print "solve" |
| 69 |
for test1, test2 in zip(solve_t1, solve_t2): |
| 70 |
print " ", test1[0] + ":", test1[1]/test2[1] |
| 71 |
|
| 72 |
print "BENCH assembly_1st", assembly_t1[0][1] / assembly_t2[0][1] |
| 73 |
print "BENCH assembly_2nd", assembly_t1[1][1] / assembly_t2[1][1] |
| 74 |
print "BENCH solve_1st", solve_t1[0][1] / solve_t2[0][1] |
| 75 |
print "BENCH solve_same_pc_pattern", solve_t1[1][1] / solve_t2[2][1] |
| 76 |
print "BENCH solve_same_pc", solve_t1[2][1] / solve_t2[2][1] |