class CodeRunner require SCRIPT_FOLDER + '/system_modules/launcher.rb' # A module to let CodeRunner run using the SLURM queue system, # used on certain HPC systems. module Slurm include Launcher def queue_status if use_launcher queue_status_launcher else #%x[squeue | grep #{ENV['USER'][0..7]}] %x[squeue -u $USER] end end def run_command # "qsub #{batch_script_file}" if use_launcher return %[mpiexec -np #{@nprocs} #{executable_location}/#{executable_name} #{parameter_string} > #{output_file} 2> #{error_file}] else "#@preamble #{mpi_prog} #{executable_location}/#{executable_name} #{parameter_string}" end end def mpi_prog nodes, ppn = @nprocs.split(/x/) nprocstot = nodes.to_i * ppn.to_i "mpirun -np #{nprocstot}" end def execute if use_launcher return execute_launcher else File.open(batch_script_file, 'w'){|file| file.puts batch_script + run_command + "\n"} _pid = %x[sbatch #{batch_script_file}].to_i return nil end end def batch_script_file "#{executable_name}.#{job_identifier}.sh" end def max_ppn raise "Please define max_ppn for your system" end def batch_script nodes, ppn = @nprocs.split(/x/) 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 # raise "Error: project (i.e. budget) not specified" unless @project ppn ||= max_ppn raise "Please specify wall minutes" unless @wall_mins 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) nprocstot = nodes.to_i * ppn.to_i <