22
33# Written (W) 2008-2012 Christian Widmer
44# Written (W) 2008-2010 Cheng Soon Ong
5- # Written (W) 2012-2013 Daniel Blanchard, dblanchard@ets.org
6- # Copyright (C) 2008-2012 Max-Planck-Society, 2012-2013 ETS
5+ # Written (W) 2012-2014 Daniel Blanchard, dblanchard@ets.org
6+ # Copyright (C) 2008-2012 Max-Planck-Society, 2012-2014 ETS
77
88# This file is part of GridMap.
99
2828
2929from __future__ import print_function , unicode_literals
3030
31- import time
31+ import logging
32+ from datetime import datetime
3233
3334from gridmap import Job , process_jobs
3435
3536
37+ def sleep_walk (secs ):
38+ '''
39+ Pass the time by adding numbers until the specified number of seconds has
40+ elapsed. Intended as a replacement for ``time.sleep`` that doesn't leave the
41+ CPU idle (which will make the job seem like it's stalled).
42+ '''
43+ start_time = datetime .now ()
44+ num = 0
45+ while (datetime .now () - start_time ).seconds < secs :
46+ num = num + 1
47+
48+
3649def compute_factorial (n ):
3750 """
3851 computes factorial of n
3952 """
40- time . sleep (10 )
53+ sleep_walk (10 )
4154 ret = 1
4255 for i in range (n ):
4356 ret = ret * (i + 1 )
@@ -62,7 +75,9 @@ def make_jobs():
6275
6376 # create job objects
6477 for arg in inputvec :
65- job = Job (compute_factorial , arg )
78+ # The default queue used by the Job class is all.q. You must specify
79+ # the `queue` keyword argument if that is not the name of your queue.
80+ job = Job (compute_factorial , arg , queue = 'all.q' )
6681 jobs .append (job )
6782
6883 return jobs
@@ -73,6 +88,10 @@ def main():
7388 run a set of jobs on cluster
7489 """
7590
91+ logging .captureWarnings (True )
92+ logging .basicConfig (format = ('%(asctime)s - %(name)s - %(levelname)s - ' +
93+ '%(message)s' ), level = logging .INFO )
94+
7695 print ("=====================================" )
7796 print ("======== Submit and Wait ========" )
7897 print ("=====================================" )
@@ -83,7 +102,7 @@ def main():
83102 print ("sending function jobs to cluster" )
84103 print ("" )
85104
86- job_outputs = process_jobs (functionJobs )
105+ job_outputs = process_jobs (functionJobs , max_processes = 4 )
87106
88107 print ("results from each job" )
89108 for (i , result ) in enumerate (job_outputs ):
0 commit comments