Skip to content

Commit

Permalink
Merge pull request #735 from NREL/fix_windows
Browse files Browse the repository at this point in the history
Fix Windows
  • Loading branch information
shorowit authored Jun 4, 2024
2 parents 966b7e8 + 07308b9 commit dcd4e93
Showing 1 changed file with 13 additions and 21 deletions.
34 changes: 13 additions & 21 deletions workflow/energy_rating_index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,37 +95,25 @@ def run_simulations(designs, options, duplicates)
# Code runs in forked child processes and makes direct calls. This is the fastest
# approach but isn't available on, e.g., Windows.

def kill
raise Parallel::Kill
end

Parallel.map(unique_designs, in_processes: unique_designs.size) do |design|
designdir = run_design_direct(design, options)
kill unless File.exist? File.join(designdir, 'eplusout.end')
if not File.exist? File.join(designdir, 'eplusout.end')
raise Parallel::Kill
end
end

else # e.g., Windows

# Fallback. Code runs in spawned child processes in order to take advantage of
# multiple processors.

def kill(pids)
pids.values.each do |pid|
begin
Process.kill('KILL', pid)
rescue
end
end
end

pids = {}
stop_procs = false
Parallel.map(unique_designs, in_threads: unique_designs.size) do |design|
designdir, pids[design] = run_design_spawn(design, options)
Process.wait pids[design]
next if stop_procs

designdir = run_design_spawn(design, options)
if not File.exist? File.join(designdir, 'eplusout.end')
kill(pids)
next
stop_procs = true # Stop any new designs from kicking off; the best we can do...
end
end

Expand All @@ -137,6 +125,8 @@ def duplicate_output_files(duplicates, designs, resultsdir)
source_design = designs.find { |d| d.hpxml_output_path == source_hpxml_path }
dest_design = designs.find { |d| d.hpxml_output_path == dest_hpxml_path }

next unless File.exist? source_design.design_dir

# Duplicate E+ output directory
FileUtils.cp_r(source_design.design_dir, dest_design.design_dir)

Expand Down Expand Up @@ -179,9 +169,11 @@ def run_design_spawn(design, options)
command += "\"#{options[:add_comp_loads]}\" "
command += "\"#{options[:output_format]}\" "
command += "\"#{options[:diagnostic_output]}\" "
pid = Process.spawn(command)
# Note: Process.spawn() does not work reliably as of OpenStudio 3.8 so
# we are switching to system()
system(command)

return design.design_dir, pid
return design.design_dir
end

def retrieve_design_outputs(designs)
Expand Down

0 comments on commit dcd4e93

Please sign in to comment.