~ubuntu-branches/ubuntu/utopic/gridengine/utopic

« back to all changes in this revision

Viewing changes to source/scripts/qsub_blast.pl

  • Committer: Bazaar Package Importer
  • Author(s): Mark Hymers
  • Date: 2008-06-25 22:36:13 UTC
  • Revision ID: james.westby@ubuntu.com-20080625223613-tvd9xlhuoct9kyhm
Tags: upstream-6.2~beta2
ImportĀ upstreamĀ versionĀ 6.2~beta2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
 
 
3
#########################################################################
 
4
 
5
#  The Contents of this file are made available subject to the terms of
 
6
#  the Sun Industry Standards Source License Version 1.2
 
7
 
8
#  Sun Microsystems Inc., March, 2001
 
9
 
10
 
11
#  Sun Industry Standards Source License Version 1.2
 
12
#  =================================================
 
13
#  The contents of this file are subject to the Sun Industry Standards
 
14
#  Source License Version 1.2 (the "License"); You may not use this file
 
15
#  except in compliance with the License. You may obtain a copy of the
 
16
#  License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
 
17
 
18
#  Software provided under this License is provided on an "AS IS" basis,
 
19
#  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 
20
#  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 
21
#  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 
22
#  See the License for the specific provisions governing your rights and
 
23
#  obligations concerning the Software.
 
24
 
25
#   The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 
26
 
27
#   Copyright: 2001 by Sun Microsystems, Inc.
 
28
 
29
#   All Rights Reserved.
 
30
 
31
#########################################################################
 
32
#
 
33
# This script forks and execs identical copies of qsub.
 
34
#
 
35
# Syntax:
 
36
#    qsub_blast.pl -n num_instances -m num_simultaneous -q -- qsub_args...
 
37
#
 
38
# Example:
 
39
#    qsub_blast.pl -n 30 -m 30 -- -sync yes -cwd examples/jobs/exit.sh 0
 
40
#
 
41
#########################################################################
 
42
 
 
43
$num_forks = 1;
 
44
$per_loop = 10;
 
45
$silent = 0;
 
46
 
 
47
# Process args
 
48
if (@ARGV == 0) {
 
49
  usage ();
 
50
  exit (0);
 
51
}
 
52
 
 
53
# Copy the arg array, remove the number of instances, and add "qsub"
 
54
@args = @ARGV;
 
55
$arg = shift (@args);
 
56
 
 
57
while ($arg ne "--") {
 
58
   if ($arg eq "-n") {
 
59
      $arg = shift (@args);
 
60
 
 
61
      if ($arg !~ /^\d+$/) {
 
62
         usage ();
 
63
         exit (1);
 
64
      }
 
65
 
 
66
      $num_forks = $arg;
 
67
   }
 
68
   elsif ($arg eq "-m") {
 
69
      $arg = shift (@args);
 
70
 
 
71
      if ($arg !~ /^\d+$/) {
 
72
         usage ();
 
73
         exit (1);
 
74
      }
 
75
 
 
76
      $per_loop = $arg;
 
77
   }
 
78
   elsif ($arg eq "-q") {
 
79
      $silent = 1;
 
80
   }
 
81
   elsif ($arg eq "-help") {
 
82
      usage ();
 
83
      exit (0);
 
84
   }
 
85
   else {
 
86
      usage ();
 
87
      exit (1);
 
88
   }
 
89
 
 
90
   $arg = shift (@args);
 
91
}
 
92
 
 
93
if ($arg ne "--") {
 
94
   usage ();
 
95
   exit (1);
 
96
}
 
97
 
 
98
unshift (@args, "qsub");
 
99
 
 
100
if ($silent) {
 
101
   push (@args, "1>/dev/null");
 
102
   push (@args, "2>&1");
 
103
}
 
104
 
 
105
# Fork and exec the right number of qsubs
 
106
 
 
107
while ($num_forks > 0) {
 
108
   if ($num_forks < $per_loop) {
 
109
      $max = $num_forks;
 
110
   }
 
111
   else {
 
112
      $max = $per_loop;
 
113
   }
 
114
 
 
115
   for ($count = 0; $count < $max; $count++) {
 
116
      if (fork () == 0) {
 
117
         exec (@args);
 
118
      }
 
119
   }
 
120
 
 
121
   # Wait once for each fork
 
122
   for ($count = 0; $count < $max; $count++) {
 
123
      wait ();
 
124
   }
 
125
 
 
126
   $num_forks -= $max;
 
127
}
 
128
 
 
129
exit (0);
 
130
 
 
131
# Print the script's usage information
 
132
sub usage {
 
133
   print "USAGE: qsub_blast.pl [args] -- qsub_args\n";
 
134
   print "\t-n num_instances     Number of instances to run\n";
 
135
   print "\t-m num_simultaneous  Number of instances which will run at a time\n";
 
136
   print "\t-q                   Suppress qsub output\n";
 
137
   print "\t-help                Print this message\n";
 
138
}