Module: CodeRunner::Moab

Included in:
Archer, Dirac, Edison, Franklin, Hector, Hopper, Iridis, Loki
Defined in:
lib/coderunner/system_modules/moab.rb

Instance Method Summary collapse

Instance Method Details

#batch_scriptObject



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/coderunner/system_modules/moab.rb', line 89

def batch_script
	ppn_checks
	hours, mins, secs = hours_minutes_seconds
<<EOF
#!/bin/bash --login 
#PBS -N #{executable_name}.#{job_identifier}
#PBS -l mppwidth=#{nprocstot}
#PBS -l mppnppn=#{ppn}
#PBS -l walltime=#{sprintf("%02d:%02d:%02d", hours, mins, secs)}
#{@project ? "#PBS -A #@project" : ""}

### start of jobscript 
cd $PBS_O_WORKDIR 
echo "workdir: $PBS_O_WORKDIR" 
#{code_run_environment}

echo "Submitting #{nodes}x#{ppn} job on #{CodeRunner::SYS} for project #@project..."
EOF
end

#batch_script_fileObject



65
66
67
# File 'lib/coderunner/system_modules/moab.rb', line 65

def batch_script_file
	"#{executable_name}.#{job_identifier}.sh"
end

#cancel_jobObject



109
110
111
112
113
114
115
116
# File 'lib/coderunner/system_modules/moab.rb', line 109

def cancel_job
	if ((prefix = ENV['CODE_RUNNER_LAUNCHER']).size > 0 rescue false)
		 fname = CodeRunner.launcher_directory + "/#{$$}.stop"
		 File.open(fname, 'w'){|file| file.puts "\n"}
	else
		`qdel #{@job_no}`
	end
end

#error_fileObject



118
119
120
121
122
123
124
# File 'lib/coderunner/system_modules/moab.rb', line 118

def error_file
	if (ENV['CODE_RUNNER_LAUNCHER'].size > 0 rescue false)
		return "#{executable_name}.#{job_identifier}.e"
	else
		return "#{executable_name}.#{job_identifier}.e#@job_no"
	end
end

#executeObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/coderunner/system_modules/moab.rb', line 50

def execute
	if ((prefix = ENV['CODE_RUNNER_LAUNCHER']).size > 0 rescue false)
		launch_id = "#{Time.now.to_i}#{$$}"
		fname = "#{CodeRunner.launcher_directory}/#{launch_id}"
		File.open(fname + '.start', 'w'){|file| file.print "cd #{Dir.pwd};", run_command, "\n"}
		sleep 2 until FileTest.exist? fname + '.pid'
		pid = File.read(fname + '.pid').to_i
		FileUtils.rm fname + '.pid'
		return pid
	else
		File.open(batch_script_file, 'w'){|file| file.puts batch_script + run_command + "\n"}
		pid = %x[qsub #{batch_script_file}].to_i
	end
end

#get_run_status(job_no, current_status) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/coderunner/system_modules/moab.rb', line 134

def get_run_status(job_no, current_status)
	if ((prefix = ENV['CODE_RUNNER_LAUNCHER']).size > 0 rescue false)
		if current_status =~ Regexp.new(job_no.to_s)
			@running = true
			return :Running
		else
			@running = false
			return :Unknown
		end
	end
	line = current_status.split(/\n/).grep(Regexp.new(job_no.to_s))[0]
	unless line
		return :Unknown
	else 
		if line =~ /\sQ\s/
			return :Queueing
		elsif line =~ /\sR\s/
			return :Running
		elsif line =~ /\sH\s/
			return :Queueing
		elsif line =~ /\sC\s/
			@running=false
			return :Unknown
		else
			ep 'line', line
			raise 'Could not get run status'
		end
	end
end

#hours_minutes_secondsObject



73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/coderunner/system_modules/moab.rb', line 73

def hours_minutes_seconds
	if @wall_mins
		ep @wall_mins
		hours = (@wall_mins / 60).floor
		mins = @wall_mins.to_i % 60
		secs = ((@wall_mins - @wall_mins.to_i) * 60).to_i
	else
		raise "Please specify wall mins using the W flag"
	end
	eputs "Allotted wall time is " + sprintf("%02d:%02d:%02d", hours, mins, secs)
	return [hours, mins, secs]
end

#max_ppnObject



69
70
71
# File 'lib/coderunner/system_modules/moab.rb', line 69

def max_ppn
	raise "Please define max_ppn for your system"
end

#mpi_progObject



24
25
26
# File 'lib/coderunner/system_modules/moab.rb', line 24

def mpi_prog
	"aprun -n #{nprocstot} -N #{ppn}"
end

#nodesObject



28
29
30
31
# File 'lib/coderunner/system_modules/moab.rb', line 28

def nodes
		nodes, ppn = @nprocs.split(/:/)[0].split(/x/)
		nodes.to_i
end

#nprocstotObject



36
37
38
39
40
# File 'lib/coderunner/system_modules/moab.rb', line 36

def nprocstot
	
		#nodes, ppn = @nprocs.split(/x/)
		nprocstot = nodes.to_i * ppn.to_i
end

#output_fileObject



126
127
128
129
130
131
132
# File 'lib/coderunner/system_modules/moab.rb', line 126

def output_file
	if (ENV['CODE_RUNNER_LAUNCHER'].size > 0 rescue false)
		return "#{executable_name}.#{job_identifier}.o"
	else
		return "#{executable_name}.#{job_identifier}.o#@job_no"
	end
end

#ppnObject



32
33
34
35
# File 'lib/coderunner/system_modules/moab.rb', line 32

def ppn
		nodes, ppn = @nprocs.split(/:/)[0].split(/x/)
		ppn.to_i
end

#ppn_checksObject



85
86
87
88
# File 'lib/coderunner/system_modules/moab.rb', line 85

def ppn_checks
	eputs "Warning: Underuse of nodes (#{ppn} cores per node instead of #{max_ppn})" if ppn.to_i < max_ppn 
	raise "Error: cores per node cannot excede #{max_ppn}" if ppn.to_i > max_ppn
end

#queue_statusObject

Kernel.change_environment_with_shell_script(conf) end



15
16
17
18
19
20
21
22
# File 'lib/coderunner/system_modules/moab.rb', line 15

def queue_status
	if ((prefix = ENV['CODE_RUNNER_LAUNCHER']).size > 0 rescue false)
		%x[cat #{CodeRunner.launcher_directory}/queue_status.txt | grep sh]  +
		%x[cat #{CodeRunner.launcher_directory}/queue_status2.txt | grep sh] 
	else
		%x[qstat | grep $USER]
	end
end

#run_commandObject



41
42
43
44
45
46
47
48
# File 'lib/coderunner/system_modules/moab.rb', line 41

def run_command
# 		"qsub #{batch_script_file}"
	if (ENV['CODE_RUNNER_LAUNCHER'].size > 0 rescue false)
		return %[#{mpi_prog} #{executable_location}/#{executable_name} #{parameter_string} > #{output_file} 2> #{error_file}]
	else
		"#{mpi_prog}  #{executable_location}/#{executable_name} #{parameter_string}"
	end
end