Module: CodeRunner::Juropa

Defined in:
lib/coderunner/system_modules/juropa.rb

Overview

System module for Juropa and HPC-FF

Instance Method Summary collapse

Instance Method Details

#batch_scriptObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/coderunner/system_modules/juropa.rb', line 50

def batch_script
	nodes, ppn = @nprocs.split(/x/)
	ppn ||= 8
	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
	end
	eputs "Allotted wall time is " + sprintf("%02d:%02d:%02d", hours, mins, secs)
<<EOF
#!/bin/bash -x 
#MSUB -l nodes=#{nodes}:ppn=#{ppn} 
#MSUB -N #{executable_name}.#{job_identifier}
#{@wall_mins ? "#MSUB -l walltime=#{sprintf("%02d:%02d:%02d", hours, mins, secs)}" : ""}

### start of jobscript 
cd $PBS_O_WORKDIR 
echo "workdir: $PBS_O_WORKDIR" 
NSLOTS=#{nodes.to_i * ppn.to_i} 
echo "running on $NSLOTS cpus ..." 

EOF

#MSUB -e #{Dir.pwd}/#{error_file} 
#      if keyword omitted : default is submitting directory  
#MSUB -o #{Dir.pwd}/#{output_file}
#       if keyword omitted : default is submitting directory 
end

#batch_script_fileObject



46
47
48
# File 'lib/coderunner/system_modules/juropa.rb', line 46

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

#cancel_jobObject



80
81
82
83
84
85
86
87
# File 'lib/coderunner/system_modules/juropa.rb', line 80

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

#error_fileObject



89
90
91
92
93
# File 'lib/coderunner/system_modules/juropa.rb', line 89

def error_file
	#For backwards compatibility
	return "#{executable_name}.sh.e" if kind_of? CodeRunner::Run and [:Completed, :Failed].include? @status
	return "#{executable_name}.#{job_identifier}.e#@job_no"
end

#executeObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/coderunner/system_modules/juropa.rb', line 25

def execute
	
	if ((prefix = ENV['CODE_RUNNER_LAUNCHER']).size > 0 rescue false)
    launch_id = "#{Time.now.to_i}#{$$}"
    fname = ENV['HOME'] + "/.coderunner_to_launch_#{prefix}/#{launch_id}"
    File.open(fname + '.start', 'w'){|file| file.puts "cd #{Dir.pwd};#{run_command}"}
    sleep 1 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"}
		jn = %x[msub #{batch_script_file}].scan(/(\d+)\s*\Z/).flatten
		if jn[0]
			 return jn[0].to_i
		 else
			 return nil
		 end
	end
end

#get_run_status(job_no, current_status) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/coderunner/system_modules/juropa.rb', line 100

def get_run_status(job_no, current_status)
	if ENV['CODE_RUNNER_LAUNCHER']
		return :Unknown
	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 =~ /\sC\s/
			return :Unknown
		else
			ep 'line', line
			raise 'Could not get run status'
		end
	end
end

#output_fileObject



95
96
97
98
# File 'lib/coderunner/system_modules/juropa.rb', line 95

def output_file
	return "#{executable_name}.sh.o" if kind_of? CodeRunner::Run and [:Completed, :Failed].include? @status
	return "#{executable_name}.#{job_identifier}.o#@job_no"
end

#queue_statusObject



7
8
9
10
11
12
13
14
# File 'lib/coderunner/system_modules/juropa.rb', line 7

def queue_status
	if prefix = ENV['CODE_RUNNER_LAUNCHER']
		%x[cat #{ENV['HOME']}/.coderunner_to_launch_#{prefix}/queue_status.txt]  +
		%x[cat #{ENV['HOME']}/.coderunner_to_launch_#{prefix}/queue_status2.txt] 
	else
		%x[qstat | grep $USER]
	end
end

#run_commandObject



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

def run_command
# 	"msub #{batch_script_file}"
	if ENV['CODE_RUNNER_LAUNCHER']
		return %[mpiexec -np #{@nprocs} #{executable_location}/#{executable_name} #{parameter_string} > #{output_file} 2> #{error_file}]
	else
		"mpiexec -np $NSLOTS #{executable_location}/#{executable_name} #{parameter_string}"
	end
end