From b2f195460305f2ff0d237df13dbea5fb5e744504 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 31 Mar 2011 18:45:43 -0700 Subject: [PATCH] Add WORKER_POOL environmental option to facilitate pysawsim.manager benchmarking. --- pysawsim/manager/mpi.py | 6 ++++-- pysawsim/manager/subproc.py | 5 +++-- pysawsim/manager/thread.py | 5 ++++- pysawsim/test/bell_rate.py | 4 ++-- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/pysawsim/manager/mpi.py b/pysawsim/manager/mpi.py index 0c4ad47..a398c4f 100644 --- a/pysawsim/manager/mpi.py +++ b/pysawsim/manager/mpi.py @@ -49,6 +49,7 @@ There is also a `free_queue` running from `receive-thread` to nodes are free (and therefore ready to receive new jobs). """ +import os from Queue import Queue, Empty import sys from threading import Thread @@ -208,8 +209,9 @@ class MPIManager (ThreadManager): 'w.run()', 'w.teardown()', ]) - if worker_pool == None: - worker_pool = MPI.COMM_WORLD.Get_size() + if worker_pool is None: + worker_pool = int(os.environ.get('WORKER_POOL', + MPI.COMM_WORLD.Get_size())) comm = MPI.COMM_SELF.Spawn( # locks with mpich2 if no mpd running sys.executable, args=['-c', spawn_script], maxprocs=worker_pool) rank = comm.Get_rank() diff --git a/pysawsim/manager/subproc.py b/pysawsim/manager/subproc.py index d767da4..6a17078 100644 --- a/pysawsim/manager/subproc.py +++ b/pysawsim/manager/subproc.py @@ -30,6 +30,7 @@ except ImportError, _DISABLING_ERROR: Process = object _SKIP = ' # doctest: +SKIP' +import os from .. import log from . import Job @@ -116,8 +117,8 @@ class SubprocessManager (ThreadManager): self._receive_queue = Queue() def _spawn_workers(self, worker_pool=None): - if worker_pool == None: - worker_pool = cpu_count() + 1 + if worker_pool is None: + worker_pool = int(os.environ.get('WORKER_POOL', cpu_count() + 1)) self._manager = Manager() self._workers = [] for i in range(worker_pool): diff --git a/pysawsim/manager/thread.py b/pysawsim/manager/thread.py index 48a2f9f..a4e98f5 100644 --- a/pysawsim/manager/thread.py +++ b/pysawsim/manager/thread.py @@ -21,6 +21,7 @@ """ import copy +import os from Queue import Queue, Empty import threading @@ -90,7 +91,7 @@ class ThreadManager (JobManager): Increasing `worker_pool` will only help you get around IO blockin at the cost increased time-slicing overhead. """ - def __init__(self, worker_pool=2): + def __init__(self, worker_pool=None): super(ThreadManager, self).__init__() self._blocked = [] self._setup_queues() @@ -101,6 +102,8 @@ class ThreadManager (JobManager): self._receive_queue = Queue() def _spawn_workers(self, worker_pool): + if worker_pool is None: + worker_pool = int(os.environ.get('WORKER_POOL', 2)) self._workers = [] for i in range(worker_pool): worker = WorkerThread(spawn_queue=self._spawn_queue, diff --git a/pysawsim/test/bell_rate.py b/pysawsim/test/bell_rate.py index f542433..fdbec6f 100644 --- a/pysawsim/test/bell_rate.py +++ b/pysawsim/test/bell_rate.py @@ -28,7 +28,7 @@ Analytically, with a spring constant .. math:: k = df/dx and a pulling velocity - +unfolindg .. math:: v = dx/dt we have a loading rate @@ -148,7 +148,7 @@ class GumbelModelFitter (HistogramModelFitter): def bell_rate(sawsim_runner, num_domains=1, unfolding_rate=1, unfolding_distance=1, temperature=1/kB, spring_constant=1, - velocity=1, N=100): + velocity=1, N=200): loading_rate = float(spring_constant * velocity) rho = kB * temperature / unfolding_distance alpha = rho * log(loading_rate / (unfolding_rate * rho)) -- 2.26.2