qtools 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e0d76a13024d569a65ccd1934078073de89ecc67
4
- data.tar.gz: e0402dda42b8217f6c999dafb586f49c39e9e9ba
3
+ metadata.gz: cb43e525d2cab83fa5e423abc7fdf93b5493cd61
4
+ data.tar.gz: 42d03f7c9712b282c247a99d89bf422a23191cfc
5
5
  SHA512:
6
- metadata.gz: e67fcc4cdb5bddec31d79e8b3cb46ebad101c69d7fa016c031866f8ec834ff27ec3ba5c1a4974f00fd1c46b18cf1321121c407fd3fcabc8fcb5f0828087625ac
7
- data.tar.gz: e91e8e618428a10c3d1d37b575eb21c13d69122412753350487e187f4d2cba1bf8ff99f445419fd3fc9d4c551e1be667ac521dd889bcb7eab040e8dd0e08ec82
6
+ metadata.gz: 42ed7171a340d405c3dbdb637fa7701bf4725ec58fa6d9b741a49b31c3c8296174284404f86d583cf1459ac2f98f8dff777fb6837fe2cd1dca239446c74c5573
7
+ data.tar.gz: c8cacf15a8717b023ed54ffcfafe8cc91b83a25694ba132af72857659f39c254198c25e91b4501c8153b270134264350a4f24b0ec75bf2c5b0bb610fb8c62fcd
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # qtools
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/qtools.svg)](https://badge.fury.io/rb/qtools)
4
+
3
5
  `qtools` offers the shortcuts for some common procedures when working with the Open Grid Scheduler.
4
6
 
5
7
 
@@ -27,57 +29,37 @@ Usage:
27
29
 
28
30
  The command above will create a shell script file with the corresponding content and submit a job which will feature the name `my_name` and require `8gb` of memory.
29
31
 
30
- ### qwatch
31
-
32
- Usage:
33
-
34
- $ qwatch
32
+ Available parameters:
35
33
 
36
- The command above is equivalent to running `watch -n1 -d "qstat -u $USER"`.
34
+ - `-n`, `--name` - job title
35
+ - `-m`, `--memory` - memory (e.g., `80gb`)
36
+ - `-q`, `--queue` - queue title
37
+ - `-t`, `--time` - job time limit in hours (default is `24`)
38
+ - `-c`, `--cpu` - number of CPUs
37
39
 
38
- Flags:
40
+ ### qwatch
39
41
 
40
- - `-n`, `--nodes` to show information on nodes too (`qstat -n1 -u $USER`)
42
+ `qwatch` is equivalent to running `watch -n1 -d "qstat -u $USER"`. Use `-n` (`--nodes`) flag to show information on nodes too (`qstat -n1 -u $USER`)
41
43
 
42
44
  ### qclean
43
45
 
44
- Usage:
45
-
46
- $ qclean
47
-
48
- The command above will run `rm *.[eo][0-9]*` in the current directory (if such files exist).
46
+ `qclean` will run `rm *.[eo][0-9]*` in the current directory (if such files exist).
49
47
 
50
48
  ### qcount
51
49
 
52
- Usage:
53
-
54
- $ qcount
55
-
56
- Count the number of jobs for the `$USER`. Running `qcount -a` will output the number of jobs for all the users.
50
+ Use `qcount` to count the number of jobs for the `$USER`. Running `qcount -a` will output the number of jobs for all the users.
57
51
 
58
52
  ### qnode
59
53
 
60
- Usage:
61
-
62
- $ qnode
63
-
64
- The command above will print the list of free nodes sorted by their `LOAD`. Use `qnode -m` to sort the list of free nodes by memory available and `qnode -c` to sort the list by the number of free cores.
54
+ Run `qnode` to print the list of free nodes sorted by their `LOAD`. Use `qnode -m` to sort the list of free nodes by memory available and `qnode -c` to sort the list by the number of free cores.
65
55
 
66
56
  ### qundo
67
57
 
68
- Usage:
69
-
70
- $ qundo
71
-
72
- The command above will try to run `qdel` for the last job submitted.
58
+ `qundo` will try to run `qdel` for the last job submitted (for the current user).
73
59
 
74
60
  ### qless
75
61
 
76
- Usage:
77
-
78
- $ qless
79
-
80
- The command above will try to read the last default error log `.e[0-9]*` in the current folder. Use `-o` flag to read the last default output file.
62
+ Run `qless` to read the last default error log `.e[0-9]*` in the current folder. Use `-o` flag to read the last default output file.
81
63
 
82
64
  ## Contributing
83
65
 
data/bin/qcount CHANGED
@@ -16,4 +16,4 @@ flags = []
16
16
  flags << '-u $USER' unless options[:all]
17
17
  flags_str = flags.join(' ')
18
18
 
19
- puts `qstat #{flags_str} | grep -c ^[0-9]`
19
+ puts `qstat #{flags_str} | grep -c ^'\s'*[0-9]`
data/bin/qnode CHANGED
@@ -27,5 +27,5 @@ else
27
27
  new_header = header.strip.gsub("CORES_TOTAL(USED)", "CORES_TOTAL\tCORES_USED") + "\tCORES_FREE"
28
28
  puts new_header
29
29
  puts `qhost | head -n2 | tail -n1`
30
- puts `qhost | egrep 'free' | sort -k5nr | tr "(" "\t" | tr -d ")" | awk 'BEGIN {OFS="\t"}; {print $0, $2-$3}'`
30
+ puts `qhost | egrep 'free' | tr "(" "\t" | tr -d ")" | awk 'BEGIN {OFS="\t"}; {print $0, $2-$3}' | sort -k8nr`
31
31
  end
data/bin/qqsub CHANGED
@@ -3,9 +3,9 @@
3
3
  require 'qtools'
4
4
  require 'optparse'
5
5
 
6
- Options = Struct.new(:name, :mem)
6
+ Options = Struct.new(:name, :mem, :queue, :cpus, :time)
7
7
 
8
- args = Options.new(:name, :mem)
8
+ args = Options.new
9
9
  OptionParser.new do |opts|
10
10
  opts.banner = "Usage: qtools 'python3 my_script.py ...' [options]"
11
11
 
@@ -15,6 +15,15 @@ OptionParser.new do |opts|
15
15
  opts.on("-m", "--memory MEMORY", "Memory for the job (e.g., 80gb)") do |m|
16
16
  args.mem = m
17
17
  end
18
+ opts.on("-q", "--queue QUEUE_TITLE", "Select a queue for the job") do |q|
19
+ args.queue = q
20
+ end
21
+ opts.on("-c", "--cpu NUMBER_OF_CORES", "Number of CPIs for the job (e.g., 8)") do |c|
22
+ args.cpus = c
23
+ end
24
+ opts.on("-t", "--time TIME_IN_HOURS", "Set the time limit for the job (default is 24 hours)") do |t|
25
+ args.time = t
26
+ end
18
27
  end.parse!
19
28
 
20
29
  command = ARGV
@@ -23,34 +32,56 @@ if command.empty?
23
32
  fail "Usage: qtools 'python3 my_script.py ...' [options]"
24
33
  end
25
34
 
26
- header_sge = <<-HEADER
27
- #!/bin/bash
28
35
 
29
- #$ -V
30
- #$ -cwd
31
- HEADER
36
+ # Guess the scheduler (SGE or PBS)
37
+ scheduler_temp = `pbs-config 2> /dev/null`
38
+ SCHEDULER = (scheduler_temp.empty? or scheduler_temp.nil?) ? :sge : :pbs
39
+ # puts "the scheduler is guessed to be #{SCHEDULER}"
32
40
 
33
41
  header_shell = "#!/bin/bash\n"
34
42
 
35
- header_pbs_tree = {}
36
- header_pbs_tree[:l] = ['walltime=24:00:00']
37
- header_pbs_tree[:d] = ['.']
43
+ if SCHEDULER == :sge
44
+ header_tree = Hash.new
45
+ header_tree[:V] = []
46
+ header_tree[:cwd] = []
47
+ header_tree[:l] = []
48
+ header_tree[:l] << "h_rt=#{args.time ? args.time : '24'}:00:00"
49
+ else
50
+ header_tree = Hash.new
51
+ header_tree[:l] = []
52
+ header_tree[:l] << "walltime=#{args.time ? args.time : '24'}:00:00"
53
+ header_tree[:d] = ['.']
54
+ end
55
+
38
56
 
39
- unless args.name.is_a? Symbol
40
- header_pbs_tree[:N] = [args.name]
57
+ if args.name
58
+ header_tree[:N] = [args.name]
41
59
  end
42
60
 
43
- unless args.mem.is_a? Symbol
44
- header_pbs_tree[:l] << "mem=#{args.mem}"
61
+ if args.mem
62
+ header_tree[:l] << "#{SCHEDULER == :sge ? "h_vmem" : "mem"}=#{args.mem}"
63
+ end
64
+
65
+ if args.queue
66
+ header_tree[:q] = [args.queue]
67
+ end
68
+
69
+ if args.cpus
70
+ if SCHEDULER == :sge
71
+ header_tree[:pe] = "smp #{args.cpus}"
72
+ else
73
+ header_tree[:l] << "ncpus=#{args.cpus}"
74
+ end
45
75
  end
46
76
 
47
- header_pbs = header_pbs_tree.map { |k, v| "#PBS -#{k} #{v.join(',')}" }.join("\n")
77
+ scheduler_prefix = SCHEDULER == :sge ? "$" : "PBS"
78
+ header = header_tree.map { |k, v| "##{scheduler_prefix} -#{k} #{v.join(',')}" }.join("\n")
48
79
 
49
80
  sh_prefix_guess = (command[0].split[1].include?('.') or command[0].split.length == 1) ? command[0].split[1] : command[0].split[0] # guess if script or executable
50
81
  sh_prefix = sh_prefix_guess.include?('.') ? sh_prefix_guess.match(/(.*)\.(.*?)/)[1] : sh_prefix_guess
51
- sh_name = (header_pbs_tree[:N] ? header_pbs_tree[:N][0] : sh_prefix) + '.sh'
82
+ sh_name = (header_tree[:N] ? header_tree[:N][0] : sh_prefix) + '.sh'
52
83
 
53
- File.write(sh_name, [header_shell, header_pbs, "", command[0]].join("\n"))
84
+ File.write(sh_name, [header_shell, header, "", command[0]].join("\n"))
54
85
 
55
86
  puts "-- Submit #{sh_name} for execution? [y/n]"
56
87
  answer = STDIN.gets.strip.downcase
data/bin/qundo CHANGED
@@ -3,7 +3,7 @@
3
3
  require 'qtools'
4
4
 
5
5
  last_job = `qstat -u $USER | tail -n 1`
6
- last_job_id = `qstat -u $USER | tail -n 1 | sed -rn 's/(^[0-9]*).*/\1/p'`
6
+ last_job_id = `qstat -u $USER | tail -n 1 | sed -rn 's/(^[0-9]*).*/\\1/p'`.strip
7
7
 
8
8
  unless last_job.empty?
9
9
  puts "-- The following job will be stopped:"
@@ -1,3 +1,3 @@
1
1
  module Qtools
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qtools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-09 00:00:00.000000000 Z
11
+ date: 2016-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler