Last active
April 27, 2016 06:13
-
-
Save iwiwi/5337010 to your computer and use it in GitHub Desktop.
Torque job machine-gun
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
# qsub.rb --- Torque job machine-gun | |
# | |
# Usage: | |
# 1. Rewrite the shell script template & parameters | |
# 2. Execute | |
# $ qsub.rb (cat) --> Output generated shell scripts | |
# $ qsub.rb sh --> Execute locally | |
# $ qsub.rb qsub --> Enqueue onto Torque | |
# | |
# Author: | |
# Takuya Akiba (@iwiwi) | |
# http://www-imai.is.s.u-tokyo.ac.jp/~takiba/index_e.html | |
# | |
def main | |
qsub({ | |
:file => ["a.txt", "b.txt", "c.txt"], | |
:parameter => [1, 2], | |
}) do <<-EOS | |
#!/bin/sh | |
#PBS -j oe | |
#PBS -l nodes=1:ppn=12 | |
#PBS -M [email protected] | |
#PBS -mb -me | |
#PBS -N #{$parameter},#{File.basename($file)} | |
ulimit -t 86400 | |
ulimit -v 41943040 | |
cd #{File.dirname(File.expand_path(__FILE__))} | |
echo #{$file} #{$parameter} | |
EOS | |
end | |
end | |
def qsub(args = {}) | |
system("mkdir -p tmp") | |
def rec(i, args, env) | |
if i < args.length | |
name = args[i][0].to_s | |
values = args[i][1].is_a?(Array) ? args[i][1] : [args[i][1]] | |
values.each do |v| | |
env[i] = [name, v] | |
rec(i + 1, args, env) { yield(env) } | |
end | |
else | |
yield(env) | |
end | |
end | |
rec(0, args.to_a, []) do |env| | |
open("tmp/tmp.sh", "w") do |f| | |
eval(env.map{|k, v| "$#{k} = '#{v.to_s}'\n"}.join("")) | |
f.puts(yield) | |
end | |
cmd = ARGV.length == 0 ? "cat" : ARGV[0] | |
sh = "" | |
if cmd == "qsub" | |
jobname = env.map do |a| | |
if a[1].is_a?(String) | |
s = File.basename(a[1].to_s) | |
s[0, [s.length, 4].min] | |
else | |
a[1].to_s | |
end | |
end.join(",") | |
sh = "cd tmp; qsub tmp.sh; cd ../" | |
else | |
sh = "#{cmd} tmp/tmp.sh" | |
end | |
system("#{sh}") | |
end | |
end | |
if __FILE__ == $0 | |
main | |
end |
FAQ
- Q: アレイジョブ知らないんですか?
- A: アレイジョブでは満足できないから作りました.複数のパラメータの組合せを網羅的に実行することが簡単にできますし,パラメータを増やしたり減らしたりも手軽にできます.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
History