#!/usr/bin/env python
#
# This script submits jobs for measuring parallel speedup.
#
# Copyright (C) 2009 Johan Hake
#
# This file is part of DOLFIN.
#
# DOLFIN is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# DOLFIN is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
#
# Modified by Anders Logg, 2009.
#
# First added:  2009-09-15
# Last changed: 2011-01-04

from dolfin_utils.pjobs import submit
from numpy import arange
import sys

# Parameters for benchmark
SIZE = 128

# Number of processes to use
# NOTE: Largest number of processors to run is 2^EXP
EXP = 6
num_processes = list(2**arange(EXP+1))

# Check command-line arguments
dryrun = True if 'dryrun' in sys.argv else False

# Iterate over process range
for np in num_processes:

    if np == 1:
        run_cmd = ""
    else:
        run_cmd = "mpirun.openmpi -n %d " % np

    # Submit assemble benchmark
    submit("%s./assemble-poisson %d" % (run_cmd, SIZE),
           nodes=max(1, np/8),
           ppn=8, # Grab all cores on a node
           name="assemble-poisson_np_%d_size_%d.log" % (np, SIZE),
           dryrun=dryrun)

    # Submit solve benchmark
    submit("%s./solve-poisson %d" % (run_cmd, SIZE),
           nodes=max(1, np/8),
           ppn=8, # Grab all cores on a node
           name="solve-poisson_np_%d_size_%d.log" % (np, SIZE),
           dryrun=dryrun)
