Class: CodeRunner::Script

Inherits:
Run
  • Object
show all
Defined in:
lib/scriptcrmod.rb

Overview

This is a module which can be used for submitting arbitrary scripts on supercomputers using the CodeRunner framework (see coderunner.sourceforge.net and coderunner on rubygems.org). It comes preinstalled with CodeRunner.

An example paints a thousand words: here is how to use it from the command line to submit a ruby script: coderunner sub -W 60 -n 1x32 -C script -X ‘/usr/bin/env ruby’ \ -p ‘“my_script.rb”, arguments: “my command line args”, \ replace_tokens: {“TOKEN” => “replace”’

The parameter replace_tokens takes a hash of => string which will be used to modify the text in the script via text.gsub!(Regexp.new(Regexp.escape(“TOKEN”)), replace) Symbols may be used instead of strings

Instance Method Summary collapse

Instance Method Details

#generate_input_fileObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/scriptcrmod.rb', line 74

def generate_input_file

	if @file_name
		ep ['Copying:', rcp.runner.root_folder + '/' + @file_name, @directory + '/' + File.basename(@file_name)]
		#FileUtils.cp(rcp.runner.root_folder + '/' + @file_name, @directory + '/' + File.basename(@file_name))
		text = File.read(rcp.runner.root_folder + '/' + @file_name)
		if @replace_tokens
			@replace_tokens.each do |token, replace_str|
				text.gsub!(Regexp.new(Regexp.escape(token)), replace_str.to_s)
			end
		end
		File.open(@directory + '/' + File.basename(@file_name), 'w'){|file| file.puts text}
	else
		eputs 'Running without a script file...'
	end
end

#generate_phantom_runsObject



105
106
# File 'lib/scriptcrmod.rb', line 105

def generate_phantom_runs
end

#graphkit(name, options) ⇒ Object



108
109
110
111
112
113
114
# File 'lib/scriptcrmod.rb', line 108

def graphkit(name, options)
	case name
	when 'empty'
	else
		raise 'Unknown graph'
	end
end

#parameter_stringObject



70
71
72
# File 'lib/scriptcrmod.rb', line 70

def parameter_string
	return sprintf("%s %s", @file_name.to_s, @arguments.to_s)
end

#parameter_transition(run) ⇒ Object



91
92
# File 'lib/scriptcrmod.rb', line 91

def parameter_transition(run)
end


63
64
65
66
67
68
# File 'lib/scriptcrmod.rb', line 63

def print_out_line
		line =  sprintf("%d:%d %30s %10s %s", @id, @job_no, @run_name, @status, @nprocs.to_s) 
		line += sprintf(" %3.1f\%", @percent_complete) if @percent_complete
		line += " -- #@comment" if @comment
		return line
end

#process_directory_code_specificObject



54
55
56
57
58
59
60
61
# File 'lib/scriptcrmod.rb', line 54

def process_directory_code_specific
	if @running
		@status ||= :Incomplete
	else
		@status = :Complete
	end
	eval(File.read('script_outputs.rb')) if FileTest.exist? 'script_outputs.rb'
end

#run_commandObject

Override whatever is in the system module



95
96
97
98
# File 'lib/scriptcrmod.rb', line 95

def run_command
	eputs "Warning: preamble does not end in a new line" unless !preamble or preamble =~ /\n\s*\Z/
	"#{preamble} #{executable_location}/#{executable_name} #{parameter_string}"
end